示例#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();
 }
示例#2
0
 public void stop() {
   if (running.compareAndSet(true, false)) {
     try {
       getSocketFactory().close(srv_sock);
     } catch (IOException e) {
     }
     Util.interruptAndWaitToDie(acceptor);
     mapper.stop();
   }
 }
示例#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);
 }
示例#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;
      }
    }
  }
示例#5
0
 public void retainAll(Collection<Address> members) {
   mapper.retainAll(members);
 }
示例#6
0
 public String printConnections() {
   return mapper.printConnections();
 }
示例#7
0
 public boolean connectionEstablishedTo(Address addr) {
   return mapper.connectionEstablishedTo(addr);
 }
示例#8
0
 public void start() throws Exception {
   if (running.compareAndSet(false, true)) {
     acceptor.start();
     mapper.start();
   }
 }
示例#9
0
 public void removeConnectionMapListener(
     AbstractConnectionMap.ConnectionMapListener<TCPConnection> l) {
   mapper.removeConnectionMapListener(l);
 }
示例#10
0
 public void addConnectionMapListener(
     AbstractConnectionMap.ConnectionMapListener<TCPConnection> l) {
   mapper.addConnectionMapListener(l);
 }
示例#11
-2
 public int getNumConnections() {
   return mapper.getNumConnections();
 }