Package org.apache.synapse.endpoints
Class LoadbalanceEndpoint
- java.lang.Object
-
- org.apache.synapse.FaultHandler
-
- org.apache.synapse.endpoints.AbstractEndpoint
-
- org.apache.synapse.endpoints.LoadbalanceEndpoint
-
- All Implemented Interfaces:
Endpoint
,ManagedLifecycle
,Nameable
,PropertyInclude
,SynapseArtifact
- Direct Known Subclasses:
DynamicLoadbalanceEndpoint
,SALoadbalanceEndpoint
public class LoadbalanceEndpoint extends AbstractEndpoint
A Load balance endpoint contains multiple child endpoints. It routes messages according to the specified load balancing algorithm. This will assume that all immediate child endpoints are identical in state (state is replicated) or state is not maintained at those endpoints. If an endpoint is failing, the failed endpoint is marked as inactive and the message sent to the next endpoint obtained using the load balancing algorithm. If all the endpoints have failed and a parent endpoint is available, onChildEndpointFail(...) method of parent endpoint is called. If a parent is not available, this will call next FaultHandler for the message context.
-
-
Field Summary
-
Fields inherited from class org.apache.synapse.endpoints.AbstractEndpoint
anonymous, artifactContainerName, CHILDREN_JSON_ATT, errorHandler, fileName, initialized, isClusteringEnabled, log, NAME_JSON_ATT, trace, TYPE_JSON_ATT
-
-
Constructor Summary
Constructors Constructor Description LoadbalanceEndpoint()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
createJsonRepresentation()
void
destroy()
This method should implement the destroying of the implemented parts of the configuration.LoadbalanceAlgorithm
getAlgorithm()
List<org.apache.axis2.clustering.Member>
getMembers()
protected Endpoint
getNextChild(MessageContext synCtx)
void
init(SynapseEnvironment synapseEnvironment)
This method should implement the initialization of the implemented parts of the configuration.boolean
isBuildMessageAtt()
boolean
isFailover()
boolean
isInitialized()
NOTE: Override org.apache.synapse.endpoints.AbstractEndpoint#isInitialized() to ensure return true only after LB Endpoint get fully initialized.void
onChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext)
Endpoints that contain other endpoints should implement this method.boolean
readyToSend()
If this endpoint is in inactive state, checks if all immediate child endpoints are still failed.void
send(MessageContext synCtx)
Sends the message context according to an endpoint specific behavior.void
setAlgorithm(LoadbalanceAlgorithm algorithm)
void
setBuildMessageAtt(boolean build)
void
setBuildMessageAttAvailable(boolean available)
void
setFailover(boolean failover)
void
setMembers(List<org.apache.axis2.clustering.Member> members)
void
startApplicationMembershipTimer()
-
Methods inherited from class org.apache.synapse.endpoints.AbstractEndpoint
addProperties, addProperty, evaluateProperties, executeEpTypeSpecificFunctions, getArtifactContainerName, getChildren, getCommentsList, getContext, getDefinition, getDescription, getEndpointChildrenAsJson, getErrorHandler, getFileName, getIsEdited, getJsonRepresentation, getMetricsMBean, getName, getParentEndpoint, getProperties, getProperty, getReportingName, getValue, handleException, handleException, handleException, informFailure, isAnonymous, isLeafEndpoint, isRetry, isSuspendFault, isTimeout, isTraceOn, isTraceOrDebugOn, logOnChildEndpointFail, logSetter, onFault, onSuccess, prepareForEndpointStatistics, removeProperty, setAdvancedProperties, setAnonymous, setArtifactContainerName, setChildren, setCommentsList, setComponentStatisticsId, setContentAware, setDefinition, setDescription, setEnableMBeanStats, setErrorHandler, setErrorOnMessage, setFileName, setForceBuildMC, setIsEdited, setName, setParentEndpoint, setValue, toString, traceOrDebug
-
Methods inherited from class org.apache.synapse.FaultHandler
executeExtendedSynapseHandlerOnFault, getStackTrace, handleFault, handleFault
-
-
-
-
Method Detail
-
init
public void init(SynapseEnvironment synapseEnvironment)
Description copied from interface:ManagedLifecycle
This method should implement the initialization of the implemented parts of the configuration.- Specified by:
init
in interfaceManagedLifecycle
- Overrides:
init
in classAbstractEndpoint
- Parameters:
synapseEnvironment
- SynapseEnvironment to be used for initialization
-
destroy
public void destroy()
Description copied from interface:ManagedLifecycle
This method should implement the destroying of the implemented parts of the configuration.- Specified by:
destroy
in interfaceManagedLifecycle
- Overrides:
destroy
in classAbstractEndpoint
-
isInitialized
public boolean isInitialized()
NOTE: Override org.apache.synapse.endpoints.AbstractEndpoint#isInitialized() to ensure return true only after LB Endpoint get fully initialized. This is done to avoid super.isInitialized return true while LoadbalanceEndpoint initializing during request burst *at server startup*- Specified by:
isInitialized
in interfaceEndpoint
- Overrides:
isInitialized
in classAbstractEndpoint
- Returns:
-
createJsonRepresentation
protected void createJsonRepresentation()
- Specified by:
createJsonRepresentation
in classAbstractEndpoint
-
send
public void send(MessageContext synCtx)
Description copied from interface:Endpoint
Sends the message context according to an endpoint specific behavior.- Specified by:
send
in interfaceEndpoint
- Overrides:
send
in classAbstractEndpoint
- Parameters:
synCtx
- MessageContext to be sent.
-
readyToSend
public boolean readyToSend()
If this endpoint is in inactive state, checks if all immediate child endpoints are still failed. If so returns false. If at least one child endpoint is in active state, sets this endpoint's state to active and returns true. As this a sessionless load balancing endpoint having one active child endpoint is enough to consider this as active.- Specified by:
readyToSend
in interfaceEndpoint
- Overrides:
readyToSend
in classAbstractEndpoint
- Returns:
- true if active. false otherwise.
-
onChildEndpointFail
public void onChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext)
Description copied from interface:Endpoint
Endpoints that contain other endpoints should implement this method. It will be called if a child endpoint causes an exception. Action to be taken on such failure is up to the implementation. But it is good practice to first try addressing the issue. If it can't be addressed propagate the exception to parent endpoint by calling parent endpoint's onChildEndpointFail(...) method.- Specified by:
onChildEndpointFail
in interfaceEndpoint
- Overrides:
onChildEndpointFail
in classAbstractEndpoint
- Parameters:
endpoint
- The child endpoint which caused the exception.synMessageContext
- MessageContext that was used in the failed attempt.
-
isFailover
public boolean isFailover()
-
isBuildMessageAtt
public boolean isBuildMessageAtt()
-
setFailover
public void setFailover(boolean failover)
-
getAlgorithm
public LoadbalanceAlgorithm getAlgorithm()
-
setAlgorithm
public void setAlgorithm(LoadbalanceAlgorithm algorithm)
-
getNextChild
protected Endpoint getNextChild(MessageContext synCtx)
-
setMembers
public void setMembers(List<org.apache.axis2.clustering.Member> members)
-
getMembers
public List<org.apache.axis2.clustering.Member> getMembers()
-
startApplicationMembershipTimer
public void startApplicationMembershipTimer()
-
setBuildMessageAtt
public void setBuildMessageAtt(boolean build)
-
setBuildMessageAttAvailable
public void setBuildMessageAttAvailable(boolean available)
-
-