Package org.apache.cxf.clustering
Class LoadDistributorTargetSelector
java.lang.Object
org.apache.cxf.endpoint.AbstractConduitSelector
org.apache.cxf.clustering.FailoverTargetSelector
org.apache.cxf.clustering.LoadDistributorTargetSelector
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.cxf.endpoint.ConduitSelector
The LoadDistributorTargetSelector attempts to do the same job as the
FailoverTargetSelector, but to choose an alternate target on every request
rather than just when a fault occurs.
The LoadDistributorTargetSelector uses the same FailoverStrategy interface as
the FailoverTargetSelector, but has a few significant limitations:
1. Because the LoadDistributorTargetSelector needs to maintain a list of targets
between calls it has to obtain that list without reference to a Message.
Most FailoverStrategy classes can support this for addresses, but it cannot
be supported for endpoints.
If the list of targets cannot be obtained without reference to a Message then
the list will still be obtained but it will be specific to the Message and thus
discarded after this message has been processed. As a consequence, if the
strategy chosen is a simple sequential one the first item in the list will
be chosen every time.
Conclusion: Be aware that if you are working with targets that are
dependent on the Message the process will be less efficient and that the
SequentialStrategy will not distribute the load at all.
2. The AbstractStaticFailoverStrategy base class excludes the 'default' endpoint
from the list of alternate endpoints.
If alternate endpoints (as opposed to alternate addresses) are to be used
you should probably ensure that your FailoverStrategy overrides getAlternateEndpoints
and calls getEndpoints with acceptCandidatesWithSameAddress = true.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.cxf.clustering.FailoverTargetSelector
FailoverTargetSelector.InvocationContext -
Field Summary
Fields inherited from class org.apache.cxf.clustering.FailoverTargetSelector
failoverStrategyFields inherited from class org.apache.cxf.endpoint.AbstractConduitSelector
CONDUIT_COMPARE_FULL_URL, conduits, endpoint, KEEP_CONDUIT_ALIVE -
Constructor Summary
ConstructorsConstructorDescriptionNormal constructor.LoadDistributorTargetSelector(String clientBootstrapAddress) LoadDistributorTargetSelector(org.apache.cxf.transport.Conduit c) Constructor, allowing a specific conduit to override normal selection. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.cxf.endpoint.EndpointgetFailoverTarget(org.apache.cxf.message.Exchange exchange, FailoverTargetSelector.InvocationContext invocation) Get the failover target endpoint, if a suitable one is available.protected Loggerbooleanprotected booleanrequiresFailover(org.apache.cxf.message.Exchange exchange, Exception ex) Check if the exchange is suitable for a failover.org.apache.cxf.transport.ConduitselectConduit(org.apache.cxf.message.Message message) Called when a Conduit is actually required.voidsetFailover(boolean failover) Methods inherited from class org.apache.cxf.clustering.FailoverTargetSelector
complete, doComplete, getClientBootstrapAddress, getDelayBetweenRetries, getInvocationContext, getInvocationKey, getStrategy, isSupportNotAvailableErrorsOnly, onFailure, onSuccess, overrideAddressProperty, overrideAddressProperty, performFailover, prepare, replaceEndpointAddressPropertyIfNeeded, setClientBootstrapAddress, setOriginalEndpoint, setStrategy, setSupportNotAvailableErrorsOnly, setupExchangeExceptionProperties, updateContextAlternativesMethods inherited from class org.apache.cxf.endpoint.AbstractConduitSelector
close, createConduit, findCompatibleConduit, getEndpoint, getSelectedConduit, removeConduit, setEndpoint
-
Constructor Details
-
LoadDistributorTargetSelector
public LoadDistributorTargetSelector()Normal constructor. -
LoadDistributorTargetSelector
-
LoadDistributorTargetSelector
public LoadDistributorTargetSelector(org.apache.cxf.transport.Conduit c) Constructor, allowing a specific conduit to override normal selection.- Parameters:
c- specific conduit
-
-
Method Details
-
isFailover
public boolean isFailover() -
setFailover
public void setFailover(boolean failover) -
getLogger
- Overrides:
getLoggerin classFailoverTargetSelector- Returns:
- the logger to use
-
selectConduit
public org.apache.cxf.transport.Conduit selectConduit(org.apache.cxf.message.Message message) Called when a Conduit is actually required.- Specified by:
selectConduitin interfaceorg.apache.cxf.endpoint.ConduitSelector- Overrides:
selectConduitin classFailoverTargetSelector- Parameters:
message-- Returns:
- the Conduit to use for mediation of the message
-
getFailoverTarget
protected org.apache.cxf.endpoint.Endpoint getFailoverTarget(org.apache.cxf.message.Exchange exchange, FailoverTargetSelector.InvocationContext invocation) Get the failover target endpoint, if a suitable one is available.- Overrides:
getFailoverTargetin classFailoverTargetSelector- Parameters:
exchange- the current Exchangeinvocation- the current InvocationContext- Returns:
- a failover endpoint if one is available Note: The only difference between this and the super implementation is that the current (failed) address is removed from the list set of alternates, it could be argued that that change should be in the super implementation but I'm not sure of the impact.
-
requiresFailover
Description copied from class:FailoverTargetSelectorCheck if the exchange is suitable for a failover.- Overrides:
requiresFailoverin classFailoverTargetSelector- Parameters:
exchange- the current Exchange- Returns:
- boolean true if a failover should be attempted
-