Example #1
0
  @Override
  public RPCMessage connect(RPCMessage RPCmsg) throws RemoteException {

    if (RPCmsg.getMessageType() == MessageType.REQUEST
        & RPCmsg.getProcedureID() == (short) 1
        & RPCmsg.getStatus() == (short) 0
        & onlineUser.size() <= 10) {

      RPCmsg.setMessageType(MessageType.REPLY);
      String userId = RPCmsg.getCvs_data();
      if (!onlineUser.contains(userId)) {
        onlineUser.add(userId);
      }

      RPCmsg.setCvs_data("Succssful");

      System.out.println(userId + " is now online");
      logicClock++;
      return RPCmsg;

    } else if (onlineUser.size() > 10) {
      RPCmsg.setMessageType(MessageType.REPLY);
      RPCmsg.setStatus((short) 1);
      RPCmsg.setCvs_data("Server full. max number of client reached");
      return RPCmsg;
    } else {
      RPCmsg.setMessageType(MessageType.REPLY);
      RPCmsg.setStatus((short) 1);
      RPCmsg.setCvs_data("error");
      return RPCmsg;
    }
  }
Example #2
0
  @Override
  public RPCMessage deposit(RPCMessage RPCmsg) throws RemoteException {
    if (RPCmsg.getMessageType() == MessageType.REQUEST
        & RPCmsg.getProcedureID() == 2
        & RPCmsg.getStatus() == 0) {

      RPCmsg.setMessageType(MessageType.REPLY);
      String[] parts = RPCmsg.getCvs_data().split(";");
      String depositor_id = parts[0];
      String receiver_id = parts[1].trim();
      String text = parts[2];

      if (!dropBox.containsKey(receiver_id)) {
        dropBox.put(receiver_id, new ArrayList<String>());
      }

      ArrayList<String> list = dropBox.get(receiver_id);
      list.add(
          text
              + " from "
              + depositor_id
              + " at "
              + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")
                  .format(Calendar.getInstance().getTime()));
      dropBox.put(receiver_id, list);
      RPCmsg.setCvs_data("Succssful");
      logicClock++;
      return RPCmsg;
    } else {
      RPCmsg.setMessageType(MessageType.REPLY);
      RPCmsg.setStatus((short) 1);
      RPCmsg.setCvs_data("error");
      return RPCmsg;
    }
  }
Example #3
0
  @Override
  public RPCMessage inquire(RPCMessage RPCmsg) throws RemoteException {
    if (RPCmsg.getMessageType() == MessageType.REQUEST
        & RPCmsg.getProcedureID() == 4
        & RPCmsg.getStatus() == 0) {
      RPCmsg.setMessageType(MessageType.REPLY);
      RPCmsg.setCvs_data(
          "User " + RPCmsg.getCvs_data() + " is online? " + isOnline(RPCmsg.getCvs_data()));

      return RPCmsg;
    } else {
      RPCmsg.setMessageType(MessageType.REPLY);
      RPCmsg.setStatus((short) 1);
      RPCmsg.setCvs_data("error");
      return RPCmsg;
    }
  }
Example #4
0
  @Override
  public RPCMessage retrieve(RPCMessage RPCmsg) throws RemoteException {
    if (RPCmsg.getMessageType() == MessageType.REQUEST
        & RPCmsg.getProcedureID() == 3
        & RPCmsg.getStatus() == 0) {

      RPCmsg.setMessageType(MessageType.REPLY);

      // System.out.println("user "+RPCmsg.getCvs_data()+" requires to retrive his messages");

      ArrayList<String> msgs = dropBox.get(RPCmsg.getCvs_data().trim());
      String text = "";
      if (msgs != null) {
        if (msgs.size() != 0) {
          for (int i = 0; i < msgs.size(); i++) {

            text += msgs.get(i) + "^";
            // msgs.remove(i);
          }
          logicClock++;
          msgs.clear();
        } else {
          text = "you have retrived all your messages already";
        }

      } else {
        text = "you dont have any message";
      }

      RPCmsg.setCvs_data(text);

      return RPCmsg;
    } else {
      RPCmsg.setMessageType(MessageType.REPLY);
      RPCmsg.setStatus((short) 1);
      RPCmsg.setCvs_data("error");
      return RPCmsg;
    }
  }
Example #5
0
  @Override
  public RPCMessage disconnect(RPCMessage RPCmsg) throws RemoteException {
    if (RPCmsg.getMessageType() == MessageType.REQUEST
        & RPCmsg.getProcedureID() == 5
        & RPCmsg.getStatus() == 0) {
      RPCmsg.setMessageType(MessageType.REPLY);

      String userId = RPCmsg.getCvs_data();
      if (onlineUser.contains(userId)) {
        onlineUser.remove(userId);
      }

      RPCmsg.setCvs_data("Succssful");

      // System.out.println(userId+" is now online");
      logicClock++;
      return RPCmsg;
    } else {
      RPCmsg.setMessageType(MessageType.REPLY);
      RPCmsg.setStatus((short) 1);
      RPCmsg.setCvs_data("error");
      return RPCmsg;
    }
  }