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