use of org.wso2.carbon.apimgt.gateway.throttling.publisher.ThrottleDataPublisher in project carbon-apimgt by wso2.
the class ServerStartupListener method completedServerStartup.
@Override
public void completedServerStartup() {
// This prevents errors in an All in one setup caused by the ThrottleDataPublisher trying to connect to the
// event receiver, before the event receiver has been started on completion of server startup.
ServiceReferenceHolder.getInstance().setThrottleDataPublisher(new ThrottleDataPublisher());
ThrottleDataHolder throttleDataHolder = new ThrottleDataHolder();
APIThrottleDataServiceImpl throttleDataServiceImpl = new APIThrottleDataServiceImpl(throttleDataHolder);
CacheInvalidationService cacheInvalidationService = new CacheInvalidationServiceImpl();
// Register APIThrottleDataService so that ThrottleData maps are available to other components.
ServiceReferenceHolder.getInstance().setCacheInvalidationService(cacheInvalidationService);
ServiceReferenceHolder.getInstance().setAPIThrottleDataService(throttleDataServiceImpl);
ServiceReferenceHolder.getInstance().setThrottleDataHolder(throttleDataHolder);
ServiceReferenceHolder.getInstance().setRevokedTokenService(new RevokedTokenDataImpl());
SubscriptionsDataService subscriptionsDataService = new SubscriptionsDataServiceImpl();
ServiceReferenceHolder.getInstance().setSubscriptionsDataService(subscriptionsDataService);
log.debug("APIThrottleDataService Registered...");
}
use of org.wso2.carbon.apimgt.gateway.throttling.publisher.ThrottleDataPublisher in project carbon-apimgt by wso2.
the class ThrottleHandler method handleRequest.
/**
* Handle incoming requests and call throttling method to perform throttling.
*
* @param messageContext message context object which contains message details.
* @return return true if message flow need to continue and pass requests to next handler in chain. Else return
* false to notify error with handler
*/
public boolean handleRequest(MessageContext messageContext) {
if (Utils.isGraphQLSubscriptionRequest(messageContext)) {
if (log.isDebugEnabled()) {
log.debug("Skipping GraphQL subscription handshake request.");
}
return true;
}
if (ServiceReferenceHolder.getInstance().getThrottleDataPublisher() == null) {
log.error("Cannot publish events to traffic manager because ThrottleDataPublisher " + "has not been initialised");
return true;
}
Timer timer3 = getTimer(MetricManager.name(APIConstants.METRICS_PREFIX, this.getClass().getSimpleName(), THROTTLE_MAIN));
Timer.Context context3 = timer3.start();
TracingSpan throttleLatencySpan = null;
if (Util.tracingEnabled()) {
TracingSpan responseLatencySpan = (TracingSpan) messageContext.getProperty(APIMgtGatewayConstants.RESOURCE_SPAN);
TracingTracer tracer = Util.getGlobalTracer();
throttleLatencySpan = Util.startSpan(APIMgtGatewayConstants.THROTTLE_LATENCY, responseLatencySpan, tracer);
}
long executionStartTime = System.currentTimeMillis();
if (!ExtensionListenerUtil.preProcessRequest(messageContext, type)) {
return false;
}
try {
boolean throttleResponse = doThrottle(messageContext);
if (!ExtensionListenerUtil.postProcessRequest(messageContext, type)) {
return false;
}
return throttleResponse;
} catch (Exception e) {
if (Util.tracingEnabled() && throttleLatencySpan != null) {
Util.setTag(throttleLatencySpan, APIMgtGatewayConstants.ERROR, APIMgtGatewayConstants.THROTTLE_HANDLER_ERROR);
}
throw e;
} finally {
messageContext.setProperty(APIMgtGatewayConstants.THROTTLING_LATENCY, System.currentTimeMillis() - executionStartTime);
context3.stop();
if (Util.tracingEnabled()) {
Util.finishSpan(throttleLatencySpan);
}
}
}
Aggregations