예제 #1
0
  private void innerBroadcast(MessageContext ctx) {
    EventBus carryEventBus = this.getContext().getCarryEventBus();

    BroadcastEventProcessor eventProcessor = new BroadcastEventProcessor();
    carryEventBus.register(eventProcessor);

    CommonEventProcessor.MsgIdGenerateEvent msgIdGenerateEvent =
        new CommonEventProcessor.MsgIdGenerateEvent();
    BroadcastEventProcessor.ValidateEvent validateEvent =
        new BroadcastEventProcessor.ValidateEvent();
    BroadcastEventProcessor.PermissionCheckEvent permissionCheckEvent =
        new BroadcastEventProcessor.PermissionCheckEvent();
    BroadcastEventProcessor.BroadcastEvent broadcastEvent =
        new BroadcastEventProcessor.BroadcastEvent();

    msgIdGenerateEvent.setMessageContext(ctx);
    validateEvent.setMessageContext(ctx);
    permissionCheckEvent.setMessageContext(ctx);
    broadcastEvent.setMessageContext(ctx);

    carryEventBus.post(msgIdGenerateEvent);
    carryEventBus.post(validateEvent);
    carryEventBus.post(permissionCheckEvent);
    carryEventBus.post(broadcastEvent);

    carryEventBus.unregister(eventProcessor);
  }
  @Override
  protected void shutDown() throws Exception {
    LOG.debug("Stopping InputSetupService");
    eventBus.unregister(this);

    for (InputState state : inputRegistry.getRunningInputs()) {
      MessageInput input = state.getMessageInput();

      LOG.info(
          "Attempting to close input <{}> [{}].", input.getUniqueReadableId(), input.getName());

      Stopwatch s = Stopwatch.createStarted();
      try {
        input.stop();

        LOG.info(
            "Input <{}> closed. Took [{}ms]",
            input.getUniqueReadableId(),
            s.elapsed(TimeUnit.MILLISECONDS));
      } catch (Exception e) {
        LOG.error(
            "Unable to stop input <{}> [{}]: " + e.getMessage(),
            input.getUniqueReadableId(),
            input.getName());
      } finally {
        s.stop();
      }
    }
    LOG.debug("Stopped InputSetupService");
  }
예제 #3
0
  @Test
  public void testSocketPreview() {
    SocketHint<Number> sh = SocketHints.createNumberSocketHint("foo", 0);
    OutputSocket<Number> socket = new OutputSocketImpl<>(eventBus, sh);

    final boolean[] handled = new boolean[] {false};
    Object eventHandler =
        new Object() {
          @SuppressFBWarnings(
              value = "UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS",
              justification = "This method is called by Guava's EventBus")
          @Subscribe
          public void onSocketPreviewed(SocketPreviewChangedEvent e) {
            handled[0] = true;
            assertTrue(
                "A preview event fired for a socket but the socket was not labeled as able to "
                    + "be previewed",
                socket.isPreviewed());
          }
        };

    eventBus.register(eventHandler);
    socket.setPreviewed(true);
    eventBus.unregister(eventHandler);

    assertTrue("SocketPreviewChangedEvent was not received", handled[0]);
  }
 protected final synchronized void unsubscribeTenant(String tenantId, String reason)
     throws IOException {
   Preconditions.checkState(
       tenantConfig.eventBusMap().containsKey(tenantId),
       "Cannot unsubscribe %s tenant '%s' (reason: %s) because EventBus not found. %s available: %s",
       getClass().getName(),
       tenantId,
       reason,
       tenantConfig.eventBusMap().size(),
       tenantConfig.eventBusMap().keySet());
   final EventBus tenantEventBus = tenantConfig.eventBusMap().get(tenantId);
   Preconditions.checkState(
       subscriberMap.containsKey(tenantId),
       "Cannot unsubscribe %s tenant '%s' (reason: %s) because subscribers not found, createSubscribers() never called? %s available: %s",
       getClass().getName(),
       tenantId,
       reason,
       subscriberMap.size(),
       subscriberMap.keySet());
   final List<Object> subscribers = subscriberMap.get(tenantId);
   log.debug(
       "Unsubscribing {} objects from '{}' EventBus: {}. Reason: {}",
       subscribers.size(),
       tenantId,
       subscribers,
       reason);
   for (Object subscriber : subscribers) {
     tenantEventBus.unregister(subscriber);
   }
   subscriberMap.remove(tenantId);
 }
예제 #5
0
 @Subscribe
 public void messageReceived(ReceivedTextFromUser evt) {
   if (state == State.LOGIN_PROMPT) {
     login = evt.getText();
     if (!login.isEmpty()) {
       if (login.equals("new") || login.equals("signup") || login.equals("sign up")) {
         ebus.unregister(this);
         ebus.register(new SignUpPanel(ebus));
       } else {
         try {
           if (App.getApp().getEntitiesManager().getUsersDao().queryForId(login) == null) {
             ebus.post(new SendTextToUser("Sorry. There is no such user.\nType your name: "));
           } else {
             ebus.post(new SendTextToUser("Hi, " + login + "! Type your password: "******"Could not check if user login is correct", ex);
           ebus.post(
               new SendTextToUser(
                   "Sorry, there was an error. We are unable to check your credintials. Please try again later or contact system administrator."));
         }
       }
     }
   } else if (state == State.PASSWORD_PROMPT) {
     try {
       User u = App.getApp().getEntitiesManager().getUsersDao().queryForId(login);
       if (u.isPasswordCorrect(evt.getText())) {
         ebus.unregister(this);
         ebus.register(new GlobalMenuPanel(ebus, u));
       } else {
         ebus.post(new SendTextToUser("Your password is incorrect. Please login once again."));
         state = State.LOGIN_PROMPT;
       }
     } catch (SQLException ex) {
       Logger.getLogger(LoginPanel.class.getName())
           .log(Level.SEVERE, "Could not check user password", ex);
       ebus.post(
           new SendTextToUser(
               "Sorry, there was an error. We are unable to check your credintials. Please try again later or contact system administrator."));
     }
   }
 }
예제 #6
0
  /**
   * Close external connections
   *
   * @throws JMSException
   */
  @PreDestroy
  public void releaseConnections() throws JMSException {
    LOGGER.debug("Tearing down: " + this.getClass().getCanonicalName());

    producer.close();
    jmsSession.close();
    connection.close();
    eventBus.unregister(this);
    session.logout();
  }
예제 #7
0
  @Test
  public void testReceiveEvent() throws Exception {

    EventBus eventBus = new EventBus("test");
    EventListener listener = new EventListener();

    eventBus.register(listener);

    eventBus.post(new TestEvent(200));
    eventBus.post(new TestEvent(300));
    eventBus.post(new TestEvent(400));

    System.out.println("最后message的值是:" + listener.getLastMessage());

    eventBus.unregister(listener);

    eventBus.post(new TestEvent(500));

    System.out.println("没有监控的情况下,最后message的值是:" + listener.getLastMessage());
  }
예제 #8
0
  @Override
  public void run() {
    try {
      String input;
      while ((input = in.readLine()) != null) {
        channel.post(input);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    // reached eof
    channel.unregister(this);
    try {
      connection.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
    in = null;
    out = null;
  }
예제 #9
0
  @Test
  public void testSocketChangedEvent() throws Exception {
    final boolean[] handled = new boolean[] {false};
    final Double[] value = new Double[] {0.0};
    Object eventHandler =
        new Object() {
          @SuppressFBWarnings(
              value = "UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS",
              justification = "This method is called by Guava's EventBus")
          @Subscribe
          public void onSocketChanged(SocketChangedEvent e) {
            handled[0] = true;
            value[0] = (Double) socket.getValue().get();
          }
        };

    eventBus.register(eventHandler);
    socket.setValue(TEST_VALUE);
    eventBus.unregister(eventHandler);

    assertTrue(handled[0]);
    assertEquals(TEST_VALUE, value[0]);
  }
예제 #10
0
 public void unregister(Object object) {
   eventBus.unregister(object);
 }
예제 #11
0
 private void unsubscribeFromEventBusses() {
   extdocBus.unregister(contentPart);
   extdocBus.unregister(overviewPart);
   workspaceBus.unregister(this);
 }
 @PreDestroy
 public void preDestroy() {
   eventBus.unregister(this);
 }
예제 #13
0
 public static void unregister(Object obj) {
   // LogUtil.logger.info("unregister for Events:" + obj);
   eventBus.unregister(obj);
 }