org.apache.synapse.endpoints
Class AbstractEndpoint

java.lang.Object
  extended by org.apache.synapse.FaultHandler
      extended by org.apache.synapse.endpoints.AbstractEndpoint
All Implemented Interfaces:
Endpoint, ManagedLifecycle, Nameable, PropertyInclude, SynapseArtifact
Direct Known Subclasses:
AddressEndpoint, DefaultEndpoint, FailoverEndpoint, IndirectEndpoint, LoadbalanceEndpoint, RecipientListEndpoint, ResolvingEndpoint, TemplateEndpoint, WSDLEndpoint

public abstract class AbstractEndpoint
extends FaultHandler
implements Endpoint, PropertyInclude

An abstract base class for all Endpoint implementations


Field Summary
protected  boolean anonymous
           
protected  String errorHandler
          The Sequence name associated with the endpoint
protected  String fileName
          The name of the file where this endpoint is defined
protected  boolean initialized
          Has this endpoint been initialized ?
protected  Boolean isClusteringEnabled
          Is clustering enabled
protected  org.apache.commons.logging.Log log
           
protected static org.apache.commons.logging.Log trace
           
 
Constructor Summary
protected AbstractEndpoint()
           
 
Method Summary
 void addProperties(Collection<MediatorProperty> mediatorProperties)
          Add all the properties to the endpoint
 void addProperty(MediatorProperty property)
          Add a property to the endpoint.
 void destroy()
          This method should implement the destroying of the implemented parts of the configuration.
protected  void evaluateProperties(MessageContext synCtx)
          Evaluates the endpoint properties based on the current message context and set the properties to the message context appropriately
 List<Endpoint> getChildren()
          Get the children of this endpoint
 EndpointContext getContext()
          Get the EndpointContext that has the run-time state of this endpoint
 EndpointDefinition getDefinition()
           
 String getDescription()
          Retrieves the description of the artifact
 String getErrorHandler()
          Get the MessageStore name associated with the Endpoint
 String getFileName()
          Get the filename from which this endpoint is loaded, null if it is an anonymous endpoint
 EndpointView getMetricsMBean()
          Get a reference to the metrics MBean for this endpoint
 String getName()
          Get the name of an abstraction
 Endpoint getParentEndpoint()
           
 Collection<MediatorProperty> getProperties()
          Return the Collection of properties specified
 MediatorProperty getProperty(String name)
          Get a property with the given name
protected  void handleException(String msg)
          Helper methods to handle errors.
protected  void handleException(String msg, Exception e)
          Helper methods to handle errors.
protected  void informFailure(MessageContext synCtx, int errorCode, String errorMsg)
           
 void init(SynapseEnvironment synapseEnvironment)
          This method should implement the initialization of the implemented parts of the configuration.
 boolean isAnonymous()
           
 boolean isInitialized()
          Has this Endpoint initialized?
 boolean isLeafEndpoint()
          Is this a leaf level endpoint? or parent endpoint that has children?
protected  boolean isRetryDisabled(MessageContext synCtx)
           
protected  boolean isSuspendFault(MessageContext synCtx)
          Is this a fault that should put the endpoint on SUSPEND? or is this a fault to ignore?
protected  boolean isTimeout(MessageContext synCtx)
          Is this [fault] message a timeout?
protected  boolean isTraceOn(MessageContext msgCtx)
          Should this mediator perform tracing? True if its explicitly asked to trace, or its parent has been asked to trace and it does not reject it
protected  boolean isTraceOrDebugOn(boolean isTraceOn)
          Is tracing or debug logging on?
protected  void logOnChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext)
           
 void onChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext)
          Endpoints that contain other endpoints should implement this method.
 void onFault(MessageContext synCtx)
          On a fault, propagate to parent if any, or call into the fault handler
 void onSuccess()
          The SynapseCallback Receiver notifies an endpoint, if a message was successfully processed to give it a chance to clear up or reset its state to active
protected  void prepareForEndpointStatistics(MessageContext synCtx)
          Process statistics for this message
 boolean readyToSend()
          Returns true to indicate that the endpoint is ready to service requests
 MediatorProperty removeProperty(String name)
          Remove a property with the given name
 void send(MessageContext synCtx)
          Sends the message context according to an endpoint specific behavior.
 void setAnonymous(boolean anonymous)
           
 void setChildren(List<Endpoint> children)
           
 void setDefinition(EndpointDefinition definition)
           
 void setDescription(String description)
          Set the description of the artifact
 void setEnableMBeanStats(boolean flag)
          set whether this endpoint needs to be registered for JMX Mbeans.
 void setErrorHandler(String errorHandler)
          Set the Message Store name associated with the Endpoint
protected  void setErrorOnMessage(MessageContext synCtx, String errorCode, String errorMsg)
           
 void setFileName(String fileName)
          Set the filename from which the endpoint is loaded
 void setName(String endpointName)
          Set the name of an abstraction
 void setParentEndpoint(Endpoint parentEndpoint)
          Sets the parent endpoint for the current endpoint.
 String toString()
           
protected  void traceOrDebug(boolean traceOn, String msg)
          Perform Trace and Debug logging of a message @INFO (trace) and DEBUG (log)
 
Methods inherited from class org.apache.synapse.FaultHandler
getStackTrace, handleFault, handleFault
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected org.apache.commons.logging.Log log

trace

protected static final org.apache.commons.logging.Log trace

initialized

protected boolean initialized
Has this endpoint been initialized ?


isClusteringEnabled

protected Boolean isClusteringEnabled
Is clustering enabled


fileName

protected String fileName
The name of the file where this endpoint is defined


anonymous

protected boolean anonymous

errorHandler

protected String errorHandler
The Sequence name associated with the endpoint

Constructor Detail

AbstractEndpoint

protected AbstractEndpoint()
Method Detail

getMetricsMBean

public EndpointView getMetricsMBean()
Description copied from interface: Endpoint
Get a reference to the metrics MBean for this endpoint

Specified by:
getMetricsMBean in interface Endpoint
Returns:
EndpointView instance

getContext

public EndpointContext getContext()
Description copied from interface: Endpoint
Get the EndpointContext that has the run-time state of this endpoint

Specified by:
getContext in interface Endpoint
Returns:
the runtime context

getName

public String getName()
Description copied from interface: Nameable
Get the name of an abstraction

Specified by:
getName in interface Nameable
Returns:
String Representation of name

isInitialized

public boolean isInitialized()
Description copied from interface: Endpoint
Has this Endpoint initialized?

Specified by:
isInitialized in interface Endpoint
Returns:
true if the endpoint is initialized

getDefinition

public EndpointDefinition getDefinition()

setDefinition

public void setDefinition(EndpointDefinition definition)

getParentEndpoint

public Endpoint getParentEndpoint()

setParentEndpoint

public void setParentEndpoint(Endpoint parentEndpoint)
Description copied from interface: Endpoint
Sets the parent endpoint for the current endpoint.

Specified by:
setParentEndpoint in interface Endpoint
Parameters:
parentEndpoint - parent endpoint containing this endpoint. It should handle the onChildEndpointFail(...) callback.

getChildren

public List<Endpoint> getChildren()
Description copied from interface: Endpoint
Get the children of this endpoint

Specified by:
getChildren in interface Endpoint
Returns:
the child endpoints

setChildren

public void setChildren(List<Endpoint> children)

getFileName

public String getFileName()
Description copied from interface: Endpoint
Get the filename from which this endpoint is loaded, null if it is an anonymous endpoint

Specified by:
getFileName in interface Endpoint
Returns:
String file name

setFileName

public void setFileName(String fileName)
Description copied from interface: Endpoint
Set the filename from which the endpoint is loaded

Specified by:
setFileName in interface Endpoint
Parameters:
fileName - from which the endpoint is loaded

isAnonymous

public boolean isAnonymous()

setAnonymous

public void setAnonymous(boolean anonymous)

setDescription

public void setDescription(String description)
Description copied from interface: SynapseArtifact
Set the description of the artifact

Specified by:
setDescription in interface SynapseArtifact
Parameters:
description - tobe set to the artifact

getDescription

public String getDescription()
Description copied from interface: SynapseArtifact
Retrieves the description of the artifact

Specified by:
getDescription in interface SynapseArtifact
Returns:
description of the artifact

toString

public String toString()
Overrides:
toString in class Object

setName

public void setName(String endpointName)
Description copied from interface: Nameable
Set the name of an abstraction

Specified by:
setName in interface Nameable
Parameters:
endpointName - String Representation of name

setEnableMBeanStats

public void setEnableMBeanStats(boolean flag)
set whether this endpoint needs to be registered for JMX Mbeans. some endpoints may not need to register under MBean and setting false will cut the additional overhead.

Parameters:
flag - set true/false

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 interface ManagedLifecycle
Parameters:
synapseEnvironment - SynapseEnvironment to be used for initialization

readyToSend

public boolean readyToSend()
Description copied from interface: Endpoint
Returns true to indicate that the endpoint is ready to service requests

Specified by:
readyToSend in interface Endpoint
Returns:
true if endpoint is ready to service requests

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 interface Endpoint
Parameters:
synCtx - MessageContext to be sent.

isLeafEndpoint

public boolean isLeafEndpoint()
Is this a leaf level endpoint? or parent endpoint that has children?

Returns:
true if there is no children - a leaf endpoint

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 interface Endpoint
Parameters:
endpoint - The child endpoint which caused the exception.
synMessageContext - MessageContext that was used in the failed attempt.

isTimeout

protected boolean isTimeout(MessageContext synCtx)
Is this [fault] message a timeout?

Parameters:
synCtx - the current fault message
Returns:
true if this is defined as a timeout

isRetryDisabled

protected boolean isRetryDisabled(MessageContext synCtx)

isSuspendFault

protected boolean isSuspendFault(MessageContext synCtx)
Is this a fault that should put the endpoint on SUSPEND? or is this a fault to ignore?

Parameters:
synCtx - the current fault message
Returns:
true if this fault should suspend the endpoint

onFault

public void onFault(MessageContext synCtx)
On a fault, propagate to parent if any, or call into the fault handler

Specified by:
onFault in class FaultHandler
Parameters:
synCtx - the message at hand

onSuccess

public void onSuccess()
The SynapseCallback Receiver notifies an endpoint, if a message was successfully processed to give it a chance to clear up or reset its state to active

Specified by:
onSuccess in interface Endpoint

isTraceOn

protected boolean isTraceOn(MessageContext msgCtx)
Should this mediator perform tracing? True if its explicitly asked to trace, or its parent has been asked to trace and it does not reject it

Parameters:
msgCtx - the current message
Returns:
true if tracing should be performed

isTraceOrDebugOn

protected boolean isTraceOrDebugOn(boolean isTraceOn)
Is tracing or debug logging on?

Parameters:
isTraceOn - is tracing known to be on?
Returns:
true, if either tracing or debug logging is on

traceOrDebug

protected void traceOrDebug(boolean traceOn,
                            String msg)
Perform Trace and Debug logging of a message @INFO (trace) and DEBUG (log)

Parameters:
traceOn - is runtime trace on for this message?
msg - the message to log/trace

prepareForEndpointStatistics

protected void prepareForEndpointStatistics(MessageContext synCtx)
Process statistics for this message

Parameters:
synCtx - the current message

handleException

protected void handleException(String msg)
Helper methods to handle errors.

Parameters:
msg - The error message

handleException

protected void handleException(String msg,
                               Exception e)
Helper methods to handle errors.

Parameters:
msg - The error message
e - The exception

logOnChildEndpointFail

protected void logOnChildEndpointFail(Endpoint endpoint,
                                      MessageContext synMessageContext)

informFailure

protected void informFailure(MessageContext synCtx,
                             int errorCode,
                             String errorMsg)

setErrorOnMessage

protected void setErrorOnMessage(MessageContext synCtx,
                                 String errorCode,
                                 String errorMsg)

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 interface ManagedLifecycle

addProperty

public void addProperty(MediatorProperty property)
Add a property to the endpoint.

Specified by:
addProperty in interface PropertyInclude
Parameters:
property - property to be added

getProperty

public MediatorProperty getProperty(String name)
Get a property with the given name

Specified by:
getProperty in interface PropertyInclude
Parameters:
name - name of the property
Returns:
a property with the given name

getProperties

public Collection<MediatorProperty> getProperties()
Return the Collection of properties specified

Specified by:
getProperties in interface PropertyInclude
Returns:
Collection of properties

removeProperty

public MediatorProperty removeProperty(String name)
Remove a property with the given name

Specified by:
removeProperty in interface PropertyInclude
Parameters:
name - name of the property to be removed
Returns:
the remove property or null if a property doesn't exists

addProperties

public void addProperties(Collection<MediatorProperty> mediatorProperties)
Add all the properties to the endpoint

Specified by:
addProperties in interface PropertyInclude
Parameters:
mediatorProperties - Collection of properties to be added

getErrorHandler

public String getErrorHandler()
Description copied from interface: Endpoint
Get the MessageStore name associated with the Endpoint

Specified by:
getErrorHandler in interface Endpoint
Returns:
String message store name

setErrorHandler

public void setErrorHandler(String errorHandler)
Description copied from interface: Endpoint
Set the Message Store name associated with the Endpoint

Specified by:
setErrorHandler in interface Endpoint

evaluateProperties

protected void evaluateProperties(MessageContext synCtx)
Evaluates the endpoint properties based on the current message context and set the properties to the message context appropriately

Parameters:
synCtx - the current message context


Copyright © 2005-2012 Apache Software Foundation. All Rights Reserved.