Package org.distributeme.core.routing
Class AbstractRouterWithStickyFailOverToNextNode
java.lang.Object
org.distributeme.core.routing.AbstractRouter
org.distributeme.core.routing.AbstractRouterWithStickyFailOverToNextNode
- All Implemented Interfaces:
FailingStrategy,ConfigurableRouter,Router,RouterConfigurationObserver
- Direct Known Subclasses:
RoundRobinRouterWithStickyFailoverToNextNode
public abstract class AbstractRouterWithStickyFailOverToNextNode
extends AbstractRouter
implements ConfigurableRouter, FailingStrategy, RouterConfigurationObserver
Abstract implementation of
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.- Version:
- $Id: $Id
- Author:
- h3llka,dvayanu
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddModRoutedMethod(String mName) Allow to add some custom method with some name using default 0 modable parameter position.protected voidaddModRoutedMethod(String mName, int modableParameterPosition) Allow to add some custom method with some name and modable parameter position to mod method registry.callFailed(ClientSideCallContext clientSideCallContext) What should happen if a call is failed.voidThis is old style customize.protected abstract booleanAllow to turn on and off failing support.protected GenericRouterConfigurationGetter for the fieldconfiguration.protected org.slf4j.LoggergetLog()Simply return configuredLoggerinstance.protected abstract longgetModableValue(Object parameter) Return long value for mod calculation.protected StringReturn serviceId based on Mod routing strategy.protected intgetRandomInt(int length) protected StringgetRRBasedServiceId(ClientSideCallContext context) Returns serviceId based on RoundRobin strategy.protected intReturn amount of services for which routing should be performed.getServiceIdForCall(ClientSideCallContext clientSideCallContext) Returns the serviceId for this particular call to route to.protected abstract RouterStrategyReturn RouterStrategy - which should be used for current Router implementation.voidrouterConfigurationChange(GenericRouterConfiguration configuration) Called after every router configuration change.voidrouterConfigurationFollowupChange(GenericRouterConfiguration configuration) Called uponvoidrouterConfigurationInitialChange(GenericRouterConfiguration configuration) Called upon FIRST configuration of the router.voidsetConfigurationName(String serviceId, String configurationName) Sets the configuration name and the service id.Methods inherited from class org.distributeme.core.routing.AbstractRouter
customize, getRoutingStats, setServiceId
-
Field Details
-
PARAMETER_KEY_SERVICES
Services parameter.- See Also:
-
PARAMETER_KEY_TIMEOUT
Timeout parameter.- See Also:
-
ATTR_TRIED_INSTANCES
Attribute for call context where we store instances that we already tried. -
UNDER_LINE
Underline constant.- See Also:
-
-
Constructor Details
-
AbstractRouterWithStickyFailOverToNextNode
public AbstractRouterWithStickyFailOverToNextNode()
-
-
Method Details
-
callFailed
What should happen if a call is failed.- Specified by:
callFailedin interfaceFailingStrategy- Parameters:
clientSideCallContext- aClientSideCallContextobject.- Returns:
- a
FailDecisionobject.
-
getServiceIdForCall
Returns the serviceId for this particular call to route to.- Specified by:
getServiceIdForCallin interfaceRouter- Parameters:
clientSideCallContext- context of the call with all call related data.- Returns:
- a
Stringobject.
-
getRandomInt
protected int getRandomInt(int length) -
customize
This is old style customize. It is called by the 'new' customize.- Overrides:
customizein classAbstractRouter- Parameters:
s- aStringobject.
-
setConfigurationName
Sets the configuration name and the service id.- Specified by:
setConfigurationNamein interfaceConfigurableRouter- Parameters:
serviceId- aStringobject.configurationName- aStringobject.
-
routerConfigurationInitialChange
Description copied from interface:RouterConfigurationObserverCalled upon FIRST configuration of the router.- Specified by:
routerConfigurationInitialChangein interfaceRouterConfigurationObserver- Parameters:
configuration- aGenericRouterConfigurationobject.
-
routerConfigurationFollowupChange
Description copied from interface:RouterConfigurationObserverCalled upon- Specified by:
routerConfigurationFollowupChangein interfaceRouterConfigurationObserver- Parameters:
configuration- aGenericRouterConfigurationobject.
-
routerConfigurationChange
Description copied from interface:RouterConfigurationObserverCalled after every router configuration change.- Specified by:
routerConfigurationChangein interfaceRouterConfigurationObserver- Parameters:
configuration- aGenericRouterConfigurationobject.
-
getRRBasedServiceId
Returns serviceId based on RoundRobin strategy.- Parameters:
context-ClientSideCallContext- Returns:
- serviceId string
-
getModBasedServiceId
Return serviceId based on Mod routing strategy. NOTE : it's native that not all methods supports such kind of routing strategy [MOD]. So, if some method does not supports MOD - strategy - then ROUND-ROBIN strategy will be used for such call.- Parameters:
context-ClientSideCallContext- Returns:
- serviceId string
-
getLog
protected org.slf4j.Logger getLog()Simply return configuredLoggerinstance.- Returns:
Logger
-
getConfiguration
Getter for the field
configuration.- Returns:
- a
GenericRouterConfigurationobject.
-
getServiceAmount
protected int getServiceAmount()Return amount of services for which routing should be performed. Current method should not return less then (int) 2 result, cause in that case router usage makes no sense, value validation will be performed in constructor.- Returns:
- int value
-
failingSupported
protected abstract boolean failingSupported()Allow to turn on and off failing support. Actually can be enabled or disabled per some implementation.- Returns:
- boolean value
-
getStrategy
Return RouterStrategy - which should be used for current Router implementation. Current method should not return NULL, value validation will be performed in constructor.- Returns:
RouterStrategy
-
getModableValue
Return long value for mod calculation.- Parameters:
parameter- some method incoming parameter- Returns:
- long value
-
addModRoutedMethod
Allow to add some custom method with some name and modable parameter position to mod method registry. Illegal argument exception will be thrown if any incoming parameter is not valid ( mName - is null or empty, modableParameterPosition is negative).- Parameters:
mName- name of method which should be routed using MOD strategymodableParameterPosition- position of method argument for mod calculations
-
addModRoutedMethod
Allow to add some custom method with some name using default 0 modable parameter position. Illegal argument exception will be thrown if mName - is null or empty.- Parameters:
mName- name of method which should be routed using MOD strategy
-