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