use of org.apache.synapse.mediators.eip.sample.MessageQueue 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