markusthoemmes commented on a change in pull request #3656: Adjust the behavior 
when update controller cluster
URL: 
https://github.com/apache/incubator-openwhisk/pull/3656#discussion_r218343743
 
 

 ##########
 File path: common/scala/src/main/scala/whisk/common/ForcibleSemaphore.scala
 ##########
 @@ -121,4 +122,18 @@ class ForcibleSemaphore(maxAllowed: Int) {
 
   /** Returns the number of currently available permits. Possibly negative. */
   def availablePermits: Int = sync.permits
+
+  /** Set the max permits for sync. */
+  def setMaxPermits(newMaxPermits: Int): Unit = synchronized {
+    require(newMaxPermits > 0, "maxPermits cannot be negative")
+    newMaxPermits - maxPermits match {
+      case 0 =>
+      case delta if delta > 0 =>
+        sync.releaseShared(delta) // increase the max permits
+      case delta if delta < 0 =>
+        sync.forceAquireShared(-delta) // reduce the max permits
+    }
 
 Review comment:
   It doesn't seem like a `match` block helps here.
   
   ```scala
   val delta = newMaxPermits - maxPermits
   if(delta > 0) {
     sync.releaseShared(delta)
   } else if(delta < 0) {
     sync.forceAquireShared(-delta)
   }
   ```
   
   Reads a bit better imo?
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to