Class AbstractAggregateRoutingStrategy
java.lang.Object
dev.getelements.elements.rt.routing.AbstractAggregateRoutingStrategy
- All Implemented Interfaces:
RoutingStrategy
- Direct Known Subclasses:
BroadcastRoutingStrategy
,ListAggregateRoutingStrategy
A compex type of
RoutingStrategy
where each invocation goes to all known RemoteInvoker
instances
and then combines the results together into a single result. In the event of a single error, the whole call is
canceled rather than trying to partially report some result.
It is not recommended that this RoutingStrategy
be used for writes if reliability is expected, but only for
read operations.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected InvocationResult
combine
(InvocationResult ra, InvocationResult rb) Combines twoInvocationResult
instances.protected abstract Object
Combines two rawObject
results.protected List
<RemoteInvoker> getRemoteInvokers
(List<Object> address) Gets theList<RemoteInvoker>
for the supplied address.invokeAsync
(List<Object> address, Invocation invocation, List<Consumer<InvocationResult>> asyncInvocationResultConsumerList, InvocationErrorConsumer asyncInvocationErrorConsumer) Invokes the method returning aAsyncOperation
for the value.invokeFuture
(List<Object> address, Invocation invocation, List<Consumer<InvocationResult>> asyncInvocationResultConsumerList, InvocationErrorConsumer asyncInvocationErrorConsumer) invokeSync
(List<Object> address, Invocation invocation, List<Consumer<InvocationResult>> asyncInvocationResultConsumerList, InvocationErrorConsumer asyncInvocationErrorConsumer) Invokes the method, blocking until it returns on the remote end.protected InvocationResult
Creates a newInvocationResult
which is used as the initial value for combining results.protected abstract Object
Gets the initial result to be fed into thecombine(Object, Object)
call.void
setApplicationId
(ApplicationId applicationId) void
setRemoteInvokerRegistry
(RemoteInvokerRegistry remoteInvokerRegistry) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.getelements.elements.rt.remote.RoutingStrategy
invokeAsyncV
-
Constructor Details
-
AbstractAggregateRoutingStrategy
public AbstractAggregateRoutingStrategy()
-
-
Method Details
-
invokeFuture
public Future<Object> invokeFuture(List<Object> address, Invocation invocation, List<Consumer<InvocationResult>> asyncInvocationResultConsumerList, InvocationErrorConsumer asyncInvocationErrorConsumer) Description copied from interface:RoutingStrategy
Invokes the method returning aFuture<Object>
with the result. Corresponds toRemoteInvoker.invokeFuture(Invocation, List, InvocationErrorConsumer)
.- Specified by:
invokeFuture
in interfaceRoutingStrategy
- Parameters:
address
- the addressinvocation
- theInvocation
asyncInvocationResultConsumerList
- the list ofConsumer<InvocationResult>
instancesasyncInvocationErrorConsumer
- theInvocationErrorConsumer
to receive the error of the invocation- Returns:
- the
Future<Object>
to handle the return value
-
invokeAsync
public AsyncOperation invokeAsync(List<Object> address, Invocation invocation, List<Consumer<InvocationResult>> asyncInvocationResultConsumerList, InvocationErrorConsumer asyncInvocationErrorConsumer) Description copied from interface:RoutingStrategy
Invokes the method returning aAsyncOperation
for the value.- Specified by:
invokeAsync
in interfaceRoutingStrategy
- Parameters:
address
- the addressinvocation
- theInvocation
asyncInvocationResultConsumerList
- the list ofConsumer<InvocationResult>
instancesasyncInvocationErrorConsumer
- theInvocationErrorConsumer
to receive the error of the invocation- Returns:
- an instance of
AsyncOperation
-
invokeSync
public Object invokeSync(List<Object> address, Invocation invocation, List<Consumer<InvocationResult>> asyncInvocationResultConsumerList, InvocationErrorConsumer asyncInvocationErrorConsumer) throws Exception Description copied from interface:RoutingStrategy
Invokes the method, blocking until it returns on the remote end. Corresponds toRemoteInvoker.invokeFuture(Invocation, List, InvocationErrorConsumer)
.- Specified by:
invokeSync
in interfaceRoutingStrategy
- Parameters:
address
- the addressinvocation
- theInvocation
asyncInvocationResultConsumerList
- the list ofConsumer<InvocationResult>
instancesasyncInvocationErrorConsumer
- theInvocationErrorConsumer
to receive the error of the invocation- Returns:
- the return value of the remote invocation
- Throws:
Exception
-
getRemoteInvokers
Gets theList<RemoteInvoker>
for the supplied address. By default this just gets all instances for a particular application UUID.- Parameters:
address
- the address- Returns:
- a
List<RemoteInvoker>
to use.
-
newInitialResult
Gets the initial result to be fed into thecombine(Object, Object)
call. This should represent a zero-state result. For example, if combiningList
instances, this should ensure that it contains an initial empty list.- Returns:
- the
Object
for the initial aggregate operation.
-
newInitialInvocationResult
Creates a newInvocationResult
which is used as the initial value for combining results. This should be a zero-stateInvocationResult
. For example, if combiningList
instances, this should ensure that it contains an initial empty list.- Returns:
- the
InvocationResult
used as the initial value for aggregations
-
combine
Combines two rawObject
results.- Parameters:
a
- the first objectb
- the second object- Returns:
- the combined
Object
-
combine
Combines twoInvocationResult
instances. Specifically the returnedInvocationResult
shoud contain the aggregate result in theInvocationResult.getResult()
and return it.- Parameters:
ra
- the firstInvocationResult
rb
- the secondInvocationResult
- Returns:
- the
InvocationResult
combining the results of both a and b
-
getApplicationId
-
setApplicationId
-
getRemoteInvokerRegistry
-
setRemoteInvokerRegistry
-