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 long
s per node - where N is the
number of nodes) for smaller latencies (operations do not require messaging).
OortMasterLong
Constructor | Description |
---|---|
OortLong(Oort oort,
java.lang.String name) |
|
OortLong(Oort oort,
java.lang.String name,
long initial) |
Modifier and Type | Method | Description |
---|---|---|
long |
addAndGet(long delta) |
|
void |
addListener(OortObject.Listener<java.lang.Long> listener) |
|
boolean |
compareAndSet(long expected,
long newValue) |
|
protected void |
doStart() |
|
protected void |
doStop() |
|
long |
get() |
|
long |
getAndAdd(long delta) |
|
long |
getAndSet(long newValue) |
|
org.cometd.bayeux.server.LocalSession |
getLocalSession() |
|
Oort |
getOort() |
|
void |
removeListener(OortObject.Listener<java.lang.Long> listener) |
|
void |
removeListeners() |
Removes all listeners.
|
long |
sum() |
public OortLong(Oort oort, java.lang.String name)
public OortLong(Oort oort, java.lang.String name, long initial)
oort
- the oort this instance is associated toname
- the name of this serviceinitial
- the initial local valueprotected void doStart() throws java.lang.Exception
doStart
in class org.eclipse.jetty.util.component.AbstractLifeCycle
java.lang.Exception
protected void doStop() throws java.lang.Exception
doStop
in class org.eclipse.jetty.util.component.AbstractLifeCycle
java.lang.Exception
public org.cometd.bayeux.server.LocalSession getLocalSession()
public void addListener(OortObject.Listener<java.lang.Long> listener)
listener
- the listener to add that is notified of updates of the value in a noderemoveListener(OortObject.Listener)
public void removeListener(OortObject.Listener<java.lang.Long> listener)
listener
- the listener to removeaddListener(OortObject.Listener)
public void removeListeners()
public long get()
public long addAndGet(long delta)
delta
- the delta to add to the local value (may be negative)public long getAndAdd(long delta)
delta
- the delta to add to the local value (may be negative)public long getAndSet(long newValue)
newValue
- the new local value to setpublic boolean compareAndSet(long expected, long newValue)
expected
- the expected local valuenewValue
- the new local valuepublic long sum()
Copyright © 2008–2017 The CometD Project. All rights reserved.