/** * <p>Creates a new client to the given server address using the given {@link StreamConnection} to decode the data. * The given connection <b>MUST</b> be unique to this object. This does not block while waiting for the connection to * open, but will call either the {@link StreamConnection#connectionOpened()} or * {@link StreamConnection#connectionClosed()} callback on the created network event processing thread.</p> * * @param connectTimeoutMillis The connect timeout set on the connection (in milliseconds). 0 is interpreted as no * timeout. */ public NioClient(final SocketAddress serverAddress, final StreamConnection parser, final int connectTimeoutMillis) throws IOException { manager.startAsync(); manager.awaitRunning(); handler = new Handler(parser, connectTimeoutMillis); Futures.addCallback(manager.openConnection(serverAddress, handler), new FutureCallback<SocketAddress>() { @Override public void onSuccess(SocketAddress result) { } @Override public void onFailure(Throwable t) { log.error("Connect to {} failed: {}", serverAddress, Throwables.getRootCause(t)); } }); }
/** * <p>Creates a new client to the given server address using the given {@link StreamConnection} to decode the data. * The given connection <b>MUST</b> be unique to this object. This does not block while waiting for the connection to * open, but will call either the {@link StreamConnection#connectionOpened()} or * {@link StreamConnection#connectionClosed()} callback on the created network event processing thread.</p> * * @param connectTimeoutMillis The connect timeout set on the connection (in milliseconds). 0 is interpreted as no * timeout. */ public NioClient(final SocketAddress serverAddress, final StreamConnection parser, final int connectTimeoutMillis) throws IOException { manager.startAsync(); manager.awaitRunning(); handler = new Handler(parser, connectTimeoutMillis); Futures.addCallback(manager.openConnection(serverAddress, handler), new FutureCallback<SocketAddress>() { @Override public void onSuccess(SocketAddress result) { } @Override public void onFailure(Throwable t) { log.error("Connect to {} failed: {}", serverAddress, Throwables.getRootCause(t)); } }); }
/** * <p>Creates a new client to the given server address using the given {@link StreamConnection} to decode the data. * The given connection <b>MUST</b> be unique to this object. This does not block while waiting for the connection to * open, but will call either the {@link StreamConnection#connectionOpened()} or * {@link StreamConnection#connectionClosed()} callback on the created network event processing thread.</p> * * @param connectTimeoutMillis The connect timeout set on the connection (in milliseconds). 0 is interpreted as no * timeout. */ public NioClient(final SocketAddress serverAddress, final StreamConnection parser, final int connectTimeoutMillis) throws IOException { manager.startAsync(); manager.awaitRunning(); handler = new Handler(parser, connectTimeoutMillis); Futures.addCallback(manager.openConnection(serverAddress, handler), new FutureCallback<SocketAddress>() { @Override public void onSuccess(SocketAddress result) { } @Override public void onFailure(Throwable t) { log.error("Connect to {} failed: {}", serverAddress, Throwables.getRootCause(t)); } }); }
/** * <p>Creates a new client to the given server address using the given {@link StreamConnection} to decode the data. * The given connection <b>MUST</b> be unique to this object. This does not block while waiting for the connection to * open, but will call either the {@link StreamConnection#connectionOpened()} or * {@link StreamConnection#connectionClosed()} callback on the created network event processing thread.</p> * * @param connectTimeoutMillis The connect timeout set on the connection (in milliseconds). 0 is interpreted as no * timeout. */ public NioClient(final SocketAddress serverAddress, final StreamConnection parser, final int connectTimeoutMillis) throws IOException { manager.startAsync(); manager.awaitRunning(); handler = new Handler(parser, connectTimeoutMillis); Futures.addCallback(manager.openConnection(serverAddress, handler), new FutureCallback<SocketAddress>() { @Override public void onSuccess(SocketAddress result) { } @Override public void onFailure(Throwable t) { log.error("Connect to {} failed: {}", serverAddress, Throwables.getRootCause(t)); } }); }
@Override public synchronized void setWriteTarget(MessageWriteTarget writeTarget) { if (closeOnOpen) writeTarget.closeConnection(); else { setTimeoutEnabled(false); this.writeTarget = writeTarget; upstreamConnection.setWriteTarget(writeTarget); } }
@Override protected synchronized void timeoutOccurred() { closeOnOpen = true; connectionClosed(); }
@Override public synchronized void setWriteTarget(MessageWriteTarget writeTarget) { if (closeOnOpen) writeTarget.closeConnection(); else { setTimeoutEnabled(false); this.writeTarget = writeTarget; upstreamConnection.setWriteTarget(writeTarget); } }
Handler(StreamConnection upstreamConnection, int connectTimeoutMillis) { this.upstreamConnection = upstreamConnection; setSocketTimeout(connectTimeoutMillis); setTimeoutEnabled(true); }
Handler(StreamConnection upstreamConnection, int connectTimeoutMillis) { this.upstreamConnection = upstreamConnection; setSocketTimeout(connectTimeoutMillis); setTimeoutEnabled(true); }
@Override public synchronized void setWriteTarget(MessageWriteTarget writeTarget) { if (closeOnOpen) writeTarget.closeConnection(); else { setTimeoutEnabled(false); this.writeTarget = writeTarget; upstreamConnection.setWriteTarget(writeTarget); } }
@Override protected synchronized void timeoutOccurred() { closeOnOpen = true; connectionClosed(); }
@Override protected synchronized void timeoutOccurred() { closeOnOpen = true; connectionClosed(); }
Handler(StreamConnection upstreamConnection, int connectTimeoutMillis) { this.upstreamConnection = upstreamConnection; setSocketTimeout(connectTimeoutMillis); setTimeoutEnabled(true); }
Handler(StreamConnection upstreamConnection, int connectTimeoutMillis) { this.upstreamConnection = upstreamConnection; setSocketTimeout(connectTimeoutMillis); setTimeoutEnabled(true); }
@Override public synchronized void setWriteTarget(MessageWriteTarget writeTarget) { if (closeOnOpen) writeTarget.closeConnection(); else { setTimeoutEnabled(false); this.writeTarget = writeTarget; upstreamConnection.setWriteTarget(writeTarget); } }
@Override protected synchronized void timeoutOccurred() { closeOnOpen = true; connectionClosed(); }