public class OortPrimaryLong extends OortPrimaryService<Long,OortPrimaryLong.Context>
A distributed counter service to be deployed on a Oort cluster that
modifies a long
value hosted in a "primary" 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 OortPrimaryLong.Callback
object that will be
invoked on the requesting node when the result has been
computed and transmitted back by the "primary" node.
Modifier and Type | Class and Description |
---|---|
static interface |
OortPrimaryLong.Callback
Callback invoked when the result of the operation on the counter is available,
or when the operation failed.
|
protected static class |
OortPrimaryLong.Context |
OortService.Request, OortService.Result<U>, OortService.ServerContext
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
ConfigurableServerChannel.ServerChannelListener.Weak
Constructor and Description |
---|
OortPrimaryLong(Oort oort,
String name,
boolean primary) |
OortPrimaryLong(Oort oort,
String name,
boolean primary,
long initial) |
Modifier and Type | Method and Description |
---|---|
boolean |
addAndGet(long delta,
OortPrimaryLong.Callback callback)
Adds the given
delta and then invokes the given callback with
the counter value after the addition. |
boolean |
get(OortPrimaryLong.Callback callback)
Retrieves the value from the "primary" node and then invokes the given
callback
with the result value. |
boolean |
getAndAdd(long delta,
OortPrimaryLong.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<Long> |
onForward(OortService.Request request)
Subclasses must implement this method, that runs on the owner node,
to implement the action functionality.
|
protected void |
onForwardFailed(Object failure,
OortPrimaryLong.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(Long result,
OortPrimaryLong.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.
|
doStart, doStop, getPrimaryOortURL, isPrimary
forward, getLocalSession, getName, getOort, getTimeout, onForwardMessage, onMessage, onResultMessage, setTimeout, toString
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
onMessage
protected long getValue()
public boolean get(OortPrimaryLong.Callback callback)
callback
with the result value.callback
- the callback invoked when the result is availablepublic boolean addAndGet(long delta, OortPrimaryLong.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, OortPrimaryLong.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<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<Long,OortPrimaryLong.Context>
request
- the request containing the parameter passed from OortService.forward(String, Object, Object)
OortService.onForwardSucceeded(Object, Object)
protected void onForwardSucceeded(Long result, OortPrimaryLong.Context context)
OortService
onForwardSucceeded
in class OortService<Long,OortPrimaryLong.Context>
result
- the result of the actioncontext
- the opaque context from OortService.forward(String, Object, Object)
protected void onForwardFailed(Object failure, OortPrimaryLong.Context context)
OortService
onForwardFailed
in class OortService<Long,OortPrimaryLong.Context>
failure
- the failure of the actioncontext
- the opaque context from OortService.forward(String, Object, Object)
Copyright © 2008–2024 The CometD Project. All rights reserved.