Package org.apache.cxf.clustering
Class FailoverTargetSelector
- java.lang.Object
-
- org.apache.cxf.endpoint.AbstractConduitSelector
-
- org.apache.cxf.clustering.FailoverTargetSelector
-
- All Implemented Interfaces:
Closeable,AutoCloseable,ConduitSelector
- Direct Known Subclasses:
CircuitBreakerTargetSelector,LoadDistributorTargetSelector
public class FailoverTargetSelector extends AbstractConduitSelector
Implements a target selection strategy based on failover to an alternate target endpoint when a transport level failure is encountered. Note that this feature changes the conduit on the fly and thus makes the Client not thread safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classFailoverTargetSelector.InvocationContextRecords the context of an invocation.
-
Field Summary
Fields Modifier and Type Field Description protected FailoverStrategyfailoverStrategy-
Fields inherited from class org.apache.cxf.endpoint.AbstractConduitSelector
CONDUIT_COMPARE_FULL_URL, conduits, endpoint, KEEP_CONDUIT_ALIVE
-
-
Constructor Summary
Constructors Constructor Description FailoverTargetSelector()Normal constructor.FailoverTargetSelector(String clientBootstrapAddress)FailoverTargetSelector(Conduit c)Constructor, allowing a specific conduit to override normal selection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcomplete(Exchange exchange)Called on completion of the MEP for which the Conduit was required.protected voiddoComplete(Exchange exchange)StringgetClientBootstrapAddress()protected longgetDelayBetweenRetries()Returns delay (in milliseconds) between retriesprotected EndpointgetFailoverTarget(Exchange exchange, FailoverTargetSelector.InvocationContext invocation)Get the failover target endpoint, if a suitable one is available.protected FailoverTargetSelector.InvocationContextgetInvocationContext(String key)protected StringgetInvocationKey(Exchange e)protected LoggergetLogger()FailoverStrategygetStrategy()booleanisSupportNotAvailableErrorsOnly()protected voidonFailure(FailoverTargetSelector.InvocationContext context, Exception ex)protected voidonSuccess(FailoverTargetSelector.InvocationContext context)protected voidoverrideAddressProperty(Map<String,Object> context)Override the ENDPOINT_ADDRESS property in the request contextprotected voidoverrideAddressProperty(Map<String,Object> context, String address)protected booleanperformFailover(Exchange exchange, FailoverTargetSelector.InvocationContext invocation)voidprepare(Message message)Called prior to the interceptor chain being traversed.protected booleanreplaceEndpointAddressPropertyIfNeeded(Message message, String endpointAddress, Conduit cond)protected booleanrequiresFailover(Exchange exchange, Exception ex)Check if the exchange is suitable for a failover.ConduitselectConduit(Message message)Called when a Conduit is actually required.voidsetClientBootstrapAddress(String clientBootstrapAddress)protected voidsetOriginalEndpoint(FailoverTargetSelector.InvocationContext invocation)voidsetStrategy(FailoverStrategy strategy)voidsetSupportNotAvailableErrorsOnly(boolean support)protected voidsetupExchangeExceptionProperties(Exchange ex)protected List<String>updateContextAlternatives(Exchange exchange, FailoverTargetSelector.InvocationContext invocation)Fetches and updates the alternative address or/and alternative endpoints (depending on the strategy) for current invocation context.-
Methods inherited from class org.apache.cxf.endpoint.AbstractConduitSelector
close, createConduit, findCompatibleConduit, getEndpoint, getSelectedConduit, removeConduit, setEndpoint
-
-
-
-
Field Detail
-
failoverStrategy
protected FailoverStrategy failoverStrategy
-
-
Constructor Detail
-
FailoverTargetSelector
public FailoverTargetSelector()
Normal constructor.
-
FailoverTargetSelector
public FailoverTargetSelector(String clientBootstrapAddress)
-
FailoverTargetSelector
public FailoverTargetSelector(Conduit c)
Constructor, allowing a specific conduit to override normal selection.- Parameters:
c- specific conduit
-
-
Method Detail
-
prepare
public void prepare(Message message)
Called prior to the interceptor chain being traversed.- Parameters:
message- the current Message
-
setupExchangeExceptionProperties
protected void setupExchangeExceptionProperties(Exchange ex)
-
selectConduit
public Conduit selectConduit(Message message)
Called when a Conduit is actually required.- Parameters:
message-- Returns:
- the Conduit to use for mediation of the message
-
getInvocationContext
protected FailoverTargetSelector.InvocationContext getInvocationContext(String key)
-
complete
public void complete(Exchange exchange)
Called on completion of the MEP for which the Conduit was required.- Specified by:
completein interfaceConduitSelector- Overrides:
completein classAbstractConduitSelector- Parameters:
exchange- represents the completed MEP
-
doComplete
protected void doComplete(Exchange exchange)
-
setOriginalEndpoint
protected void setOriginalEndpoint(FailoverTargetSelector.InvocationContext invocation)
-
performFailover
protected boolean performFailover(Exchange exchange, FailoverTargetSelector.InvocationContext invocation)
-
onSuccess
protected void onSuccess(FailoverTargetSelector.InvocationContext context)
-
onFailure
protected void onFailure(FailoverTargetSelector.InvocationContext context, Exception ex)
-
setStrategy
public void setStrategy(FailoverStrategy strategy)
- Parameters:
strategy- the FailoverStrategy to use
-
getStrategy
public FailoverStrategy getStrategy()
- Returns:
- strategy the FailoverStrategy to use
-
getLogger
protected Logger getLogger()
- Specified by:
getLoggerin classAbstractConduitSelector- Returns:
- the logger to use
-
getDelayBetweenRetries
protected long getDelayBetweenRetries()
Returns delay (in milliseconds) between retries- Returns:
- delay, 0 means no delay
-
requiresFailover
protected boolean requiresFailover(Exchange exchange, Exception ex)
Check if the exchange is suitable for a failover.- Parameters:
exchange- the current Exchange- Returns:
- boolean true if a failover should be attempted
-
getFailoverTarget
protected Endpoint getFailoverTarget(Exchange exchange, FailoverTargetSelector.InvocationContext invocation)
Get the failover target endpoint, if a suitable one is available.- Parameters:
exchange- the current Exchangeinvocation- the current InvocationContext- Returns:
- a failover endpoint if one is available
-
updateContextAlternatives
protected List<String> updateContextAlternatives(Exchange exchange, FailoverTargetSelector.InvocationContext invocation)
Fetches and updates the alternative address or/and alternative endpoints (depending on the strategy) for current invocation context.- Parameters:
exchange- the current Exchangeinvocation- the current InvocationContext- Returns:
- alternative addresses
-
overrideAddressProperty
protected void overrideAddressProperty(Map<String,Object> context)
Override the ENDPOINT_ADDRESS property in the request context- Parameters:
context- the request context
-
overrideAddressProperty
protected void overrideAddressProperty(Map<String,Object> context, String address)
-
replaceEndpointAddressPropertyIfNeeded
protected boolean replaceEndpointAddressPropertyIfNeeded(Message message, String endpointAddress, Conduit cond)
- Overrides:
replaceEndpointAddressPropertyIfNeededin classAbstractConduitSelector
-
isSupportNotAvailableErrorsOnly
public boolean isSupportNotAvailableErrorsOnly()
-
setSupportNotAvailableErrorsOnly
public void setSupportNotAvailableErrorsOnly(boolean support)
-
getClientBootstrapAddress
public String getClientBootstrapAddress()
-
setClientBootstrapAddress
public void setClientBootstrapAddress(String clientBootstrapAddress)
-
-