use of org.apache.axis2.description.AxisDescription in project wso2-synapse by wso2.
the class ThrottleEnguageUtils method enguage.
public static void enguage(AxisDescription axisDescription, ConfigurationContext configctx, Throttle defaultThrottle) throws AxisFault {
String currentServiceName;
if (axisDescription instanceof AxisService) {
Throttle throttle = null;
AxisService currentService = ((AxisService) axisDescription);
PolicySubject policySubject = currentService.getPolicySubject();
if (policySubject != null) {
try {
List policies = new ArrayList(policySubject.getAttachedPolicyComponents());
Policy currentPolicy = PolicyUtil.getMergedPolicy(policies, currentService);
if (currentPolicy != null) {
throttle = ThrottleFactory.createServiceThrottle(currentPolicy);
if (throttle == null) {
// this is for the scenario when throttle policy is empty rather than
// null (eg: removing the throttle policy via policy editor)
throttle = defaultThrottle;
}
// todo - done by isuru, recheck
} else {
AxisConfiguration axisConfig = configctx.getAxisConfiguration();
AxisModule throttleModule = axisConfig.getModule(ThrottleConstants.THROTTLE_MODULE_NAME);
policySubject = throttleModule.getPolicySubject();
if (policySubject != null) {
currentPolicy = ThrottleEnguageUtils.getThrottlePolicy(policySubject.getAttachedPolicyComponents());
if (currentPolicy != null) {
throttle = ThrottleFactory.createModuleThrottle(currentPolicy);
}
}
// todo - done by isuru
}
} catch (ThrottleException e) {
log.error("Error was occurred when engaging throttle module for" + " the service :" + currentService.getName() + e.getMessage());
log.info("Throttling will occur using default module policy");
throttle = defaultThrottle;
}
if (throttle != null) {
Map throttles = (Map) configctx.getPropertyNonReplicable(ThrottleConstants.THROTTLES_MAP);
if (throttles == null) {
throttles = new HashMap();
configctx.setNonReplicableProperty(ThrottleConstants.THROTTLES_MAP, throttles);
}
String serviceName = currentService.getName();
throttle.setId(serviceName);
throttles.put(serviceName, throttle);
ConcurrentAccessController cac = throttle.getConcurrentAccessController();
if (cac != null) {
String cacKey = ThrottleConstants.THROTTLE_PROPERTY_PREFIX + serviceName + ThrottleConstants.CAC_SUFFIX;
configctx.setProperty(cacKey, cac);
}
}
}
} else if (axisDescription instanceof AxisOperation) {
Throttle throttle = null;
AxisOperation currentOperation = ((AxisOperation) axisDescription);
AxisService axisService = (AxisService) currentOperation.getParent();
if (axisService != null) {
currentServiceName = axisService.getName();
PolicySubject policySubject = currentOperation.getPolicySubject();
if (policySubject != null) {
try {
List policies = new ArrayList(policySubject.getAttachedPolicyComponents());
Policy currentPolicy = PolicyUtil.getMergedPolicy(policies, currentOperation);
if (currentPolicy != null) {
throttle = ThrottleFactory.createOperationThrottle(currentPolicy);
}
} catch (ThrottleException e) {
log.error("Error was occurred when engaging throttle module " + "for operation : " + currentOperation.getName() + " in the service :" + currentServiceName + e.getMessage());
log.info("Throttling will occur using default module policy");
}
// if current throttle is null, use the default throttle
if (throttle == null) {
throttle = defaultThrottle;
}
Map throttles = (Map) configctx.getPropertyNonReplicable(ThrottleConstants.THROTTLES_MAP);
if (throttles == null) {
throttles = new HashMap();
configctx.setNonReplicableProperty(ThrottleConstants.THROTTLES_MAP, throttles);
}
QName opQName = currentOperation.getName();
if (opQName != null) {
String opName = opQName.getLocalPart();
String key = currentServiceName + opName;
throttle.setId(key);
throttles.put(key, throttle);
ConcurrentAccessController cac = throttle.getConcurrentAccessController();
if (cac != null) {
String cacKey = ThrottleConstants.THROTTLE_PROPERTY_PREFIX + key + ThrottleConstants.CAC_SUFFIX;
configctx.setProperty(cacKey, cac);
}
}
}
}
}
}
use of org.apache.axis2.description.AxisDescription in project wso2-synapse by wso2.
the class ThrottleObserver method serviceUpdate.
public void serviceUpdate(AxisEvent axisEvent, AxisService axisService) {
log.debug("ThrottleObserver notified for a serviceUpdate.");
AxisDescription axisDescription = axisEvent.getAxisDescription();
if (axisDescription.isEngaged(axisService.getAxisConfiguration().getModule(ThrottleConstants.THROTTLE_MODULE_NAME))) {
if (axisEvent.getEventType() == AxisEvent.POLICY_ADDED) {
try {
ThrottleEnguageUtils.enguage(axisDescription, configctx, defautThrottle);
} catch (AxisFault axisFault) {
log.error("Error while re-engaging throttling", axisFault);
}
}
}
}
Aggregations