public void run() {
    while (true) {
      try {
        TimeUnit.SECONDS.sleep(1);
      } catch (Exception e) {
        e.printStackTrace();
      }
      //            System.out.println("Here is Exit at " + exit.getInfo());
      //            System.out.println("Now has occupied places number : " + exit.getOccupiedNum());
      //            System.out.println("Now has exit car number : " + exit.getExitNum());
      if (exit.hasMessage()) {
        exit.tick();
        Message message = exit.getAndRemoveEarliestMessage();
        switch (message.getType()) {
          case REQUEST:
            {
            }
            break;

          case REPLY:
            {
            }
            break;

          case INFORM_ENTER:
            {
              exit.handleInformEnterFrom(message.getSource());
            }
            break;

          case INFORM_EXIT:
            {
              exit.handleInformExitFrom(message.getSource());
            }
            break;

          case UPDATE:
            {
              exit.handleUpdateFrom(message.getSource());
            }
            break;

          case UPDATE_REPLY:
            {
              exit.handleUpdateReply(message.getData());
            }
            break;
        }
      }
    }
  }
Ejemplo n.º 2
0
 public boolean acceptMsg(Message msg) {
   logRecvMsg(msg);
   TestChatServer.logUserMsgRecvd(username, msg.toString(), new Date());
   TransportObject toSend =
       new TransportObject(
           ServerReply.receive,
           msg.getSource(),
           msg.getDest(),
           msg.getContent(),
           msg.getTimestamp(),
           msg.getSQN());
   if (!queueReply(toSend)) return false;
   msgReceived(
       msg.getSource() + "\t" + msg.getDest() + "\t" + msg.getSQN() + "\t" + msg.getContent());
   return true;
 }
  public void getRequestToken(Message msg) {
    if (msg.getMessageType() != MTRequest) {
      System.err.println("??? (getRequestToken)");
      return;
    }

    int originator = Integer.parseInt(msg.getParam());
    try {
      this.mutex.acquire();

      if (this.parent == -1) {
        if (holding) {
          node.send(MTToken, originator, "");
          this.holding = false;
        } else {
          this.deferred = originator;
        }
      } else {
        node.send(MTRequest, parent, msg.getParam());
      }
      this.parent = msg.getSource();

      this.mutex.release();
    } catch (InterruptedException ex) {
      System.err.println("Error (getRequestToken " + node.getId() + "): " + ex.getMessage());
    }
  }
Ejemplo n.º 4
0
  private void logRecvMsg(Message msg) {
    // Add to chatlog
    ChatLog log;
    String reference;

    if (msg.isFromGroup()) reference = msg.getDest();
    else reference = msg.getSource();

    if (chatlogs.containsKey(reference)) log = chatlogs.get(reference);
    else {
      if (msg.isFromGroup()) log = new ChatLog(msg.getSource(), this, msg.getDest());
      else log = new ChatLog(msg.getSource(), this);

      chatlogs.put(reference, log);
    }

    log.add(msg);
  }
Ejemplo n.º 5
0
 public void addTargetedMessage(Connection connection, Message message, MessageRow.Type type) {
   Entity target = message.getTarget();
   if (target.equals(connection.getLocalUser())) {
     target = message.getSource();
   }
   Tab tab = null;
   for (Tab _tab : getItems()) {
     if (_tab.getEntity().equals(target)) {
       tab = _tab;
       break;
     }
   }
   if (tab == null) {
     if (type == MessageRow.Type.PART && message.getSource().equals(connection.getLocalUser())) {
       return;
     }
     tab = create(connection, target);
   }
   tab.getContentPane().getMessagePane().addRow(new MessageRow(message, type));
 }
 public void addMessage(MessageResolver messageResolver) {
   Locale currentLocale = LocaleContextHolder.getLocale();
   if (logger.isDebugEnabled()) {
     logger.debug("Resolving message using " + messageResolver);
   }
   Message message = messageResolver.resolveMessage(messageSource, currentLocale);
   List<Message> messages = sourceMessages.get(message.getSource());
   if (logger.isDebugEnabled()) {
     logger.debug("Adding resolved message " + message);
   }
   messages.add(message);
 }