示例#1
0
  public Conversation insertNewConversation(long rmt_ip, int lcl_port, int rmt_port) {
    gc();

    Conversation conv = new Conversation(rmt_ip, lcl_port, rmt_port);

    modLong.setLong(rmt_ip);
    modInt.setInt((lcl_port << 16) | (rmt_port & 0xFFFF));

    ModInteger mInt = new ModInteger();
    mInt.setInt((lcl_port << 16) | (rmt_port & 0xFFFF));

    HashMap portsMap = (HashMap) hostsMap.get(modLong);
    if (portsMap == null) {
      ModLong mLong = new ModLong();

      mLong.setLong(rmt_ip);
      portsMap = new HashMap();
      hostsMap.put(mLong, portsMap);
    }
    portsMap.put(mInt, conv);
    allConversations.add(conv);
    hasChanged = true;

    return conv;
  }
示例#2
0
 /*
  * Note: When the list of connections grows large copying will be longer
  * and longer, so it's better to return the previous set then to lock and
  * wait until the copy is completed, later this will be changed to using an
  * array so that the problem is not here and done w/o synch.
  *
  * large is 3000+ connecations.
  */
 public Conversation[] getArray() {
   if (hasChanged || convArr == null) {
     hasChanged = false;
     try {
       Conversation[] tmp = (Conversation[]) allConversations.toArray(new Conversation[] {});
       convArr = tmp;
     } catch (Exception e) {
     }
   }
   return convArr;
 }
示例#3
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();
  }
示例#4
0
  public Conversation removeConversation(long rmt_ip, int lcl_port, int rmt_port) {
    modLong.setLong(rmt_ip);
    modInt.setInt((lcl_port << 16) | (rmt_port & 0xFFFF));

    HashMap portsMap = (HashMap) hostsMap.get(modLong);
    Conversation conv = null;

    if (portsMap != null) {
      conv = (Conversation) portsMap.remove(modInt);
      if (conv != null) {
        if (portsMap.size() == 0) {
          hostsMap.remove(modLong);
        }
      }
    }

    allConversations.remove(conv);

    return conv;
  }
示例#5
0
 public int convCount() {
   return allConversations.size();
 }