Package akka.util
Class Switch
- java.lang.Object
-
- akka.util.Switch
-
public class Switch extends java.lang.Object
An atomic switch that can be either on or off
-
-
Constructor Summary
Constructors Constructor Description Switch(boolean startAsOn)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
$lessinit$greater$default$1()
<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 performanceboolean
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 IMMEDIATELY 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’s lock, i.e.boolean
switchOff()
Switches the switch off (if on), uses lockingboolean
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 exceptionboolean
switchOn()
Switches the switch on (if off), uses lockingboolean
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 exceptionprotected 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 performanceboolean
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
-
-
-
Method Detail
-
$lessinit$greater$default$1
public static boolean $lessinit$greater$default$1()
-
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
-
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
-
switchOff
public boolean switchOff()
Switches the switch off (if on), uses locking
-
switchOn
public boolean switchOn()
Switches the switch on (if off), uses locking
-
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)
-
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)
-
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)
-
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)
-
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
-
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
-
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
-
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
-
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
-
locked
public <T> T locked(scala.Function0<T> code)
Executes the given code while holding this switch’s lock, i.e. protected from concurrent modification of the switch status.
-
isOn
public boolean isOn()
Returns whether the switch is IMMEDIATELY on (no locking)
-
isOff
public boolean isOff()
Returns whether the switch is IMMEDIATELY off (no locking)
-
-