예제 #1
0
 private void removeUnused() {
   Conversation[] cons = getArray();
   for (int i = 0; i < cons.length; i++) {
     Conversation c = cons[i];
     if (!c.isUsed()) {
       removeConversation(c.getRmt_ip(), c.getLcl_port(), c.getRmt_port());
     }
   }
 }
예제 #2
0
  public void readIn(DataInputStream din) throws IOException {
    Iterator it = allConversations.iterator();
    while (it.hasNext()) {
      Conversation conv = (Conversation) it.next();
      conv.setUsed(false);
    }

    int count = din.readInt();
    for (int i = 0; i < count; i++) {
      readConv.readIn(din);
      Conversation existing =
          findConversation(readConv.getRmt_ip(), readConv.getLcl_port(), readConv.getRmt_port());
      existing.setUsed(true);
      existing.setInfo(readConv);
    }
    removeUnused();
  }
예제 #3
0
  private void gc() {
    if (gcTime == -1) {
      return;
    }

    long curTime = System.currentTimeMillis();

    if ((curTime - lastTime) > gcTime) {
      int collected = 0;
      lastTime = curTime;

      Conversation[] cons = getArray();
      for (int i = 0; i < cons.length; i++) {
        Conversation c = cons[i];

        long l = c.getLastActive();
        if ((curTime - l) > convTime) {
          collected++;
          removeConversation(c.getRmt_ip(), c.getLcl_port(), c.getRmt_port());
        }
      }
    }
  }