Package io.netty.channel.socket

Examples of io.netty.channel.socket.SocketChannel


    private static ChannelListener<StreamConnection> switchToHornetQProtocol(final HornetQServer hornetqServer, final String acceptorName) {
        return new ChannelListener<StreamConnection>() {
            @Override
            public void handleEvent(final StreamConnection connection) {
                MESSAGING_LOGGER.debugf("Switching to %s protocol for %s http-acceptor", HORNETQ_REMOTING, acceptorName);
                SocketChannel channel = new WrappingXnioSocketChannel(connection);
                RemotingService remotingService = hornetqServer.getRemotingService();

                NettyAcceptor acceptor = (NettyAcceptor)remotingService.getAcceptor(acceptorName);
                acceptor.transfer(channel);
                connection.getSourceChannel().resumeReads();
View Full Code Here


    i++;
    ch.write(new Command(set, numToBytes(i, false), VALUE));
  }

  public static void main(String[] args) throws Exception {
    final SocketChannel ch = new NioSocketChannel();
    new NioEventLoopGroup().register(ch);
    final long start = System.currentTimeMillis();
    ch.pipeline().addLast(new RedisCommandEncoder(), new RedisReplyDecoder());
    ch.connect(new InetSocketAddress("localhost", 6379)).addListener(new ChannelFutureListener() {
      @Override
      public void operationComplete(ChannelFuture channelFuture) throws Exception {
        write(ch);
      }
    });
View Full Code Here

    }
  }

  @Override
  protected <C> NetChannel<IN, OUT> createChannel(C ioChannel) {
    SocketChannel ch = (SocketChannel) ioChannel;
    int backlog = getEnvironment().getProperty("reactor.tcp.connectionReactorBacklog", Integer.class, 128);

    return new NettyNetChannel<IN, OUT>(
        getEnvironment(),
        getCodec(),
        new NettyEventLoopDispatcher(ch.eventLoop(), backlog),
        getReactor(),
        ch
    );
  }
View Full Code Here

    group.register(socketChannel);
  }

  public static Promise<RedisClientBase> connect(String host, int port) {
    final Queue<Promise<Reply>> queue = new LinkedList<>();
    SocketChannel socketChannel = new NioSocketChannel();
    final RedisClientBase client = new RedisClientBase(socketChannel, queue);
    socketChannel.pipeline().addLast(new RedisCommandEncoder(), new RedisReplyDecoder(),
            new SimpleChannelInboundHandler<Reply<?>>() {
              @Override
              protected void channelRead0(ChannelHandlerContext channelHandlerContext, Reply<?> reply) throws Exception {
                Promise<Reply> poll;
                synchronized (client) {
                  poll = queue.poll();
                  if (poll == null) {
                    throw new IllegalStateException("Promise queue is empty, received reply");
                  }
                }
                poll.set(reply);
              }
            });
    final Promise<RedisClientBase> promise = new Promise<>();
    socketChannel.connect(new InetSocketAddress(host, port)).addListener(new ChannelFutureListenerPromiseAdapter<>(promise, client));
    return promise;
  }
View Full Code Here

            if (log.isDebugEnabled()) {
                log.debug("Received HTTP message {}", httpObject);
            }
            if (httpObject instanceof HttpRequest) {
                HttpRequest req = (HttpRequest)httpObject;
                SocketChannel channel = (SocketChannel)ctx.channel();
                curRequest = new NettyHttpRequest(req, channel);
                // Set the "attachment" field on the Java request object for testing
                curRequest.setClientAttachment(injectedAttachment);

                curResponse = new NettyHttpResponse(
View Full Code Here

public class RegisterSocket {

    public void register(java.nio.channels.SocketChannel socket, EventLoopGroup egroup) {
        java.nio.channels.SocketChannel mySocket = socket;

        SocketChannel ch = new NioSocketChannel(mySocket);
        EventLoopGroup group = egroup;
        group.register(ch);

    }
View Full Code Here

        TestHandler h = new TestHandler();
        ServerSocket ss = new ServerSocket();
        Socket s = null;
        try {
            ss.bind(addr);
            SocketChannel ch = (SocketChannel) cb.handler(h).connect().sync().channel();
            assertTrue(ch.isActive());
            assertFalse(ch.isOutputShutdown());

            s = ss.accept();
            ch.writeAndFlush(Unpooled.wrappedBuffer(new byte[] { 1 })).sync();
            assertEquals(1, s.getInputStream().read());

            assertTrue(h.ch.isOpen());
            assertTrue(h.ch.isActive());
            assertFalse(h.ch.isInputShutdown());
            assertFalse(h.ch.isOutputShutdown());

            // Make the connection half-closed and ensure read() returns -1.
            ch.shutdownOutput().sync();
            assertEquals(-1, s.getInputStream().read());

            assertTrue(h.ch.isOpen());
            assertTrue(h.ch.isActive());
            assertFalse(h.ch.isInputShutdown());
View Full Code Here

        run();
    }

    public void testWriteBeforeConnect(Bootstrap cb) throws Throwable {
        TestHandler h = new TestHandler();
        SocketChannel ch = null;
        try {
            ch = (SocketChannel) cb.handler(h).connect().channel();
            ch.writeAndFlush(Unpooled.wrappedBuffer(new byte[] { 1 }));
        } finally {
            if (ch != null) {
                ch.close();
            }
        }
    }
View Full Code Here

TOP

Related Classes of io.netty.channel.socket.SocketChannel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.