/** * Returns marshaller. * * @return Marshaller. */ protected GridClientMarshaller marshaller(GridNioSession ses) { GridClientMarshaller marsh = ses.meta(MARSHALLER.ordinal()); assert marsh != null; return marsh; }
/** * Gets ssl handler from the session. * * @param ses Session instance. * @return SSL handler. */ private GridNioSslHandler sslHandler(GridNioSession ses) { GridSslMeta sslMeta = ses.meta(SSL_META.ordinal()); assert sslMeta != null; GridNioSslHandler hnd = sslMeta.handler(); if (hnd == null) throw new IgniteException("Failed to process incoming message (received message before SSL handler " + "was created): " + ses); return hnd; }
req.marshallerId(GridClientJdkMarshaller.ID); ses.addMeta(MARSHALLER.ordinal(), marsh);
ses.addMeta(MARSHALLER.ordinal(), marsh);
/** * Tests correct parsing of client handshake packets. * * @throws Exception If failed. */ @Test public void testParseClientHandshake() throws Exception { for (int splitPos = 1; splitPos < 5; splitPos++) { log.info("Checking split position: " + splitPos); ByteBuffer tmp = clientHandshakePacket(); ByteBuffer[] split = split(tmp, splitPos); GridNioSession ses = new MockNioSession(); ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller()); GridTcpRestParser parser = new GridTcpRestParser(false); Collection<GridClientMessage> lst = new ArrayList<>(1); for (ByteBuffer buf : split) { GridClientMessage r; while (buf.hasRemaining() && (r = parser.decode(ses, buf)) != null) lst.add(r); assertTrue("Parser has left unparsed bytes.", buf.remaining() == 0); } assertEquals(1, lst.size()); GridClientHandshakeRequest req = (GridClientHandshakeRequest)F.first(lst); assertNotNull(req); assertEquals(U.bytesToShort(new byte[]{5, 0}, 0), req.version()); } }
ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller());
/** * @throws Exception If failed. */ @Test public void testCustomMessages() throws Exception { GridClientCacheRequest req = new GridClientCacheRequest(CAS); req.key("key"); req.value(1); req.value2(2); req.clientId(UUID.randomUUID()); ByteBuffer raw = clientRequestPacket(req); GridNioSession ses = new MockNioSession(); ses.addMeta(MARSHALLER.ordinal(), new GridClientOptimizedMarshaller()); GridTcpRestParser parser = new GridTcpRestParser(false); GridClientMessage msg = parser.decode(ses, raw); assertNotNull(msg); assertEquals("Parser leaved unparsed bytes", 0, raw.remaining()); assertTrue(msg instanceof GridClientCacheRequest); GridClientCacheRequest res = (GridClientCacheRequest) msg; assertEquals("Invalid operation", req.operation(), res.operation()); assertEquals("Invalid clientId", req.clientId(), res.clientId()); assertEquals("Invalid key", req.key(), res.key()); assertEquals("Invalid value 1", req.value(), res.value()); assertEquals("Invalid value 2", req.value2(), res.value2()); }
/** * Returns marshaller. * * @return Marshaller. */ protected GridClientMarshaller marshaller(GridNioSession ses) { GridClientMarshaller marsh = ses.meta(MARSHALLER.ordinal()); assert marsh != null; return marsh; }
/** * Gets ssl handler from the session. * * @param ses Session instance. * @return SSL handler. */ private GridNioSslHandler sslHandler(GridNioSession ses) { GridSslMeta sslMeta = ses.meta(SSL_META.ordinal()); assert sslMeta != null; GridNioSslHandler hnd = sslMeta.handler(); if (hnd == null) throw new IgniteException("Failed to process incoming message (received message before SSL handler " + "was created): " + ses); return hnd; }
req.marshallerId(GridClientJdkMarshaller.ID); ses.addMeta(MARSHALLER.ordinal(), marsh);
ses.addMeta(MARSHALLER.ordinal(), marsh);