public void removeConnection(Address address) {
   Connection conn = null;
   lock.lock();
   try {
     conn = conns.remove(address);
   } finally {
     lock.unlock();
   }
   Util.close(conn);
 }
 public void addConnection(Address address, V conn) {
   lock.lock();
   try {
     V previous = conns.put(address, conn);
     Util.close(previous);
   } finally {
     lock.unlock();
   }
   notifyConnectionOpened(address, conn);
 }
Exemple #3
0
 public void setState(InputStream istream) {
   try {
     try {
       panel.readState(istream);
     } catch (IOException e) {
       e.printStackTrace();
     }
   } finally {
     Util.close(istream);
   }
 }
Exemple #4
0
 public void getState(OutputStream ostream) {
   try {
     try {
       panel.writeState(ostream);
     } catch (IOException e) {
       e.printStackTrace();
     }
   } finally {
     Util.close(ostream);
   }
 }
 public void stop() {
   if (reaper != null) {
     reaper.stop();
   }
   lock.lock();
   try {
     for (Iterator<Entry<Address, V>> i = conns.entrySet().iterator(); i.hasNext(); ) {
       Entry<Address, V> e = i.next();
       Util.close(e.getValue());
     }
     clear();
   } finally {
     lock.unlock();
   }
   conn_listeners.clear();
 }
 public void run() {
   while (!Thread.currentThread().isInterrupted()) {
     lock.lock();
     try {
       for (Iterator<Entry<Address, V>> it = conns.entrySet().iterator(); it.hasNext(); ) {
         Entry<Address, V> entry = it.next();
         V c = entry.getValue();
         if (c.isExpired(System.currentTimeMillis())) {
           log.info("Connection " + c.toString() + " reaped");
           Util.close(c);
           it.remove();
         }
       }
     } finally {
       lock.unlock();
     }
     Util.sleep(reaperInterval);
   }
 }
  /**
   * Removes all connections from ConnectionTable which are not in current_mbrs
   *
   * @param current_mbrs
   */
  public void retainAll(Collection<Address> current_mbrs) {
    if (current_mbrs == null) return;

    Map<Address, V> copy = null;
    lock.lock();
    try {
      copy = new HashMap<Address, V>(conns);
      conns.keySet().retainAll(current_mbrs);
    } finally {
      lock.unlock();
    }
    copy.keySet().removeAll(current_mbrs);

    for (Iterator<Entry<Address, V>> i = copy.entrySet().iterator(); i.hasNext(); ) {
      Entry<Address, V> e = i.next();
      Util.close(e.getValue());
    }
    copy.clear();
  }