Search in sources :

Example 26 with GridNioSession

use of org.apache.ignite.internal.util.nio.GridNioSession 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

GridNioSession (org.apache.ignite.internal.util.nio.GridNioSession)26 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)11 ByteBuffer (java.nio.ByteBuffer)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 GridNioServer (org.apache.ignite.internal.util.nio.GridNioServer)8 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)8 IgniteException (org.apache.ignite.IgniteException)7 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)7 Nullable (org.jetbrains.annotations.Nullable)5 GridClientOptimizedMarshaller (org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller)4 GridClientMessage (org.apache.ignite.internal.processors.rest.client.message.GridClientMessage)4 IpcEndpoint (org.apache.ignite.internal.util.ipc.IpcEndpoint)4 IpcSharedMemoryServerEndpoint (org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint)4 GridNioRecoveryDescriptor (org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor)4 IOException (java.io.IOException)3 BindException (java.net.BindException)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3