akka.util
Class Switch

java.lang.Object
  extended by akka.util.Switch

public class Switch
extends java.lang.Object

An atomic switch that can be either on or off


Constructor Summary
Switch(boolean startAsOn)
           
 
Method Summary
<T> T
fold(scala.Function0<T> on, scala.Function0<T> off)
          Executes the provided callbacks depending on if the switch is either on or off waiting for any pending changes to happen before (locking) Be careful of longrunning or blocking within the provided action as it can lead to deadlocks or bad performance
 boolean ifOff(scala.Function0<scala.runtime.BoxedUnit> action)
          Executes the provided action and returns if the action was executed or not, if the switch is IMMEDIATELY off (i.e.
<T> scala.Option<T>
ifOffYield(scala.Function0<T> action)
          Executes the provided action and returns its value if the switch is IMMEDIATELY off (i.e.
 boolean ifOn(scala.Function0<scala.runtime.BoxedUnit> action)
          Executes the provided action and returns if the action was executed or not, if the switch is IMMEDIATELY on (i.e.
<T> scala.Option<T>
ifOnYield(scala.Function0<T> action)
          Executes the provided action and returns its value if the switch is IMMEDIATELY on (i.e.
 boolean isOff()
          Returns whether the switch is IMMEDDIATELY off (no locking)
 boolean isOn()
          Returns whether the switch is IMMEDIATELY on (no locking)
<T> T
locked(scala.Function0<T> code)
          Executes the given code while holding this switch&rsquo;s lock, i.e.
 boolean switchOff()
          Switches the switch off (if on), uses locking
 boolean switchOff(scala.Function0<scala.runtime.BoxedUnit> action)
          Executes the provided action if the lock is on under a lock, so be _very_ careful with longrunning/blocking operations in it Only executes the action if the switch is on, and switches it off immediately after obtaining the lock Will switch it back on if the provided action throws an exception
 boolean switchOn()
          Switches the switch on (if off), uses locking
 boolean switchOn(scala.Function0<scala.runtime.BoxedUnit> action)
          Executes the provided action if the lock is off under a lock, so be _very_ careful with longrunning/blocking operations in it Only executes the action if the switch is off, and switches it on immediately after obtaining the lock Will switch it back off if the provided action throws an exception
protected  boolean transcend(boolean from, scala.Function0<scala.runtime.BoxedUnit> action)
           
 boolean whileOff(scala.Function0<scala.runtime.BoxedUnit> action)
          Executes the provided action and returns if the action was executed or not, if the switch is off, waiting for any pending changes to happen before (locking) Be careful of longrunning or blocking within the provided action as it can lead to deadlocks or bad performance
<T> scala.Option<T>
whileOffYield(scala.Function0<T> action)
          Executes the provided action and returns its value if the switch is off, waiting for any pending changes to happen before (locking) Be careful of longrunning or blocking within the provided action as it can lead to deadlocks or bad performance
 boolean whileOn(scala.Function0<scala.runtime.BoxedUnit> action)
          Executes the provided action and returns if the action was executed or not, if the switch is on, waiting for any pending changes to happen before (locking) Be careful of longrunning or blocking within the provided action as it can lead to deadlocks or bad performance
<T> scala.Option<T>
whileOnYield(scala.Function0<T> action)
          Executes the provided action and returns its value if the switch is on, waiting for any pending changes to happen before (locking) Be careful of longrunning or blocking within the provided action as it can lead to deadlocks or bad performance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Switch

public Switch(boolean startAsOn)
Method Detail

transcend

protected boolean transcend(boolean from,
                            scala.Function0<scala.runtime.BoxedUnit> action)

switchOff

public boolean switchOff(scala.Function0<scala.runtime.BoxedUnit> action)
Executes the provided action if the lock is on under a lock, so be _very_ careful with longrunning/blocking operations in it Only executes the action if the switch is on, and switches it off immediately after obtaining the lock Will switch it back on if the provided action throws an exception

Parameters:
action - (undocumented)
Returns:
(undocumented)

switchOn

public boolean switchOn(scala.Function0<scala.runtime.BoxedUnit> action)
Executes the provided action if the lock is off under a lock, so be _very_ careful with longrunning/blocking operations in it Only executes the action if the switch is off, and switches it on immediately after obtaining the lock Will switch it back off if the provided action throws an exception

Parameters:
action - (undocumented)
Returns:
(undocumented)

switchOff

public boolean switchOff()
Switches the switch off (if on), uses locking

Returns:
(undocumented)

switchOn

public boolean switchOn()
Switches the switch on (if off), uses locking

Returns:
(undocumented)

ifOnYield

public <T> scala.Option<T> ifOnYield(scala.Function0<T> action)
Executes the provided action and returns its value if the switch is IMMEDIATELY on (i.e. no lock involved)

Parameters:
action - (undocumented)
Returns:
(undocumented)

ifOffYield

public <T> scala.Option<T> ifOffYield(scala.Function0<T> action)
Executes the provided action and returns its value if the switch is IMMEDIATELY off (i.e. no lock involved)

Parameters:
action - (undocumented)
Returns:
(undocumented)

ifOn

public boolean ifOn(scala.Function0<scala.runtime.BoxedUnit> action)
Executes the provided action and returns if the action was executed or not, if the switch is IMMEDIATELY on (i.e. no lock involved)

Parameters:
action - (undocumented)
Returns:
(undocumented)

ifOff

public boolean ifOff(scala.Function0<scala.runtime.BoxedUnit> action)
Executes the provided action and returns if the action was executed or not, if the switch is IMMEDIATELY off (i.e. no lock involved)

Parameters:
action - (undocumented)
Returns:
(undocumented)

whileOnYield

public <T> scala.Option<T> whileOnYield(scala.Function0<T> action)
Executes the provided action and returns its value if the switch is on, waiting for any pending changes to happen before (locking) Be careful of longrunning or blocking within the provided action as it can lead to deadlocks or bad performance

Parameters:
action - (undocumented)
Returns:
(undocumented)

whileOffYield

public <T> scala.Option<T> whileOffYield(scala.Function0<T> action)
Executes the provided action and returns its value if the switch is off, waiting for any pending changes to happen before (locking) Be careful of longrunning or blocking within the provided action as it can lead to deadlocks or bad performance

Parameters:
action - (undocumented)
Returns:
(undocumented)

whileOn

public boolean whileOn(scala.Function0<scala.runtime.BoxedUnit> action)
Executes the provided action and returns if the action was executed or not, if the switch is on, waiting for any pending changes to happen before (locking) Be careful of longrunning or blocking within the provided action as it can lead to deadlocks or bad performance

Parameters:
action - (undocumented)
Returns:
(undocumented)

whileOff

public boolean whileOff(scala.Function0<scala.runtime.BoxedUnit> action)
Executes the provided action and returns if the action was executed or not, if the switch is off, waiting for any pending changes to happen before (locking) Be careful of longrunning or blocking within the provided action as it can lead to deadlocks or bad performance

Parameters:
action - (undocumented)
Returns:
(undocumented)

fold

public <T> T fold(scala.Function0<T> on,
                  scala.Function0<T> off)
Executes the provided callbacks depending on if the switch is either on or off waiting for any pending changes to happen before (locking) Be careful of longrunning or blocking within the provided action as it can lead to deadlocks or bad performance

Parameters:
on - (undocumented)
off - (undocumented)
Returns:
(undocumented)

locked

public <T> T locked(scala.Function0<T> code)
Executes the given code while holding this switch&rsquo;s lock, i.e. protected from concurrent modification of the switch status.

Parameters:
code - (undocumented)
Returns:
(undocumented)

isOn

public boolean isOn()
Returns whether the switch is IMMEDIATELY on (no locking)

Returns:
(undocumented)

isOff

public boolean isOff()
Returns whether the switch is IMMEDDIATELY off (no locking)

Returns:
(undocumented)