/** * Gets filters used by communication. * * @return Filters array. */ private GridNioFilter[] filters() { return new GridNioFilter[] { new GridNioAsyncNotifyFilter(igniteInstanceName, execSvc, log), new HandshakeAndBackpressureFilter(), new HadoopMarshallerFilter(marsh), new GridNioCodecFilter(new GridBufferedParser(directBuf, ByteOrder.nativeOrder()), log, false) }; }
/** {@inheritDoc} */ @Override public void onExceptionCaught( GridNioSession ses, IgniteCheckedException ex ) throws IgniteCheckedException { proceedExceptionCaught(ses, ex); }
/** {@inheritDoc} */ @Override public void onMessageReceived(GridNioSession ses, Object msg) throws IgniteCheckedException { if (!(msg instanceof ByteBuffer)) throw new GridNioException("Failed to decode incoming message (incoming message is not a byte buffer, " + "is filter properly placed?): " + msg.getClass()); try { ByteBuffer input = (ByteBuffer)msg; while (input.hasRemaining()) { Object res = parser.decode(ses, input); if (res != null) proceedMessageReceived(ses, res); else { if (input.hasRemaining()) { if (directMode) return; LT.warn(log, "Parser returned null but there are still unread data in input buffer (bug in " + "parser code?) [parser=" + parser + ", ses=" + ses + ']'); input.position(input.limit()); } } } } catch (IOException e) { throw new GridNioException(e); } }
/** {@inheritDoc} */ @Override public void onSessionIdleTimeout(GridNioSession ses) throws IgniteCheckedException { proceedSessionIdleTimeout(ses); }
/** {@inheritDoc} */ @Override public void onSessionOpened(GridNioSession ses) throws IgniteCheckedException { proceedSessionOpened(ses); }
/** {@inheritDoc} */ @Override public void onSessionClosed(GridNioSession ses) throws IgniteCheckedException { proceedSessionClosed(ses); }
/** {@inheritDoc} */ @Override public GridNioFuture<Boolean> onSessionClose(GridNioSession ses) throws IgniteCheckedException { return proceedSessionClose(ses); }
/** {@inheritDoc} */ @Override public void onSessionIdleTimeout(GridNioSession ses) throws IgniteCheckedException { proceedSessionIdleTimeout(ses); }
/** {@inheritDoc} */ @Override public void onSessionOpened(GridNioSession ses) throws IgniteCheckedException { proceedSessionOpened(ses); }
/** {@inheritDoc} */ @Override public void onSessionClosed(GridNioSession ses) throws IgniteCheckedException { proceedSessionClosed(ses); }
/** {@inheritDoc} */ @Override public GridNioFuture<Boolean> onSessionClose(GridNioSession ses) throws IgniteCheckedException { return proceedSessionClose(ses); }
srvLsnr, writerFactory, new GridNioCodecFilter( new GridDirectParser(log.getLogger(GridDirectParser.class), msgFactory, readerFactory), log,
/** {@inheritDoc} */ @Override public void onExceptionCaught( GridNioSession ses, IgniteCheckedException ex ) throws IgniteCheckedException { proceedExceptionCaught(ses, ex); }
/** {@inheritDoc} */ @Override public void onMessageReceived(GridNioSession ses, Object msg) throws IgniteCheckedException { if (!(msg instanceof ByteBuffer)) throw new GridNioException("Failed to decode incoming message (incoming message is not a byte buffer, " + "is filter properly placed?): " + msg.getClass()); try { ByteBuffer input = (ByteBuffer)msg; while (input.hasRemaining()) { Object res = parser.decode(ses, input); if (res != null) proceedMessageReceived(ses, res); else { if (input.hasRemaining()) { if (directMode) return; LT.warn(log, "Parser returned null but there are still unread data in input buffer (bug in " + "parser code?) [parser=" + parser + ", ses=" + ses + ']'); input.position(input.limit()); } } } } catch (IOException e) { throw new GridNioException(e); } }
GridNioFilter codecFilter = new GridNioCodecFilter(new GridTcpRestParser(routerClient), gridLog, false);
GridNioFilter codecFilter = new GridNioCodecFilter(new ClientListenerBufferedParser(), log, false);
boolean needClientAuth) { try { GridNioFilter codec = new GridNioCodecFilter(parser, log, false);
/** * @param port Port to listen. * @param parser Parser to use. * @param lsnr Listener. * @return Server builder. * @throws Exception If failed. */ @SuppressWarnings("unchecked") protected GridNioServer.Builder<?> serverBuilder(int port, GridNioParser parser, GridNioServerListener lsnr) throws Exception { return GridNioServer.builder() .address(U.getLocalHost()) .port(port) .listener(lsnr) .logger(log) .selectorCount(Runtime.getRuntime().availableProcessors()) .igniteInstanceName("nio-test-grid") .tcpNoDelay(true) .directBuffer(true) .byteOrder(ByteOrder.nativeOrder()) .socketSendBufferSize(0) .socketReceiveBufferSize(0) .sendQueueLimit(0) .filters(new GridNioCodecFilter(parser, log, false)); }
GridNioParser parser, @Nullable SSLContext sslCtx, ConnectorConfiguration cfg) { try { GridNioFilter codec = new GridNioCodecFilter(parser, log, false);
/** * Starts the server. * * @throws IgniteCheckedException If failed. */ public void start() throws IgniteCheckedException { try { String igniteInstanceName = "test"; srv = GridNioServer.<GridClientMessage>builder() .address(InetAddress.getByName("127.0.0.1")) .port(port) .listener(new TestListener()) .logger(log) .selectorCount(2) .igniteInstanceName(igniteInstanceName) .byteOrder(ByteOrder.nativeOrder()) .tcpNoDelay(true) .directBuffer(false) .filters( new GridNioAsyncNotifyFilter(igniteInstanceName, Executors.newFixedThreadPool(2), log), new GridNioCodecFilter(new TestParser(), log, false) ) .build(); } catch (UnknownHostException e) { throw new IgniteCheckedException("Failed to determine localhost address.", e); } srv.start(); }