Beispiel #1
0
 public void handleEvent(final ConnectedStreamChannel channel) {
   if (UndertowLogger.REQUEST_LOGGER.isTraceEnabled()) {
     UndertowLogger.REQUEST_LOGGER.tracef("Opened connection with %s", channel.getPeerAddress());
   }
   final PushBackStreamChannel pushBackStreamChannel = new PushBackStreamChannel(channel);
   HttpServerConnection connection =
       new HttpServerConnection(
           channel, bufferPool, rootHandler, maxConcurrentRequestsPerConnection);
   HttpReadListener readListener = new HttpReadListener(channel, connection);
   pushBackStreamChannel.getReadSetter().set(readListener);
   readListener.handleEvent(pushBackStreamChannel);
   channel.resumeReads();
 }
Beispiel #2
0
 private void doConnectionTest(
     final Runnable body,
     final ChannelListener<? super ConnectedStreamChannel> clientHandler,
     final ChannelListener<? super ConnectedStreamChannel> serverHandler)
     throws Exception {
   Xnio xnio = Xnio.getInstance("nio", NioTcpTestCase.class.getClassLoader());
   final ConnectionChannelThread connectionChannelThread =
       xnio.createConnectionChannelThread(threadFactory);
   final ConnectionChannelThread serverChannelThread =
       xnio.createConnectionChannelThread(threadFactory);
   final ReadChannelThread readChannelThread = xnio.createReadChannelThread(threadFactory);
   final ReadChannelThread clientReadChannelThread = xnio.createReadChannelThread(threadFactory);
   final WriteChannelThread writeChannelThread = xnio.createWriteChannelThread(threadFactory);
   final WriteChannelThread clientWriteChannelThread =
       xnio.createWriteChannelThread(threadFactory);
   try {
     final AcceptingChannel<? extends ConnectedStreamChannel> server =
         xnio.createStreamServer(
             new InetSocketAddress(
                 Inet4Address.getByAddress(new byte[] {127, 0, 0, 1}), SERVER_PORT),
             serverChannelThread,
             ChannelListeners.<ConnectedStreamChannel>openListenerAdapter(
                 readChannelThread,
                 writeChannelThread,
                 new CatchingChannelListener<ConnectedStreamChannel>(
                     serverHandler, threadFactory)),
             OptionMap.create(Options.REUSE_ADDRESSES, Boolean.TRUE));
     server.resumeAccepts();
     try {
       final IoFuture<? extends ConnectedStreamChannel> ioFuture =
           xnio.connectStream(
               new InetSocketAddress(
                   Inet4Address.getByAddress(new byte[] {127, 0, 0, 1}), SERVER_PORT),
               connectionChannelThread,
               clientReadChannelThread,
               clientWriteChannelThread,
               new CatchingChannelListener<ConnectedStreamChannel>(clientHandler, threadFactory),
               null,
               OptionMap.EMPTY);
       final ConnectedStreamChannel channel = ioFuture.get();
       try {
         body.run();
         channel.close();
         server.close();
       } catch (Exception e) {
         log.errorf(e, "Error running body");
         throw e;
       } catch (Error e) {
         log.errorf(e, "Error running body");
         throw e;
       } finally {
         IoUtils.safeClose(channel);
       }
     } finally {
       IoUtils.safeClose(server);
     }
   } finally {
     connectionChannelThread.shutdown();
     serverChannelThread.shutdown();
     clientReadChannelThread.shutdown();
     clientWriteChannelThread.shutdown();
     readChannelThread.shutdown();
     writeChannelThread.shutdown();
   }
   connectionChannelThread.awaitTermination();
   serverChannelThread.awaitTermination();
   readChannelThread.awaitTermination();
   writeChannelThread.awaitTermination();
   clientReadChannelThread.awaitTermination();
   clientWriteChannelThread.awaitTermination();
 }