public class OortMasterLong extends OortMasterService<java.lang.Long,OortMasterLong.Context>
A distributed counter service to be deployed on a Oort cluster that
modifies a long
value hosted in a "master" node.
Instances of this service may be used as unique ID generator, or as unique counter across the cluster, for example to aggregate values from different nodes, such as the number of users connected to each node.
Applications may call methods addAndGet(long, Callback)
or
getAndAdd(long, Callback)
providing the amount to add
(it may be negative) and a OortMasterLong.Callback
object that will be
invoked on the requesting node when the result has been
computed and transmitted back by the "master" node.
Modifier and Type | Class | Description |
---|---|---|
static interface |
OortMasterLong.Callback |
Callback invoked when the result of the operation on the counter is available,
or when the operation failed.
|
protected static class |
OortMasterLong.Context |
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
org.cometd.bayeux.server.ConfigurableServerChannel.ServerChannelListener.Weak
org.eclipse.jetty.util.component.LifeCycle.Listener
OortService.Request, OortService.Result<U>, OortService.ServerContext
FAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPING
logger
Constructor | Description |
---|---|
OortMasterLong(Oort oort,
java.lang.String name,
boolean master) |
|
OortMasterLong(Oort oort,
java.lang.String name,
boolean master,
long initial) |
Modifier and Type | Method | Description |
---|---|---|
boolean |
addAndGet(long delta,
OortMasterLong.Callback callback) |
Adds the given
delta and then invokes the given callback with
the counter value after the addition. |
boolean |
get(OortMasterLong.Callback callback) |
Retrieves the value from the "master" node and then invokes the given
callback
with the result value. |
boolean |
getAndAdd(long delta,
OortMasterLong.Callback callback) |
Adds the given
delta and then invokes the given callback with
the counter value before the addition. |
protected long |
getValue() |
|
protected OortService.Result<java.lang.Long> |
onForward(OortService.Request request) |
Subclasses must implement this method, that runs on the owner node,
to implement the action functionality.
|
protected void |
onForwardFailed(java.lang.Object failure,
OortMasterLong.Context context) |
Subclasses must implement this method, that runs on the requesting node,
to complete the functionality after the action failed on the owner node.
|
protected void |
onForwardSucceeded(java.lang.Long result,
OortMasterLong.Context context) |
Subclasses must implement this method, that runs on the requesting node,
to complete the functionality after the action has been successfully run on the owner node.
|
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
doStart, doStop, getMasterOortURL, isMaster
forward, getLocalSession, getName, getOort, getTimeout, onForwardMessage, onMessage, onResultMessage, setTimeout, toString
public OortMasterLong(Oort oort, java.lang.String name, boolean master)
public OortMasterLong(Oort oort, java.lang.String name, boolean master, long initial)
oort
- the oort this instance is associated toname
- the name of this servicemaster
- whether this service lives on the "master" nodeinitial
- the initial local valueprotected long getValue()
public boolean get(OortMasterLong.Callback callback)
callback
with the result value.callback
- the callback invoked when the result is availablepublic boolean addAndGet(long delta, OortMasterLong.Callback callback)
delta
and then invokes the given callback
with
the counter value after the addition.
The counter value may be already out of date at the moment
of the invocation of the callback
.delta
- the value to add, may be negativecallback
- the callback invoked when the result is availablegetAndAdd(long, Callback)
public boolean getAndAdd(long delta, OortMasterLong.Callback callback)
delta
and then invokes the given callback
with
the counter value before the addition.delta
- the value to add, may be negativecallback
- the callback invoked when the result is availableaddAndGet(long, Callback)
protected OortService.Result<java.lang.Long> onForward(OortService.Request request)
OortService
Subclasses must implement this method, that runs on the owner node, to implement the action functionality.
The result to return is OortService.Result.success(Object)
or OortService.Result.failure(Object)
if the implementation of this method was able to find the entity on which the action
functionality was meant to be applied, or OortService.Result.ignore(Object)
if the entity
was not found.
onForward
in class OortService<java.lang.Long,OortMasterLong.Context>
request
- the request containing the parameter passed from OortService.forward(String, Object, Object)
OortService.onForwardSucceeded(Object, Object)
protected void onForwardSucceeded(java.lang.Long result, OortMasterLong.Context context)
OortService
onForwardSucceeded
in class OortService<java.lang.Long,OortMasterLong.Context>
result
- the result of the actioncontext
- the opaque context from OortService.forward(String, Object, Object)
protected void onForwardFailed(java.lang.Object failure, OortMasterLong.Context context)
OortService
onForwardFailed
in class OortService<java.lang.Long,OortMasterLong.Context>
failure
- the failure of the actioncontext
- the opaque context from OortService.forward(String, Object, Object)
Copyright © 2008–2017 The CometD Project. All rights reserved.