Class OortService<R,C>
- Type Parameters:
R
- the result typeC
- the opaque context type
- All Implemented Interfaces:
EventListener
,Bayeux.BayeuxListener
,ConfigurableServerChannel.ServerChannelListener
,ServerChannel.MessageListener
,org.eclipse.jetty.util.component.LifeCycle
- Direct Known Subclasses:
OortPrimaryService
An OortService
allows applications to forward actions to Oort
nodes that own the entity onto which the action should be applied.
An OortService
builds on the concept introduced by OortObject
that the ownership of a particular entity belongs only to one node.
Any node can read the entity, but only the owner can create/modify/delete it.
In order to perform actions that modify the entity, a node has to know what is the node that owns the entity, and then forward the action to the owner node.
OortService
provides the facilities to forward the action to the
owner node and return the result of the action, or its failure.
OortService
s are usually created at application startup, but may
be created and destroyed on-the-fly.
In both cases, they must be started
to make them functional
and stopped
when they are no longer needed.
Usage of OortService
follows these steps:
-
The application running in the requesting node identifies
the owner node and calls
forward(String, Object, Object)
, passing the Oort URL of the owner node, the action data, and an opaque context -
The application implements
onForward(Request)
, which is executed in the owner node. In this method the action data is used to perform the action that modifies the entity, and the result is returned (or an exception thrown in case of failure). -
The application implements
onForwardSucceeded(Object, Object)
(which is executed in the requesting node) which provides as parameters the result of the action from the second step and the opaque context from the first step. -
The application implements
onForwardFailed(Object, Object)
(which is executed in the requesting node) which provides as parameters the failure from the second step and the opaque context from the first step. The failure object is the message string of a generic exception, or the failure returned byOortService.Result.failure(Object)
.
The steps above do not change if the requesting node and the owner node are the same.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Encapsulates a forwarded request.static class
Encapsulates the result of a forwarded request returned byonForward(Request)
.static class
Utility context that stores theServerSession
and theServerMessage
.Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException
Nested classes/interfaces inherited from interface org.cometd.bayeux.server.ConfigurableServerChannel.ServerChannelListener
ConfigurableServerChannel.ServerChannelListener.Weak
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, STARTED, STARTING, STOPPED, STOPPING
-
Constructor Summary
ModifierConstructorDescriptionprotected
OortService
(Oort oort, String name) Creates anOortService
with the given name. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doStart()
protected void
doStop()
protected boolean
Subclasses must call this method to forward the action to the owner node.getName()
getOort()
long
protected abstract OortService.Result
<R> onForward
(OortService.Request request) Subclasses must implement this method, that runs on the owner node, to implement the action functionality.protected abstract void
onForwardFailed
(Object failure, C 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
onForwardMessage
(Map<String, Object> data, boolean broadcast) protected abstract void
onForwardSucceeded
(R result, C 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.boolean
onMessage
(ServerSession from, ServerChannel channel, ServerMessage.Mutable message) protected void
onResultMessage
(Map<String, Object> data) void
setTimeout
(long timeout) toString()
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addEventListener, getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, setEventListeners, start, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.cometd.bayeux.server.ServerChannel.MessageListener
onMessage
-
Constructor Details
-
OortService
Creates anOortService
with the given name.- Parameters:
oort
- the Oort where this service livesname
- the unique name across the cluster of this service
-
-
Method Details
-
getOort
- Returns:
- the Oort of this service
-
getName
- Returns:
- the name of this service
-
getLocalSession
- Returns:
- the local session associated with this service
-
getTimeout
public long getTimeout()- Returns:
- the timeout, in milliseconds, for an action to return a result (by default 5000 ms)
-
setTimeout
public void setTimeout(long timeout) - Parameters:
timeout
- the timeout, in milliseconds, for an action to return a result
-
doStart
-
doStop
-
forward
Subclasses must call this method to forward the action to the owner node.
If the
targetOortURL
isnull
, then the action is broadcast to all nodes. Nodes that receive an action request that they can't fullfill because they don't own the entity the action should be applied to must returnOortService.Result.ignore(Object)
.- Parameters:
targetOortURL
- the owner node Oort URL, or null to broadcast the action to all nodesparameter
- the action parameter that will be passed toonForward(Request)
context
- the opaque context passed toonForwardSucceeded(Object, Object)
- Returns:
- whether the forward succeeded
-
onMessage
Description copied from interface:ServerChannel.MessageListener
Blocking version of
ServerChannel.MessageListener.onMessage(ServerSession, ServerChannel, ServerMessage.Mutable, Promise)
.- Specified by:
onMessage
in interfaceServerChannel.MessageListener
- Parameters:
from
- the session that publishes the messagechannel
- the channel the message is published tomessage
- the message to be published- Returns:
- whether the message processing should continue
-
onForwardMessage
-
onResultMessage
-
onForward
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)
orOortService.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, orOortService.Result.ignore(Object)
if the entity was not found.- Parameters:
request
- the request containing the parameter passed fromforward(String, Object, Object)
- Returns:
- the result containing the data that will be passed to
onForwardSucceeded(Object, Object)
-
onForwardSucceeded
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.- Parameters:
result
- the result of the actioncontext
- the opaque context fromforward(String, Object, Object)
-
onForwardFailed
Subclasses must implement this method, that runs on the requesting node, to complete the functionality after the action failed on the owner node.- Parameters:
failure
- the failure of the actioncontext
- the opaque context fromforward(String, Object, Object)
-
toString
- Overrides:
toString
in classorg.eclipse.jetty.util.component.AbstractLifeCycle
-