/** * @param addr Node address. * @param rmtNodeId Id of node to open connection check session with. */ public void init(InetSocketAddress addr, UUID rmtNodeId) { boolean connect; try { ch = SocketChannel.open(); ch.configureBlocking(false); ch.socket().setTcpNoDelay(true); ch.socket().setKeepAlive(false); connect = ch.connect(addr); } catch (Exception e) { finish(false); return; } if (!connect) { sesMeta = new GridLeanMap<>(3); // Set dummy key to identify connection-check outgoing connection. sesMeta.put(TcpCommunicationSpi.CONN_IDX_META, new ConnectionKey(rmtNodeId, -1, -1, true)); sesMeta.put(SES_FUT_META, this); nioSrvr.createSession(ch, sesMeta, true, new IgniteInClosure<IgniteInternalFuture<GridNioSession>>() { @Override public void apply(IgniteInternalFuture<GridNioSession> fut) { if (fut.error() != null) finish(false); } }); } }
ses = (GridNioSession)srv.createSession(ch, meta, false, null).get();
nioSrvr.createSession(ch, F.<Integer, Object>asMap(HANDSHAKE_FINISH_META, fin), false, null);
/** * @throws Exception If test failed. */ @Test public void testAsyncSendReceive() throws Exception { CountDownLatch latch = new CountDownLatch(10); NioListener lsnr = new NioListener(latch); GridNioServer<?> srvr1 = startServer(new BufferedParser(false), lsnr); GridNioServer<?> srvr2 = startServer(new BufferedParser(false), lsnr); GridNioSession ses = null; try { SocketChannel ch = SocketChannel.open(new InetSocketAddress(U.getLocalHost(), srvr2.port())); GridNioFuture<GridNioSession> fut = srvr1.createSession(ch, null, false, null); ses = fut.get(); for (int i = 0; i < 5; i++) { ses.send(createMessageWithSize()); ses.send(createMessageWithSize()); } assert latch.await(30, SECONDS); assertEquals("Unexpected message count", 10, lsnr.getMessageCount()); } finally { if (ses != null) ses.close(); srvr1.stop(); srvr2.stop(); } }
/** * @param addr Node address. * @param rmtNodeId Id of node to open connection check session with. */ public void init(InetSocketAddress addr, UUID rmtNodeId) { boolean connect; try { ch = SocketChannel.open(); ch.configureBlocking(false); ch.socket().setTcpNoDelay(true); ch.socket().setKeepAlive(false); connect = ch.connect(addr); } catch (Exception e) { finish(false); return; } if (!connect) { sesMeta = new GridLeanMap<>(3); // Set dummy key to identify connection-check outgoing connection. sesMeta.put(TcpCommunicationSpi.CONN_IDX_META, new ConnectionKey(rmtNodeId, -1, -1, true)); sesMeta.put(SES_FUT_META, this); nioSrvr.createSession(ch, sesMeta, true, new IgniteInClosure<IgniteInternalFuture<GridNioSession>>() { @Override public void apply(IgniteInternalFuture<GridNioSession> fut) { if (fut.error() != null) finish(false); } }); } }
ses = (GridNioSession)srv.createSession(ch, meta, false, null).get();
GridNioSession ses = nioSrvr.createSession(ch, meta, false, null).get();