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.AbstractLifeCycle

A shared atomic long made of an internal AtomicLong and of an internal OortObject<Long>.

This class exposes an API similar to that of AtomicLong, and for every successful update of the local value of the internal AtomicLong, it broadcast the local value via the internal OortObject to other nodes.

This class can be seen as the counterpart of OortMasterLong.

Where the OortMasterLong instance in each node has an internal AtomicLong, but only the one in the "master" node has a non-zero value, the instance of this class in each node has an internal AtomicLong that has its own value.

Where in OortMasterLong updates are always sent to the "master" node, in this class updates are always local, and then broadcast to the other nodes in the cluster.

Where in OortMasterLong each node has to send a message to the "master" node to retrieve the total value, in this class the total value can be obtained from the internal OortObject without network communication with other nodes.

Where OortMasterLong trades less memory (one long per node) for larger latencies (every operation on non-master nodes requires sending a message to the master node), this class trades more memory (N longs per node - where N is the number of nodes) for smaller latencies (operations do not require messaging).

See Also:
OortMasterLong
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

    org.eclipse.jetty.util.component.LifeCycle.Listener
  • Field Summary

    Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
  • Constructor Summary

    Constructors 
    Constructor Description
    OortLong​(Oort oort, String name)  
    OortLong​(Oort oort, String name, long initial)  
  • Method Summary

    Modifier and Type Method Description
    long addAndGet​(long delta)  
    void addListener​(OortObject.Listener<Long> listener)  
    boolean compareAndSet​(long expected, long newValue)  
    protected void doStart()  
    protected void doStop()  
    long get()  
    long getAndAdd​(long delta)  
    long getAndSet​(long newValue)  
    LocalSession getLocalSession()  
    Oort getOort()  
    void removeListener​(OortObject.Listener<Long> listener)  
    void removeListeners()
    Removes all listeners.
    long sum()  

    Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • OortLong

      public OortLong​(Oort oort, String name)
    • OortLong

      public OortLong​(Oort oort, String name, long initial)
      Parameters:
      oort - the oort this instance is associated to
      name - the name of this service
      initial - the initial local value
  • Method Details

    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class org.eclipse.jetty.util.component.AbstractLifeCycle
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class org.eclipse.jetty.util.component.AbstractLifeCycle
      Throws:
      Exception
    • getOort

      public Oort getOort()
      Returns:
      the Oort instance associated with this oort long
    • getLocalSession

      public LocalSession getLocalSession()
      Returns:
      the local session that sends messages to other nodes
    • addListener

      public void addListener​(OortObject.Listener<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<Long> listener)
      Parameters:
      listener - the listener to remove
      See Also:
      addListener(OortObject.Listener)
    • removeListeners

      public void removeListeners()
      Removes all listeners.
      See Also:
      addListener(OortObject.Listener), removeListener(OortObject.Listener)
    • 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 value
      newValue - the new local value
      Returns:
      whether the operation was successful
    • sum

      public long sum()
      Returns:
      the sum of local values of each node