List of usage examples for io.vertx.core.net NetSocket endHandler
@Override NetSocket endHandler(Handler<Void> endHandler);
This handler might be called after the close handler when the socket is paused and there are still buffers to deliver.
From source file:com.sibvisions.rad.remote.vertx.NetSocketConnection.java
License:Apache License
/** * {@inheritDoc}/* www .jav a 2s . co m*/ */ @Override public void open(ConnectionInfo pConnectionInfo) throws Throwable { closeSocket(); NetClientOptions options = new NetClientOptions(); options.setReconnectAttempts(3); options.setConnectTimeout(5000); options.setReconnectInterval(1000); client = vertx.createNetClient(options); client.connect(iPort, sHost, new Handler<AsyncResult<NetSocket>>() { public void handle(final AsyncResult<NetSocket> pCommunication) { NetSocket sock = pCommunication.result(); if (sock != null) { sock.handler(new Handler<Buffer>() { public void handle(Buffer pBuffer) { if (inputStream != null) { inputStream.receive(pBuffer); } } }); sock.exceptionHandler(new Handler<Throwable>() { public void handle(Throwable pException) { if (inputStream != null) { inputStream.finish(); } } }); sock.endHandler(new Handler<Void>() { public void handle(Void pParam) { if (inputStream != null) { inputStream.finish(); } } }); } synchronized (NetSocketConnection.this) { if (pCommunication.succeeded()) { socket = sock; } else { LoggerFactory.getInstance(NetSocketConnection.class).error(pCommunication.cause()); socket = null; } NetSocketConnection.this.notify(); } } }); synchronized (this) { if (socket == null) { wait(15000); } } if (socket == null) { throw new ConnectException("Can't establish connection!"); } socket.write(Buffer.buffer(new byte[] { STREAM_COMMUNICATION })); super.open(pConnectionInfo); if (oInitialConId == null) { oInitialConId = pConnectionInfo.getConnectionId(); } }
From source file:com.sibvisions.rad.remote.vertx.NetSocketConnection.java
License:Apache License
/** * Opens a new transfer client.// w w w. j a v a 2 s .c om * * @throws IOException if opening failed */ private void openTransfer() throws IOException { closeTransfer(); if (socketTransfer != null) { socketTransfer.close(); socketTransfer = null; } NetClientOptions options = new NetClientOptions(); options.setReconnectAttempts(3); options.setReconnectInterval(1000); clientTransfer = vertx.createNetClient(options); isTransfer = new SyncedInputStream(); clientTransfer.connect(iPort, sHost, new Handler<AsyncResult<NetSocket>>() { public void handle(AsyncResult<NetSocket> pCommunication) { NetSocket sock = pCommunication.result(); if (sock != null) { sock.handler(new Handler<Buffer>() { public void handle(Buffer pBuffer) { if (isTransfer != null) { isTransfer.receive(pBuffer); } } }); sock.exceptionHandler(new Handler<Throwable>() { public void handle(Throwable pException) { if (isTransfer != null) { isTransfer.finish(); } } }); sock.endHandler(new Handler<Void>() { public void handle(Void pParam) { if (isTransfer != null) { isTransfer.finish(); } } }); } synchronized (clientTransfer) { socketTransfer = sock; clientTransfer.notify(); } } }); try { synchronized (clientTransfer) { if (socketTransfer == null) { clientTransfer.wait(15000); } } } catch (InterruptedException ie) { throw new IOException(ie); } if (socketTransfer == null) { throw new ConnectException("Can't establish transfer connection!"); } }
From source file:com.sibvisions.vertx.NetSocketServer.java
License:Apache License
/** * Starts the server to listen on the configured port. *///from w w w . ja v a 2 s .c o m public void start() { if (vertx == null) { vertx = Vertx.vertx(); } NetServerOptions options = new NetServerOptions(); options.setTcpKeepAlive(true); options.setTcpNoDelay(true); srvVertx = vertx.createNetServer(options); srvVertx.connectHandler(new Handler<NetSocket>() { public void handle(NetSocket pSocket) { AbstractDataHandler dataHandler = new NetDataHandler(srvJVx, pSocket); pSocket.handler(dataHandler); pSocket.endHandler(new StopHandler(dataHandler)); pSocket.exceptionHandler(new ExceptionHandler(dataHandler)); } }); srvVertx.listen(iPort, sInterface); }
From source file:shadowsocks.vertxio.ClientHandler.java
License:Apache License
private void setFinishHandler(NetSocket socket) { socket.closeHandler(v -> {/* ww w.j a v a 2 s . c o m*/ destory(); }); socket.endHandler(v -> { destory(); }); socket.exceptionHandler(e -> { log.error("Catch Exception.", e); destory(); }); }