private boolean doThrottleByConcurrency(boolean isResponse) { boolean canAccess = true; if (concurrentAccessController != null) { // do the concurrency throttling int concurrentLimit = concurrentAccessController.getLimit(); if (log.isDebugEnabled()) { log.debug("Concurrent access controller for ID: " + id + " allows: " + concurrentLimit + " concurrent accesses"); } int available; if (!isResponse) { available = concurrentAccessController.getAndDecrement(); canAccess = available > 0; if (log.isDebugEnabled()) { log.debug("Concurrency Throttle: Access " + (canAccess ? "allowed" : "denied") + " :: " + available + " of available of " + concurrentLimit + " connections"); } } else { available = concurrentAccessController.incrementAndGet(); if (log.isDebugEnabled()) { log.debug("Concurrency Throttle : Connection returned" + " :: " + available + " of available of " + concurrentLimit + " connections"); } } } return canAccess; }
localAccessController = throttleDataHolder.getConcurrentAccessController(key); if (localAccessController != null) { localAccessController.updateCounter(action);
public void updateCounter(boolean isIncrement) { if (isIncrement) { incrementAndGet(); } else { getAndDecrement(); } } }
/** * Helper method that handles the concurrent access through throttle * * @param isResponse Current Message is response or not * @param synLog the Synapse log to use * @return true if the caller can access ,o.w. false */ private boolean doThrottleByConcurrency(boolean isResponse, SynapseLog synLog) { boolean canAccess = true; if (concurrentAccessController != null) { // do the concurrency throttling int concurrentLimit = concurrentAccessController.getLimit(); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Concurrent access controller for ID : " + id + " allows : " + concurrentLimit + " concurrent accesses"); } int available; if (!isResponse) { available = concurrentAccessController.getAndDecrement(); canAccess = available > 0; if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Concurrency Throttle : Access " + (canAccess ? "allowed" : "denied") + " :: " + available + " of available of " + concurrentLimit + " connections"); } } } return canAccess; }
smc.getProperty(SynapseConstants.SYNAPSE_CONCURRENT_ACCESS_CONTROLLER); int available = concurrentAccessController.incrementAndGet(); int concurrentLimit = concurrentAccessController.getLimit();
concurrentAccessController.incrementAndGet(); if (isClusteringEnable) { cc.setProperty(key, concurrentAccessController); concurrentAccessController.incrementAndGet(); if (isClusteringEnable) { cc.setProperty(key, concurrentAccessController);
/** * Test decrementConcurrencyThrottleAccessController method for incremented connection count. * @throws Exception */ public void testDecrement() throws Exception { MessageContext mc = TestUtils.getTestContext("<a><b>bob</b></a>", null); mc.setProperty(SynapseConstants.SYNAPSE_CONCURRENCY_THROTTLE, true); ConcurrentAccessController controller = new ConcurrentAccessController(1); mc.setProperty(SynapseConstants.SYNAPSE_CONCURRENT_ACCESS_CONTROLLER, controller); //Set limit and counter to 5 controller.set(5); ConcurrencyThrottlingUtils.decrementConcurrencyThrottleAccessController(mc); //getAndDecrement - decrement by 1 and return previous value int newValue = controller.getAndDecrement(); Assert.assertEquals("connection count after increment should be 5", 5, newValue); Assert.assertFalse("flag should be cleared to avoid further executions of the method", (boolean) mc.getProperty(SynapseConstants.SYNAPSE_CONCURRENCY_THROTTLE)); } }
new ConcurrentAccessController(intValue));
/** * Decrement the internal counter for concurrency throttling, in case of normal response retrieval, * delayed response at synapse timeout, exceptional cases while mediation end up trigger fault. * In clustered environment, replicate the decremented value to other members. * * @param synCtx Synapse Message Context of which mediation occurs. */ public static void decrementConcurrencyThrottleAccessController(MessageContext synCtx) { Boolean isConcurrencyThrottleEnabled = (Boolean) synCtx .getProperty(SynapseConstants.SYNAPSE_CONCURRENCY_THROTTLE); if (isConcurrencyThrottleEnabled != null && isConcurrencyThrottleEnabled) { ConcurrentAccessController concurrentAccessController = (ConcurrentAccessController) synCtx .getProperty(SynapseConstants.SYNAPSE_CONCURRENT_ACCESS_CONTROLLER); int available = concurrentAccessController.incrementAndGet(); int concurrentLimit = concurrentAccessController.getLimit(); if (log.isDebugEnabled()) { log.debug("Concurrency Throttle : Connection returned" + " :: " + available + " of available of" + concurrentLimit + " connections"); } ConcurrentAccessReplicator concurrentAccessReplicator = (ConcurrentAccessReplicator) synCtx .getProperty(SynapseConstants.SYNAPSE_CONCURRENT_ACCESS_REPLICATOR); String throttleKey = (String) synCtx.getProperty(SynapseConstants.SYNAPSE_CONCURRENCY_THROTTLE_KEY); if (concurrentAccessReplicator != null) { concurrentAccessReplicator.replicate(throttleKey, true); } //once decremented, clear the flag since we no longer required to decrement the value //concurrency throttle access controller synCtx.setProperty(SynapseConstants.SYNAPSE_CONCURRENCY_THROTTLE, false); } }
concurrentAccessController.incrementAndGet(); if (isClusteringEnable) { cc.setProperty(key, concurrentAccessController); concurrentAccessController.incrementAndGet(); if (isClusteringEnable) { cc.setProperty(key, concurrentAccessController);
new ConcurrentAccessController(intvalue));
private boolean doThrottleByConcurrency(boolean isResponse) { boolean canAccess = true; if (concurrentAccessController != null) { // do the concurrency throttling int concurrentLimit = concurrentAccessController.getLimit(); if (log.isDebugEnabled()) { log.debug("Concurrent access controller for ID: " + id + " allows: " + concurrentLimit + " concurrent accesses"); } int available; if (!isResponse) { available = concurrentAccessController.getAndDecrement(); canAccess = available > 0; if (log.isDebugEnabled()) { log.debug("Concurrency Throttle: Access " + (canAccess ? "allowed" : "denied") + " :: " + available + " of available of " + concurrentLimit + " connections"); } } else { available = concurrentAccessController.incrementAndGet(); if (log.isDebugEnabled()) { log.debug("Concurrency Throttle : Connection returned" + " :: " + available + " of available of " + concurrentLimit + " connections"); } } } return canAccess; }
protected void informFailure(MessageContext synCtx, int errorCode, String errorMsg) { Boolean isConcurrencyThrottleEnabled = (Boolean) synCtx .getProperty(SynapseConstants.SYNAPSE_CONCURRENCY_THROTTLE); if (isConcurrencyThrottleEnabled != null && isConcurrencyThrottleEnabled) { ConcurrentAccessController concurrentAccessController = (ConcurrentAccessController) synCtx .getProperty(SynapseConstants.SYNAPSE_CONCURRENT_ACCESS_CONTROLLER); int available = concurrentAccessController.incrementAndGet(); int concurrentLimit = concurrentAccessController.getLimit(); if (log.isDebugEnabled()) { log.debug("Concurrency Throttle : Connection returned" + " :: " + available + " of available of " + concurrentLimit + " connections"); } ConcurrentAccessReplicator concurrentAccessReplicator = (ConcurrentAccessReplicator) synCtx .getProperty(SynapseConstants.SYNAPSE_CONCURRENT_ACCESS_REPLICATOR); String throttleKey = (String) synCtx .getProperty(SynapseConstants.SYNAPSE_CONCURRENCY_THROTTLE_KEY); if (concurrentAccessReplicator != null) { concurrentAccessReplicator.replicate(throttleKey, true); } } if (synCtx.getProperty(SynapseConstants.LAST_ENDPOINT) == null) { setErrorOnMessage(synCtx, errorCode, errorMsg); } invokeNextFaultHandler(synCtx); }
available = concurrentAccessController.getAndDecrement(); canAccess = available > 0; if (debugOn) { log.debug("Concurrency Throttle : Access " + (canAccess ? "allowed" : "denied") + " :: " + available + " of available of " + concurrentAccessController.getLimit() + " connections"); available = concurrentAccessController.incrementAndGet(); if (debugOn) { log.debug("Concurrency Throttle : Connection returned" + " :: " + available + " of available of " + concurrentAccessController.getLimit() + " connections");
(ConcurrentAccessController) synapseOutMessageContext .getProperty(SynapseConstants.SYNAPSE_CONCURRENT_ACCESS_CONTROLLER); int available = concurrentAccessController.incrementAndGet(); int concurrentLimit = concurrentAccessController.getLimit(); if (log.isDebugEnabled()) { log.debug("Concurrency Throttle : Connection returned" + " :: " +
cac.incrementAndGet(); cache.put(key, cac); if (debugOn) { cac.incrementAndGet();
synapseOutMsgCtx .getProperty(SynapseConstants.SYNAPSE_CONCURRENT_ACCESS_CONTROLLER); int available = concurrentAccessController.incrementAndGet(); int concurrentLimit = concurrentAccessController.getLimit(); if (log.isDebugEnabled()) { log.debug("Concurrency Throttle : Connection returned" + " :: " +