@Override public ChannelControlBlock connect(SocketAddress remoteAddress) throws InterruptedException, NetException { MultiplexedConnection mConn = md.connect((InetSocketAddress) remoteAddress); return mConn.openChannel(); }
/** * Create a {@link MultiplexedConnection} that can create channels to the specified remote address. * The remote address must have a {@link MuxDemux} listening for connections. * * @param remoteAddress * - Address of the remote {@link MuxDemux} * @return a {@link MultiplexedConnection} connected to the remote address. * @throws InterruptedException * - This call was interrupted while waiting for connection setup. * In such an event, it is safe to retry the {@link #connect(InetSocketAddress)} call. * @throws NetException */ public MultiplexedConnection connect(InetSocketAddress remoteAddress) throws InterruptedException, NetException { MultiplexedConnection mConn; synchronized (this) { mConn = outgoingConnectionMap.get(remoteAddress); if (mConn == null) { mConn = new MultiplexedConnection(this); outgoingConnectionMap.put(remoteAddress, mConn); tcpEndpoint.initiateConnection(remoteAddress); } } mConn.waitUntilConnected(); return mConn; }
@Override public void notifyIOReady(TCPConnection connection, boolean readable, boolean writable) throws IOException, NetException { if (readable) { driveReaderStateMachine(); } if (writable) { driveWriterStateMachine(); } }
@Override public void connectionFailure(InetSocketAddress remoteAddress, IOException error) { MultiplexedConnection mConn; synchronized (MuxDemux.this) { mConn = outgoingConnectionMap.get(remoteAddress); assert mConn != null; int nConnectionAttempts = mConn.getConnectionAttempts(); if (nConnectionAttempts > MuxDemux.this.maxConnectionAttempts) { outgoingConnectionMap.remove(remoteAddress); mConn.setConnectionFailure(new IOException(remoteAddress.toString() + ": " + error, error)); } else { mConn.setConnectionAttempts(nConnectionAttempts + 1); tcpEndpoint.initiateConnection(remoteAddress); } } }
@Override public void acceptedConnection(TCPConnection connection) { MultiplexedConnection mConn = new MultiplexedConnection(MuxDemux.this); mConn.setTCPConnection(connection); connection.setEventListener(mConn); connection.setAttachment(mConn); incomingConnectionMap.put(connection.getRemoteAddress(), mConn); }
public InetSocketAddress getRemoteAddress() { return cSet.getMultiplexedConnection().getRemoteAddress(); }
public synchronized JsonNode getState() { final ObjectNode state = JSONUtil.createObject(); state.put("localAddress", tcpEndpoint.getLocalAddress().toString()); final ArrayNode outgoingConnections = JSONUtil.createArray(); state.set("outgoingConnections", outgoingConnections); for (MultiplexedConnection connection : outgoingConnectionMap.values()) { connection.getState().ifPresent(outgoingConnections::add); } final ArrayNode incomingConnections = JSONUtil.createArray(); state.set("incomingConnections", incomingConnections); for (MultiplexedConnection connection : incomingConnectionMap.values()) { connection.getState().ifPresent(incomingConnections::add); } return state; } }
MultiplexedConnection mConn = new MultiplexedConnection(MuxDemux.this); mConn.setTCPConnection(connection); connection.setEventListener(mConn);
private ChannelControlBlock createChannel(int idx) throws NetException { if (idx > MuxDemuxCommand.MAX_CHANNEL_ID) { throw new NetException("Channel Id > " + MuxDemuxCommand.MAX_CHANNEL_ID + " being opened"); } if (idx >= ccbArray.length) { expand(idx); } if (ccbArray[idx] != null) { assert ccbArray[idx].completelyClosed() : ccbArray[idx].toString(); if (ccbArray[idx].completelyClosed()) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Cleaning free channel: " + ccbArray[idx]); } freeChannel(ccbArray[idx]); } } assert idx < ccbArray.length; assert !allocationBitmap.get(idx); IChannelInterfaceFactory channelInterfaceFactory = mConn.getChannelInterfaceFactory(); ChannelControlBlock channel = new ChannelControlBlock(this, idx, channelInterfaceFactory); ccbArray[idx] = channel; allocationBitmap.set(idx); ++openChannelCount; return channel; }
public synchronized Optional<JsonNode> getState() { if (tcpConnection == null) { return Optional.empty(); } final ObjectNode state = JSONUtil.createObject(); state.put("remoteAddress", getRemoteAddress().toString()); final ArrayNode channels = cSet.getState(); state.set("channels", channels); return Optional.of(state); } }
public ChannelControlBlock connect(SocketAddress remoteAddress) throws InterruptedException, NetException { MultiplexedConnection mConn = md.connect((InetSocketAddress) remoteAddress); return mConn.openChannel(); }
public ChannelControlBlock connect(SocketAddress remoteAddress) throws InterruptedException, NetException { MultiplexedConnection mConn = md.connect((InetSocketAddress) remoteAddress); return mConn.openChannel(); }
private ChannelControlBlock connect(SocketAddress remoteAddress) throws InterruptedException, NetException { MultiplexedConnection mConn = md.connect((InetSocketAddress) remoteAddress); return mConn.openChannel(); }