This class represents the endpoints referred by keys. It does not store the actual referred
endpoint as a private variable as it could expire. Therefore, it only stores the key and gets the
actual endpoint from the synapse configuration.
As this is also an instance of endpoint, this can be used any place, where a normal endpoint is
used.
Method from org.apache.synapse.endpoints.IndirectEndpoint Detail: |
protected void auditWarn(String msg,
MessageContext msgContext) {
log.warn(msg);
if (msgContext.getServiceLog() != null) {
msgContext.getServiceLog().warn(msg);
}
if (shouldTrace(msgContext)) {
trace.warn(msg);
}
}
|
public String getKey() {
return key;
}
|
public String getName() {
return name;
}
|
public boolean isActive(MessageContext synMessageContext) {
Endpoint endpoint = synMessageContext.getEndpoint(key);
if (endpoint == null) {
handleException("Reference to non-existent endpoint for key : " + key);
}
assert endpoint != null;
return endpoint.isActive(synMessageContext);
}
IndirectEndpoints are active if its referref endpoint is active and vise versa. Therefore,
this returns if its referred endpoint is active or not. |
public void onChildEndpointFail(Endpoint endpoint,
MessageContext synMessageContext) {
// if this is a child of some other endpoint, inform parent about the failure.
// if not, inform to the next fault handler.
if (parentEndpoint != null) {
parentEndpoint.onChildEndpointFail(this, synMessageContext);
} else {
Object o = synMessageContext.getFaultStack().pop();
if (o != null) {
((FaultHandler) o).handleFault(synMessageContext);
}
}
}
|
public void onFault(MessageContext synMessageContext) {
// At this point,child endpoint is in inactive state
// if this is a child of some other endpoint, inform parent about the failure.
// if not, inform to the next fault handler.
if (parentEndpoint != null) {
parentEndpoint.onChildEndpointFail(this, synMessageContext);
} else {
Object o = synMessageContext.getFaultStack().pop();
if (o != null) {
((FaultHandler) o).handleFault(synMessageContext);
}
}
}
|
public void send(MessageContext synMessageContext) {
// get the actual endpoint and send
Endpoint endpoint = synMessageContext.getEndpoint(key);
if (endpoint == null) {
handleException("Reference to non-existent endpoint for key : " + key);
}
assert endpoint != null;
if (endpoint.isActive(synMessageContext)) {
// register this as the immediate fault handler for this message.
synMessageContext.pushFaultHandler(this);
endpoint.send(synMessageContext);
} else {
// if this is a child of some other endpoint, inform parent about the failure.
// if not, inform to the next fault handler.
if (parentEndpoint != null) {
auditWarn("Endpoint : " + endpoint.getName() + " is currently inactive" +
" - invoking parent endpoint", synMessageContext);
parentEndpoint.onChildEndpointFail(this, synMessageContext);
} else {
auditWarn("Endpoint : " + endpoint.getName() + " is currently inactive" +
" - invoking fault handler / assuming failure", synMessageContext);
Object o = synMessageContext.getFaultStack().pop();
if (o != null) {
((FaultHandler) o).handleFault(synMessageContext);
}
}
}
}
|
public void setActive(boolean active,
MessageContext synMessageContext) {
Endpoint endpoint = synMessageContext.getEndpoint(key);
if (endpoint == null) {
handleException("Reference to non-existent endpoint for key : " + key);
}
assert endpoint != null;
endpoint.setActive(active, synMessageContext);
}
Activating or deactivating an IndirectEndpoint is the activating or deactivating its
referref endpoint. Therefore, this sets the active state of its referred endpoint. |
public void setKey(String key) {
this.key = key;
}
|
public void setName(String name) {
this.name = name.trim();
}
|
public void setParentEndpoint(Endpoint parentEndpoint) {
this.parentEndpoint = parentEndpoint;
}
|
public boolean shouldTrace(MessageContext synCtx) {
Endpoint endpoint = synCtx.getEndpoint(key);
EndpointDefinition endptDefn = null;
if (endpoint instanceof AddressEndpoint) {
AddressEndpoint addEndpt = (AddressEndpoint) endpoint;
endptDefn = addEndpt.getEndpoint();
} else if (endpoint instanceof WSDLEndpoint) {
WSDLEndpoint wsdlEndpt = (WSDLEndpoint) endpoint;
endptDefn = wsdlEndpt.getEndpoint();
}
return endptDefn != null && ((endptDefn.getTraceState() == SynapseConstants.TRACING_ON) ||
(endptDefn.getTraceState() == SynapseConstants.TRACING_UNSET &&
synCtx.getTracingState() == SynapseConstants.TRACING_ON));
}
|