Search in sources :

Example 1 with Target

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);
        }
    }
}
Also used : Target(org.apache.synapse.mediators.eip.Target) Endpoint(org.apache.synapse.endpoints.Endpoint) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) ManagedLifecycle(org.apache.synapse.ManagedLifecycle)

Example 2 with Target

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);
}
Also used : Target(org.apache.synapse.mediators.eip.Target) AspectConfiguration(org.apache.synapse.aspects.AspectConfiguration)

Example 3 with Target

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;
}
Also used : Target(org.apache.synapse.mediators.eip.Target) Iterator(java.util.Iterator) OMAttribute(org.apache.axiom.om.OMAttribute) CloneMediator(org.apache.synapse.mediators.eip.splitter.CloneMediator)

Example 4 with Target

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;
}
Also used : Target(org.apache.synapse.mediators.eip.Target) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 5 with 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;
}
Also used : Target(org.apache.synapse.mediators.eip.Target) MessageQueue(org.apache.synapse.mediators.eip.sample.MessageQueue) SamplingThrottleMediator(org.apache.synapse.mediators.eip.sample.SamplingThrottleMediator) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

Target (org.apache.synapse.mediators.eip.Target)10 OMElement (org.apache.axiom.om.OMElement)5 OMAttribute (org.apache.axiom.om.OMAttribute)4 Endpoint (org.apache.synapse.endpoints.Endpoint)3 Iterator (java.util.Iterator)2 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)2 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)2 CloneMediator (org.apache.synapse.mediators.eip.splitter.CloneMediator)2 QName (javax.xml.namespace.QName)1 OperationContext (org.apache.axis2.context.OperationContext)1 MessageContext (org.apache.synapse.MessageContext)1 SynapseLog (org.apache.synapse.SynapseLog)1 AspectConfiguration (org.apache.synapse.aspects.AspectConfiguration)1 Evaluator (org.apache.synapse.commons.evaluators.Evaluator)1 EvaluatorException (org.apache.synapse.commons.evaluators.EvaluatorException)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 SharedDataHolder (org.apache.synapse.mediators.eip.SharedDataHolder)1 MessageQueue (org.apache.synapse.mediators.eip.sample.MessageQueue)1 SamplingThrottleMediator (org.apache.synapse.mediators.eip.sample.SamplingThrottleMediator)1 IterateMediator (org.apache.synapse.mediators.eip.splitter.IterateMediator)1