public abstract class AbstractRouterWithFailOverToNextNode extends Object implements Router, FailingStrategy
Router
which supports FailingStrategy
.
By methods overriding/implementing router can be configured to support :
- Mod or RoundRobin strategy (override properly getStrategy() method - NOTE : should not return null
); - different amounts of service instances, can be configured via annotation ar simply changed by getServerAmount() method override; - support or not support call failing (failingSupported() should return true fro support, false otherwise ). In case when Mod routing strategy selected for some router, register all MOD - routed methods directly in router-constructor using next calls: - addModRoutedMethod (name, position) - which will add mod support for method with selected [name], and incoming argument with selected [position] will be used as modable value; - addModRoutedMethod(name) - will add mod support for method with selected [name], and parameter with 0 position will be used as modable (common case). IMPORTANT : If MOD routing can't be performed for some call (method does not have any incoming params, or incoming params does not matches for modable calculations, or simply we does not need to route some method by MOD ) - RoundRobin will be performed instead!. For this - just don't call addModRoutedMethod for method which should not be routed by MOD. By implementing getModableValue(>) method - You can simply extract some long from incoming parameter, for further calculations.Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractRouterWithFailOverToNextNode.RouterStrategy
Returns type of strategy - on which current router works.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractRouterWithFailOverToNextNode()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addModRoutedMethod(String mName)
Allow to add some custom method with some name using default 0 modable parameter position.
|
protected void |
addModRoutedMethod(String mName,
int modableParameterPosition)
Allow to add some custom method with some name and modable parameter position to mod method registry.
|
FailDecision |
callFailed(ClientSideCallContext clientSideCallContext)
What should happen if a call is failed.
|
void |
customize(String s)
Called shortly after the initialization to customize this router according to the parameter in the annotation.
|
protected abstract boolean |
failingSupported()
Allow to turn on and off failing support.
|
protected org.slf4j.Logger |
getLog()
Simply return configured
Logger instance. |
protected abstract long |
getModableValue(Object parameter)
Return long value for mod calculation.
|
protected int |
getServiceAmount()
Return amount of services for which routing should be performed.
|
String |
getServiceIdForCall(ClientSideCallContext clientSideCallContext)
Returns the serviceId for this particular call to route to.
|
protected abstract AbstractRouterWithFailOverToNextNode.RouterStrategy |
getStrategy()
Return RouterStrategy - which should be used for current Router implementation.
|
protected AbstractRouterWithFailOverToNextNode()
AssertionError
in case when getStrategy() implementation is wrong ( result NULL ).public FailDecision callFailed(ClientSideCallContext clientSideCallContext)
FailingStrategy
callFailed
in interface FailingStrategy
public String getServiceIdForCall(ClientSideCallContext clientSideCallContext)
Router
getServiceIdForCall
in interface Router
clientSideCallContext
- context of the call with all call related data.public void customize(String s)
Router
protected void addModRoutedMethod(String mName, int modableParameterPosition)
mName
- name of method which should be routed using MOD strategymodableParameterPosition
- position of method argument for mod calculationsprotected void addModRoutedMethod(String mName)
mName
- name of method which should be routed using MOD strategyprotected org.slf4j.Logger getLog()
Logger
instance.Logger
protected abstract boolean failingSupported()
protected abstract AbstractRouterWithFailOverToNextNode.RouterStrategy getStrategy()
protected int getServiceAmount()
protected abstract long getModableValue(Object parameter)
parameter
- some method incoming parameterCopyright © 2010-2014 anotheria.net. All Rights Reserved.