/** * @param ses NIO session. * @param res Response. * @return NIO send future. */ private GridNioFuture<?> sendResponse(GridNioSession ses, GridMemcachedMessage res) { return ses.send(res); }
/** * Sends a response to be encoded and sent to the Redis client. * * @param ses NIO session. * @param res Response. * @return NIO send future. */ private GridNioFuture<?> sendResponse(GridNioSession ses, GridRedisMessage res) { return ses.send(res); } }
@Override public void onMessage(GridNioSession ses, Object msg) { // Reply with echo. ses.send(msg); } };
@Override public void onMessage(GridNioSession ses, Object msg) { // Reply with echo. ses.send(msg); } };
@Override public void onMessage(GridNioSession ses, Object msg) { // Reply with echo. ses.send(msg); } };
@Override public void onMessage(GridNioSession ses, Object msg) { // Reply with echo. ses.send(msg); } };
/** {@inheritDoc} */ @Override public void onMessage(GridNioSession ses, byte[] msg) { ses.send(msg); } }
@Override public void onMessage(GridNioSession ses, Object msg) { // Reply with echo. ses.send(msg); } };
@Override public void onDone(GridClientFuture fut) { try { GridRouterResponse res = (GridRouterResponse)fut.get(); // Restoring original request id, because it was overwritten by the client. res.requestId(reqId); ses.send(res); } catch (GridClientException e) { ses.send(makeFailureResponse(e, clientId, reqId)); } } });
@Override public void onConnected(GridNioSession ses) { ses.send(bytes); }
/** {@inheritDoc} */ @Override public void onMessage(GridNioSession ses, GridClientMessage msg) { if (msg == GridClientPingPacket.PING_MESSAGE) ses.send(GridClientPingPacket.PING_MESSAGE); else if (msg instanceof GridClientAuthenticationRequest) ses.send(makeResponseFor(msg)); else if (msg instanceof GridClientTopologyRequest) { GridClientResponse res = makeResponseFor(msg); res.result(top); ses.send(res); } else if (msg instanceof GridClientHandshakeRequest) ses.send(GridClientHandshakeResponse.OK); }
@Override public void onMessage(GridNioSession ses, ByteBuffer msg) { ByteBuffer buf = ByteBuffer.allocate(msg.remaining()).put(msg); buf.position(0); ses.send(buf); }
/** {@inheritDoc} */ @Override public void sendMessage(ByteBuffer data) throws IgniteCheckedException { if (closed()) throw new IgniteCheckedException("Client was closed: " + this); GridNioFuture<?> fut = ses.send(data); if (fut.isDone()) fut.get(); }
/** {@inheritDoc} */ @Override public void sendMessage(HadoopProcessDescriptor desc, HadoopMessage msg) throws IgniteCheckedException { if (closed()) throw new IgniteCheckedException("Client was closed: " + this); GridNioFuture<?> fut = ses.send(msg); if (fut.isDone()) fut.get(); }
@Override public void send(ClientListenerResponse resp) { if (resp != null) { if (log.isDebugEnabled()) log.debug("Async response: [resp=" + resp.status() + ']'); byte[] outMsg = parser.encode(resp); ses.send(outMsg); } } };
@Override public void send(ClientListenerResponse resp) { if (resp != null) { if (log.isDebugEnabled()) log.debug("Async response: [resp=" + resp.status() + ']'); byte[] outMsg = parser.encode(resp); ses.send(outMsg); } } };
/** {@inheritDoc} */ @Override public void onSessionOpened(final GridNioSession ses) throws IgniteCheckedException { if (ses.accepted()) { if (log.isDebugEnabled()) log.debug("Accepted connection, initiating handshake: " + ses); // Server initiates handshake. ses.send(locIdMsg).listen(new CI1<IgniteInternalFuture<?>>() { @Override public void apply(IgniteInternalFuture<?> fut) { try { // Make sure there were no errors. fut.get(); } catch (IgniteCheckedException e) { log.warning("Failed to send handshake message, will close session: " + ses, e); ses.close(); } } }); } }
/** * @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(); } }
GridNioFuture<?> sf = ses.send(res);