List of usage examples for io.vertx.core.net NetClientOptions NetClientOptions
public NetClientOptions()
From source file:com.cyngn.vertx.opentsdb.service.client.OpenTsDbClient.java
License:Apache License
public OpenTsDbClient(String host, int port, Vertx vertx, Consumer<Boolean> onInitialized) { NetClientOptions options = new NetClientOptions().setTcpKeepAlive(true); netClient = vertx.createNetClient(options); connected = false;//from w ww. j a va 2 s . c o m consecutiveDisconnects = 0; bytesWrittenForPeriod = 0; bus = vertx.eventBus(); this.vertx = vertx; this.host = host; this.port = port; netClient.connect(port, host, connectResult -> { onInitialized.accept(connectResult.succeeded()); if (connectResult.succeeded()) { onConnect(connectResult.result()); } // if we don't succeed initially we'll fail startup of the reporter }); }
From source file:com.sibvisions.rad.remote.vertx.NetSocketConnection.java
License:Apache License
/** * {@inheritDoc}/*from w w w. j a va 2 s . c om*/ */ @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.//from ww w. ja 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:examples.NetExamples.java
License:Open Source License
public void example14(Vertx vertx) { NetClientOptions options = new NetClientOptions().setConnectTimeout(10000); NetClient client = vertx.createNetClient(options); }
From source file:examples.NetExamples.java
License:Open Source License
public void example15(Vertx vertx) { NetClientOptions options = new NetClientOptions().setConnectTimeout(10000); NetClient client = vertx.createNetClient(options); client.connect(4321, "localhost", res -> { if (res.succeeded()) { System.out.println("Connected!"); NetSocket socket = res.result(); } else {/*from w ww.j a v a2 s .com*/ System.out.println("Failed to connect: " + res.cause().getMessage()); } }); }
From source file:examples.NetExamples.java
License:Open Source License
public void example16(Vertx vertx) { NetClientOptions options = new NetClientOptions().setReconnectAttempts(10).setReconnectInterval(500); NetClient client = vertx.createNetClient(options); }
From source file:examples.NetExamples.java
License:Open Source License
public void exampleNetworkActivityLoggingOnClient(Vertx vertx) { NetClientOptions options = new NetClientOptions().setLogActivity(true); NetClient client = vertx.createNetClient(options); }
From source file:examples.NetExamples.java
License:Open Source License
public void example29(Vertx vertx) { NetClientOptions options = new NetClientOptions().setSsl(true).setTrustAll(true); NetClient client = vertx.createNetClient(options); }
From source file:examples.NetExamples.java
License:Open Source License
public void example30(Vertx vertx) { NetClientOptions options = new NetClientOptions().setSsl(true).setTrustStoreOptions(new JksOptions() .setPath("/path/to/your/truststore.jks").setPassword("password-of-your-truststore")); NetClient client = vertx.createNetClient(options); }
From source file:examples.NetExamples.java
License:Open Source License
public void example31(Vertx vertx) { Buffer myTrustStoreAsABuffer = vertx.fileSystem().readFileBlocking("/path/to/your/truststore.jks"); NetClientOptions options = new NetClientOptions().setSsl(true).setTrustStoreOptions( new JksOptions().setValue(myTrustStoreAsABuffer).setPassword("password-of-your-truststore")); NetClient client = vertx.createNetClient(options); }