private void processMessage(Message message) throws IOException {
    if (message.getType().equals("SimpleMessage")) {
      MessageType messageType = (MessageType) message.getValue();
      String receiver = messageType.getToUser();
      history.get(receiver).add(messageType);
    }

    if (message.getType().equals("ConnectUserMessage")) {
      String user = (String) message.getValue();
      Messages messages = history.get(user);
      Operations.sendHistory(messages.getLastFiveWith(user), out);
    }
  }
  public void handleMessageData(int length, MVByteBuffer messageData, AgentInfo agentInfo) {
    if (length == -1 || messageData == null) {
      if ((agentInfo.flags & MessageAgent.DOMAIN_FLAG_TRANSIENT) != 0) {
        Log.info("Lost connection to '" + agentInfo.agentName + "' (transient)");
        agents.remove(agentInfo.socket);
        agentNames.remove(agentInfo.agentName);
        messageIO.removeAgent(agentInfo);
      } else Log.info("Lost connection to '" + agentInfo.agentName + "'");

      try {
        agentInfo.socket.close();
      } catch (java.io.IOException ex) {
        Log.exception("close", ex);
      }
      agentInfo.socket = null;
      // ## clear buffers
      // ## keep agentInfo?  to preserve agentId?
      return;
    }

    Message message = (Message) MarshallingRuntime.unmarshalObject(messageData);

    MessageType msgType = message.getMsgType();
    if (Log.loggingDebug)
      Log.debug(
          "handleMessageData from "
              + agentInfo.agentName
              + ","
              + message.getMsgId()
              + " type="
              + msgType.getMsgTypeString()
              + " len="
              + length
              + " class="
              + message.getClass().getName());

    try {
      if (message instanceof AllocNameMessage)
        handleAllocName((AllocNameMessage) message, agentInfo.socket);
      else if (message instanceof AwaitPluginDependentsMessage)
        handleAwaitPluginDependents((AwaitPluginDependentsMessage) message, agentInfo.socket);
      else if (message instanceof PluginAvailableMessage)
        handlePluginAvailable((PluginAvailableMessage) message, agentInfo.socket);
      else
        Log.error(
            "Unsupported message from "
                + agentInfo.agentName
                + ","
                + message.getMsgId()
                + " type="
                + msgType.getMsgTypeString()
                + " len="
                + length
                + " class="
                + message.getClass().getName());
    } catch (java.io.IOException e) {
      Log.error(
          "IO error on message from "
              + agentInfo.agentName
              + ","
              + message.getMsgId()
              + " type="
              + msgType.getMsgTypeString()
              + " len="
              + length
              + " class="
              + message.getClass().getName());
    }
  }