use of org.apache.synapse.commons.throttle.core.AccessRateController in project wso2-synapse by wso2.
the class ThrottleMediator method init.
public void init(SynapseEnvironment se) {
if (onAcceptMediator instanceof ManagedLifecycle) {
((ManagedLifecycle) onAcceptMediator).init(se);
} else if (onAcceptSeqKey != null) {
SequenceMediator onAcceptSeq = (SequenceMediator) se.getSynapseConfiguration().getSequence(onAcceptSeqKey);
if (onAcceptSeq == null || onAcceptSeq.isDynamic()) {
se.addUnavailableArtifactRef(onAcceptSeqKey);
}
}
if (onRejectMediator instanceof ManagedLifecycle) {
((ManagedLifecycle) onRejectMediator).init(se);
} else if (onRejectSeqKey != null) {
SequenceMediator onRejectSeq = (SequenceMediator) se.getSynapseConfiguration().getSequence(onRejectSeqKey);
if (onRejectSeq == null || onRejectSeq.isDynamic()) {
se.addUnavailableArtifactRef(onRejectSeqKey);
}
}
// reference to axis2 configuration context
configContext = ((Axis2SynapseEnvironment) se).getAxis2ConfigurationContext();
// throttling data holder initialization of
// runtime throttle data eg :- throttle contexts
dataHolder = (ThrottleDataHolder) configContext.getProperty(ThrottleConstants.THROTTLE_INFO_KEY);
if (dataHolder == null) {
log.debug("Data holder not present in current Configuration Context");
synchronized (configContext) {
dataHolder = (ThrottleDataHolder) configContext.getProperty(ThrottleConstants.THROTTLE_INFO_KEY);
if (dataHolder == null) {
dataHolder = new ThrottleDataHolder();
configContext.setNonReplicableProperty(ThrottleConstants.THROTTLE_INFO_KEY, dataHolder);
}
}
}
// initializes whether clustering is enabled an Env. level
ClusteringAgent clusteringAgent = configContext.getAxisConfiguration().getClusteringAgent();
if (clusteringAgent != null) {
isClusteringEnable = true;
}
// static policy initialization
if (inLinePolicy != null) {
log.debug("Initializing using static throttling policy : " + inLinePolicy);
try {
throttle = ThrottleFactory.createMediatorThrottle(PolicyEngine.getPolicy(inLinePolicy));
if (throttle != null && concurrentAccessController == null) {
concurrentAccessController = throttle.getConcurrentAccessController();
if (concurrentAccessController != null) {
dataHolder.setConcurrentAccessController(key, concurrentAccessController);
}
}
} catch (ThrottleException e) {
handleException("Error processing the throttling policy", e, null);
}
}
// access rate controller initialization
accessControler = new AccessRateController();
// replicator for global concurrent state maintenance
if (isClusteringEnable) {
concurrentAccessReplicator = new ConcurrentAccessReplicator(configContext);
}
}
Aggregations