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 InvocationResultcombine(InvocationResult ra, InvocationResult rb) Combines twoInvocationResultinstances.protected abstract ObjectCombines two rawObjectresults.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 aAsyncOperationfor 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 InvocationResultCreates a newInvocationResultwhich is used as the initial value for combining results.protected abstract ObjectGets the initial result to be fed into thecombine(Object, Object)call.voidsetApplicationId(ApplicationId applicationId) voidsetRemoteInvokerRegistry(RemoteInvokerRegistry remoteInvokerRegistry) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:RoutingStrategyInvokes the method returning aFuture<Object>with the result. Corresponds toRemoteInvoker.invokeFuture(Invocation, List, InvocationErrorConsumer).- Specified by:
invokeFuturein interfaceRoutingStrategy- Parameters:
address- the addressinvocation- theInvocationasyncInvocationResultConsumerList- the list ofConsumer<InvocationResult>instancesasyncInvocationErrorConsumer- theInvocationErrorConsumerto 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:RoutingStrategyInvokes the method returning aAsyncOperationfor the value.- Specified by:
invokeAsyncin interfaceRoutingStrategy- Parameters:
address- the addressinvocation- theInvocationasyncInvocationResultConsumerList- the list ofConsumer<InvocationResult>instancesasyncInvocationErrorConsumer- theInvocationErrorConsumerto 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:RoutingStrategyInvokes the method, blocking until it returns on the remote end. Corresponds toRemoteInvoker.invokeFuture(Invocation, List, InvocationErrorConsumer).- Specified by:
invokeSyncin interfaceRoutingStrategy- Parameters:
address- the addressinvocation- theInvocationasyncInvocationResultConsumerList- the list ofConsumer<InvocationResult>instancesasyncInvocationErrorConsumer- theInvocationErrorConsumerto 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 combiningListinstances, this should ensure that it contains an initial empty list.- Returns:
- the
Objectfor the initial aggregate operation.
-
newInitialInvocationResult
Creates a newInvocationResultwhich is used as the initial value for combining results. This should be a zero-stateInvocationResult. For example, if combiningListinstances, this should ensure that it contains an initial empty list.- Returns:
- the
InvocationResultused as the initial value for aggregations
-
combine
Combines two rawObjectresults.- Parameters:
a- the first objectb- the second object- Returns:
- the combined
Object
-
combine
Combines twoInvocationResultinstances. Specifically the returnedInvocationResultshoud contain the aggregate result in theInvocationResult.getResult()and return it.- Parameters:
ra- the firstInvocationResultrb- the secondInvocationResult- Returns:
- the
InvocationResultcombining the results of both a and b
-
getApplicationId
-
setApplicationId
-
getRemoteInvokerRegistry
-
setRemoteInvokerRegistry
-