Exemplo n.º 1
0
  @Override
  public boolean accept(Message<?> message) {
    Object payloadObject = message.getPayload();
    if (Event.class.isInstance(payloadObject)) {

      Event payload = (Event) message.getPayload();
      return monitor.requiredEvents().contains(payload.getClass());

    } else {
      return false;
    }
  }
  @Override
  public void handleEvent(Event event) {
    // should be safe due to required events set
    UserEvent userEvent = (UserEvent) event;
    LOGGER.info(
        "[{}] delegating {} for user {}",
        getName(),
        event.getClass().getName(),
        userEvent.getUsername());

    int handleCount = 0;
    for (UserLoginLogoutMonitor monitor : monitors) {
      if (monitor.getUsername().equals(userEvent.getUsername())) {
        monitor.handleEvent(event);
        handleCount++;
      }
    }
    LOGGER.info(
        "[{}] delegated {} for user {} to {} UserLoginLogoutMonitor(s)",
        getName(),
        event.getClass().getName(),
        userEvent.getUsername(),
        handleCount);
  }