Пример #1
0
  /** Starts the throttle manager. */
  @Override
  public void start() {
    // Use the default ThrottleSettings if one is not set already.
    if (settings == null) settings = new ThrottleSettings();

    if (settings.isDestinationThrottleEnabled()) {
      inboundDestinationMark = new MessageFrequency(settings.getIncomingDestinationFrequency());
      outboundDestinationMark = new MessageFrequency(settings.getOutgoingDestinationFrequency());
    }

    if (settings.isInboundClientThrottleEnabled())
      inboundClientMarks = new HashMap<String, MessageFrequency>();
  }
Пример #2
0
 /**
  * Attempts to throttle destination-level incoming and outgoing messages.
  *
  * @param message Message to throttle.
  * @param incoming Whether the message is incoming or outgoing.
  * @return The result of the throttling attempt.
  */
 public ThrottleResult throttleDestinationLevel(Message message, boolean incoming) {
   if (incoming && settings.isInboundDestinationThrottleEnabled()) {
     ThrottleResult result =
         inboundDestinationMark.checkLimit(
             settings.getIncomingDestinationFrequency(), settings.getInboundPolicy());
     return result;
   } else if (!incoming && settings.isOutboundDestinationThrottleEnabled()) {
     ThrottleResult result =
         outboundDestinationMark.checkLimit(
             settings.getOutgoingDestinationFrequency(), settings.getOutboundPolicy());
     return result;
   }
   // Return the default OK result.
   return new ThrottleResult();
 }