Exemplo n.º 1
0
  public List<AbstractMemberMessage> getAllMessages(String recipient) {
    List<AbstractMemberMessage> messages = new LinkedList<>();
    QueueManager queueManager = new QueueManager(getQueueName(recipient));

    AbstractMemberMessage message = queueManager.consume();
    while (message != null) {
      messages.add(message);
      message = queueManager.consume();
    }

    System.out.println(recipient + " read all messages");
    return messages;
  }
Exemplo n.º 2
0
  public void sendMessage(AbstractMemberMessage messageObject) {
    QueueManager queueManager = new QueueManager(getQueueName(messageObject.getRecipient()));
    queueManager.produce(messageObject);
    System.out.println(
        messageObject.getSender() + " send a message to " + messageObject.getRecipient());

    if (_listeners.containsKey(messageObject.getRecipient())) {
      try {
        _listeners.get(messageObject.getRecipient()).notifyAboutMessage();
        System.out.println("The recipient was notified about this");
      } catch (RemoteException e) {
        unregisterListener(messageObject.getRecipient());
      }
    }
  }