/** * A utility method to handle outgoing throttling results in a common way. * * @param message The message that is being throttled. * @param throttleResult The throttling result. * @param isClientLevel Whether the message is being throttled at the client level or not. */ public void handleOutgoingThrottleResult( Message message, ThrottleResult throttleResult, boolean isClientLevel) { Result result = throttleResult.getResult(); // Update the management metrics. if (result != Result.OK && isManaged()) { if (isClientLevel) ((ThrottleManagerControl) getControl()).incrementClientOutgoingMessageThrottleCount(); else ((ThrottleManagerControl) getControl()).incrementDestinationOutgoingMessageThrottleCount(); } // Result can only be IGNORE (or NONE which means no throttling) if (result == Result.IGNORE) { // Improve the detail message for IGNORE. if (isClientLevel) throttleResult.setDetail( "Message '" + message.getMessageId() + "' ignored: Too many messages sent to client '" + message.getClientId() + "' in too small of a time interval " + throttleResult.getDetail()); else throttleResult.setDetail( "Message '" + message.getMessageId() + "' throttled: Too many messages routed by destination '" + message.getDestination() + "' in too small of a time interval " + throttleResult.getDetail()); if (Log.isInfo()) Log.getLogger(LOG_CATEGORY).info(throttleResult.getDetail()); } }
/** * A utility method to handle incoming throttling results in a common way. * * @param message The message that is being throttled. * @param throttleResult The throttling result. * @param isClientLevel Whether the message is being throttled at the client level or not. */ protected void handleIncomingThrottleResult( Message message, ThrottleResult throttleResult, boolean isClientLevel) { Result result = throttleResult.getResult(); // Update the management metrics. if (result != Result.OK && isManaged()) { if (isClientLevel) ((ThrottleManagerControl) getControl()).incrementClientIncomingMessageThrottleCount(); else ((ThrottleManagerControl) getControl()).incrementDestinationIncomingMessageThrottleCount(); } // Result can be IGNORE or ERROR (or NONE which means no throttling). if (result == Result.IGNORE || result == Result.ERROR) { if (isClientLevel) throttleResult.setDetail( "Message '" + message.getMessageId() + "' throttled: Too many messages sent by the client '" + message.getClientId() + "' in too small of a time interval " + throttleResult.getDetail()); else throttleResult.setDetail( "Message '" + message.getMessageId() + "' throttled: Too many messages sent to destination '" + message.getDestination() + "' in too small of a time interval " + throttleResult.getDetail()); String detail = throttleResult.getDetail(); if (result == Result.ERROR) { if (Log.isError()) Log.getLogger(LOG_CATEGORY).error(detail); // And, throw an exception, so the client gets the error. MessageException me = new MessageException(detail); throw me; } // Otherwise, just log it. if (Log.isInfo()) Log.getLogger(LOG_CATEGORY).info(detail); } }