use of org.apache.synapse.mediators.eip.Target in project wso2-synapse by wso2.
the class CloneMediator method init.
public void init(SynapseEnvironment se) {
synapseEnv = se;
for (Target target : targets) {
ManagedLifecycle seq = target.getSequence();
if (seq != null) {
seq.init(se);
} else if (target.getSequenceRef() != null) {
SequenceMediator targetSequence = (SequenceMediator) se.getSynapseConfiguration().getSequence(target.getSequenceRef());
if (targetSequence == null || targetSequence.isDynamic()) {
se.addUnavailableArtifactRef(target.getSequenceRef());
}
}
Endpoint endpoint = target.getEndpoint();
if (endpoint != null) {
endpoint.init(se);
}
}
}
use of org.apache.synapse.mediators.eip.Target in project wso2-synapse by wso2.
the class CloneMediator method setComponentStatisticsId.
@Override
public void setComponentStatisticsId(ArtifactHolder holder) {
if (getAspectConfiguration() == null) {
configure(new AspectConfiguration(getMediatorName()));
}
String sequenceId = StatisticIdentityGenerator.getIdForFlowContinuableMediator(getMediatorName(), ComponentType.MEDIATOR, holder);
getAspectConfiguration().setUniqueId(sequenceId);
for (Target target : targets) {
target.setStatisticIdForMediators(holder);
}
StatisticIdentityGenerator.reportingFlowContinuableEndEvent(sequenceId, ComponentType.MEDIATOR, holder);
}
use of org.apache.synapse.mediators.eip.Target in project wso2-synapse by wso2.
the class CloneMediatorFactory method createSpecificMediator.
/**
* This method implements the createMediator method of the MediatorFactory interface
*
* @param elem - OMElement describing the element which will be parsed
* to build the CloneMediator
* @param properties
* @return Mediator of the type CloneMediator built from the config element
*/
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
boolean asynchronousExe = true;
CloneMediator mediator = new CloneMediator();
processAuditStatus(mediator, elem);
OMAttribute id = elem.getAttribute(ID_Q);
if (id != null) {
mediator.setId(id.getAttributeValue());
}
OMAttribute continueParent = elem.getAttribute(ATT_CONTINUE_PARENT);
if (continueParent != null) {
mediator.setContinueParent(JavaUtils.isTrueExplicitly(continueParent.getAttributeValue()));
}
OMAttribute synchronousExeAttr = elem.getAttribute(SEQUENTIAL_Q);
if (synchronousExeAttr != null && synchronousExeAttr.getAttributeValue().equals("true")) {
asynchronousExe = false;
}
mediator.setSequential(!asynchronousExe);
Iterator targetElements = elem.getChildrenWithName(TARGET_Q);
while (targetElements.hasNext()) {
Target target = TargetFactory.createTarget((OMElement) targetElements.next(), properties);
target.setAsynchronous(asynchronousExe);
mediator.addTarget(target);
}
return mediator;
}
use of org.apache.synapse.mediators.eip.Target in project wso2-synapse by wso2.
the class TargetFactory method createTarget.
/**
* This static method will be used to build the Target from the specified element
*
* @param elem - OMElement describing the xml configuration of the target
* @param properties bag of properties with information
* @return Target built by parsing the given element
*/
public static Target createTarget(OMElement elem, Properties properties) {
if (!TARGET_Q.equals(elem.getQName())) {
handleException("Element does not match with the target QName");
}
Target target = new Target();
OMAttribute toAttr = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "to"));
if (toAttr != null && toAttr.getAttributeValue() != null) {
target.setToAddress(toAttr.getAttributeValue());
}
OMAttribute soapAction = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "soapAction"));
if (soapAction != null && soapAction.getAttributeValue() != null) {
target.setSoapAction(soapAction.getAttributeValue());
}
OMAttribute sequenceAttr = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "sequence"));
if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
target.setSequenceRef(sequenceAttr.getAttributeValue());
}
OMAttribute endpointAttr = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "endpoint"));
if (endpointAttr != null && endpointAttr.getAttributeValue() != null) {
target.setEndpointRef(endpointAttr.getAttributeValue());
}
OMElement sequence = elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "sequence"));
if (sequence != null) {
SequenceMediatorFactory fac = new SequenceMediatorFactory();
target.setSequence(fac.createAnonymousSequence(sequence, properties));
}
OMElement endpoint = elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "endpoint"));
if (endpoint != null) {
target.setEndpoint(EndpointFactory.getEndpointFromElement(endpoint, true, properties));
}
return target;
}
use of org.apache.synapse.mediators.eip.Target in project wso2-synapse by wso2.
the class SamplingThrottleMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement omElement, Properties properties) {
SamplingThrottleMediator samplingThrottleMediator = new SamplingThrottleMediator();
processAuditStatus(samplingThrottleMediator, omElement);
OMAttribute idAttribute = omElement.getAttribute(ID_ATTR);
if (idAttribute != null) {
samplingThrottleMediator.setId(idAttribute.getAttributeValue());
}
OMAttribute rateAttribute = omElement.getAttribute(RATE_ATTR);
if (rateAttribute != null) {
try {
samplingThrottleMediator.setSamplingRate(Integer.parseInt(rateAttribute.getAttributeValue()));
} catch (NumberFormatException nfe) {
handleException("Sampling rate has to be an integer value, but found : " + rateAttribute.getAttributeValue());
}
}
OMAttribute unitTimeAttribute = omElement.getAttribute(UNIT_TIME_ATTR);
if (unitTimeAttribute != null) {
try {
samplingThrottleMediator.setUnitTime(Long.parseLong(unitTimeAttribute.getAttributeValue()));
} catch (NumberFormatException nfe) {
handleException("Sampling unitTime has to be a long value in milliseconds, " + "but found : " + rateAttribute.getAttributeValue());
}
}
OMElement targetElem = omElement.getFirstChildWithName(TARGET_Q);
if (targetElem != null) {
Target target = TargetFactory.createTarget(targetElem, properties);
samplingThrottleMediator.setTarget(target);
} else {
handleException("Sampler requires a target for the sampling mediation");
}
OMElement messageQueueElem = omElement.getFirstChildWithName(MESSAGE_QUEUE_Q);
if (messageQueueElem != null && messageQueueElem.getAttribute(CLASS_ATTR) != null) {
String className = messageQueueElem.getAttributeValue(CLASS_ATTR);
try {
Class messageQueueImplClass = Class.forName(className);
Object obj = messageQueueImplClass.newInstance();
if (obj instanceof MessageQueue) {
samplingThrottleMediator.setMessageQueue((MessageQueue) obj);
} else {
handleException("Provided message queue class : " + className + " doesn't implement the org.apache.synapse.mediators." + "eip.sample.MessageQueue interface");
}
} catch (ClassNotFoundException e) {
handleException("Couldn't find the class specified for the message queue " + "implementation : " + className);
} catch (InstantiationException e) {
handleException("Couldn't instantiate the message queue : " + className);
} catch (IllegalAccessException e) {
handleException("Couldn't instantiate the message queue : " + className);
}
}
return samplingThrottleMediator;
}
Aggregations