Esempio n. 1
0
 public String toString() {
   StringBuilder ret = new StringBuilder();
   ret.append("local_addr=" + local_addr).append("\n");
   ret.append("connections (" + mapper.size() + "):\n");
   ret.append(mapper.toString());
   ret.append('\n');
   return ret.toString();
 }
Esempio n. 2
0
 public void stop() {
   if (running.compareAndSet(true, false)) {
     try {
       getSocketFactory().close(srv_sock);
     } catch (IOException e) {
     }
     Util.interruptAndWaitToDie(acceptor);
     mapper.stop();
   }
 }
Esempio n. 3
0
 public static <T, K> List<K> map(final List<T> target, final Mapper<T, K> mapper) {
   if (target == null) {
     return null;
   }
   final List<K> list = new ArrayList<K>();
   for (T item : target) {
     final K mappedItem = mapper.apply(item);
     if (mappedItem != null) {
       list.add(mappedItem);
     }
   }
   return (list.size() == 0 ? null : list);
 }
Esempio n. 4
0
  public void send(Address dest, byte[] data, int offset, int length) throws Exception {
    if (dest == null) {
      if (log.isErrorEnabled()) log.error("destination is null");
      return;
    }

    if (data == null) {
      log.warn("data is null; discarding packet");
      return;
    }

    if (!running.get()) {
      if (log.isDebugEnabled())
        log.debug("connection table is not running, discarding message to " + dest);
      return;
    }

    if (dest.equals(local_addr)) {
      receive(local_addr, data, offset, length);
      return;
    }

    // 1. Try to obtain correct Connection (or create one if not yet existent)
    TCPConnection conn;
    conn = mapper.getConnection(dest);

    // 2. Send the message using that connection
    if (conn != null) {
      try {
        conn.send(data, offset, length);
      } catch (Exception ex) {
        mapper.removeConnection(dest);
        throw ex;
      }
    }
  }
Esempio n. 5
0
 public void retainAll(Collection<Address> members) {
   mapper.retainAll(members);
 }
Esempio n. 6
0
 public String printConnections() {
   return mapper.printConnections();
 }
Esempio n. 7
0
 public boolean connectionEstablishedTo(Address addr) {
   return mapper.connectionEstablishedTo(addr);
 }
Esempio n. 8
0
 public void start() throws Exception {
   if (running.compareAndSet(false, true)) {
     acceptor.start();
     mapper.start();
   }
 }
Esempio n. 9
0
 public void removeConnectionMapListener(
     AbstractConnectionMap.ConnectionMapListener<TCPConnection> l) {
   mapper.removeConnectionMapListener(l);
 }
Esempio n. 10
0
 public void addConnectionMapListener(
     AbstractConnectionMap.ConnectionMapListener<TCPConnection> l) {
   mapper.addConnectionMapListener(l);
 }
Esempio n. 11
-2
 public int getNumConnections() {
   return mapper.getNumConnections();
 }