Search in sources :

Example 1 with GridDelimitedParser

use of org.apache.ignite.internal.util.nio.GridDelimitedParser in project ignite by apache.

the class SocketStreamer method start.

/**
 * Starts streamer.
 *
 * @throws IgniteException If failed.
 */
public void start() {
    A.ensure(getSingleTupleExtractor() != null || getMultipleTupleExtractor() != null, "tupleExtractor (single or multiple)");
    A.notNull(getStreamer(), "streamer");
    A.notNull(getIgnite(), "ignite");
    A.ensure(threads > 0, "threads > 0");
    log = getIgnite().log();
    GridNioServerListener<byte[]> lsnr = new GridNioServerListenerAdapter<byte[]>() {

        @Override
        public void onConnected(GridNioSession ses) {
            assert ses.accepted();
            if (log.isDebugEnabled())
                log.debug("Accepted connection: " + ses.remoteAddress());
        }

        @Override
        public void onDisconnected(GridNioSession ses, @Nullable Exception e) {
            if (e != null)
                log.error("Connection failed with exception", e);
        }

        @Override
        public void onMessage(GridNioSession ses, byte[] msg) {
            addMessage(converter.convert(msg));
        }
    };
    ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
    GridNioParser parser = F.isEmpty(delim) ? new GridBufferedParser(directMode, byteOrder) : new GridDelimitedParser(delim, directMode);
    if (converter == null)
        converter = new DefaultConverter<>(getIgnite().name());
    GridNioFilter codec = new GridNioCodecFilter(parser, log, directMode);
    GridNioFilter[] filters = new GridNioFilter[] { codec };
    try {
        srv = new GridNioServer.Builder<byte[]>().address(addr == null ? InetAddress.getLocalHost() : addr).serverName("sock-streamer").port(port).listener(lsnr).logger(log).selectorCount(threads).byteOrder(byteOrder).filters(filters).build();
    } catch (IgniteCheckedException | UnknownHostException e) {
        throw new IgniteException(e);
    }
    srv.start();
    if (log.isDebugEnabled())
        log.debug("Socket streaming server started on " + addr + ':' + port);
}
Also used : GridBufferedParser(org.apache.ignite.internal.util.nio.GridBufferedParser) GridNioFilter(org.apache.ignite.internal.util.nio.GridNioFilter) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridNioParser(org.apache.ignite.internal.util.nio.GridNioParser) UnknownHostException(java.net.UnknownHostException) ByteOrder(java.nio.ByteOrder) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) UnknownHostException(java.net.UnknownHostException) GridDelimitedParser(org.apache.ignite.internal.util.nio.GridDelimitedParser) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) GridNioCodecFilter(org.apache.ignite.internal.util.nio.GridNioCodecFilter) GridNioServerListenerAdapter(org.apache.ignite.internal.util.nio.GridNioServerListenerAdapter) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

UnknownHostException (java.net.UnknownHostException)1 ByteOrder (java.nio.ByteOrder)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 GridBufferedParser (org.apache.ignite.internal.util.nio.GridBufferedParser)1 GridDelimitedParser (org.apache.ignite.internal.util.nio.GridDelimitedParser)1 GridNioCodecFilter (org.apache.ignite.internal.util.nio.GridNioCodecFilter)1 GridNioFilter (org.apache.ignite.internal.util.nio.GridNioFilter)1 GridNioParser (org.apache.ignite.internal.util.nio.GridNioParser)1 GridNioServerListenerAdapter (org.apache.ignite.internal.util.nio.GridNioServerListenerAdapter)1 GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)1 Nullable (org.jetbrains.annotations.Nullable)1