Class OortLong
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.cometd.oort.OortLong
-
- All Implemented Interfaces:
org.eclipse.jetty.util.component.LifeCycle
public class OortLong extends org.eclipse.jetty.util.component.AbstractLifeCycleA shared atomic long made of an internal
AtomicLongand of an internalOortObject<Long>.This class exposes an API similar to that of
AtomicLong, and for every successful update of the local value of the internalAtomicLong, it broadcast the local value via the internalOortObjectto other nodes.This class can be seen as the counterpart of
OortPrimaryLong.Where the
OortPrimaryLonginstance in each node has an internalAtomicLong, but only the one in the "primary" node has a non-zero value, the instance of this class in each node has an internalAtomicLongthat has its own value.Where in
OortPrimaryLongupdates are always sent to the "primary" node, in this class updates are always local, and then broadcast to the other nodes in the cluster.Where in
OortPrimaryLongeach node has to send a message to the "primary" node to retrieve the total value, in this class the total value can be obtained from the internalOortObjectwithout network communication with other nodes.Where
OortPrimaryLongtrades less memory (onelongper node) for larger latencies (every operation on non-primary nodes requires sending a message to the primary node), this class trades more memory (Nlongs per node - where N is the number of nodes) for smaller latencies (operations do not require messaging).- See Also:
OortPrimaryLong
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longaddAndGet(long delta)voidaddListener(OortObject.Listener<java.lang.Long> listener)booleancompareAndSet(long expected, long newValue)protected voiddoStart()protected voiddoStop()longget()longgetAndAdd(long delta)longgetAndSet(long newValue)LocalSessiongetLocalSession()OortgetOort()voidremoveListener(OortObject.Listener<java.lang.Long> listener)voidremoveListeners()Removes all listeners.longsum()
-
-
-
Method Detail
-
doStart
protected void doStart() throws java.lang.Exception- Overrides:
doStartin classorg.eclipse.jetty.util.component.AbstractLifeCycle- Throws:
java.lang.Exception
-
doStop
protected void doStop() throws java.lang.Exception- Overrides:
doStopin classorg.eclipse.jetty.util.component.AbstractLifeCycle- Throws:
java.lang.Exception
-
getLocalSession
public LocalSession getLocalSession()
- Returns:
- the local session that sends messages to other nodes
-
addListener
public void addListener(OortObject.Listener<java.lang.Long> listener)
- Parameters:
listener- the listener to add that is notified of updates of the value in a node- See Also:
removeListener(OortObject.Listener)
-
removeListener
public void removeListener(OortObject.Listener<java.lang.Long> listener)
- Parameters:
listener- the listener to remove- See Also:
addListener(OortObject.Listener)
-
removeListeners
public void removeListeners()
Removes all listeners.
-
get
public long get()
- Returns:
- the local value
-
addAndGet
public long addAndGet(long delta)
- Parameters:
delta- the delta to add to the local value (may be negative)- Returns:
- the new local value
-
getAndAdd
public long getAndAdd(long delta)
- Parameters:
delta- the delta to add to the local value (may be negative)- Returns:
- the old local value
-
getAndSet
public long getAndSet(long newValue)
- Parameters:
newValue- the new local value to set- Returns:
- the old local value
-
compareAndSet
public boolean compareAndSet(long expected, long newValue)- Parameters:
expected- the expected local valuenewValue- the new local value- Returns:
- whether the operation was successful
-
sum
public long sum()
- Returns:
- the sum of local values of each node
-
-