Beispiel #1
0
    @Override
    public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {

      final NioSocketChannel ch = (NioSocketChannel) e.getChannel();
      NioWorker worker = ch.getWorker();

      // Choose a handler
      final HandlerHolder handler = handlerManager.chooseHandler(worker);

      if (handler == null) {
        // Ignore
        return;
      }

      VertxInternal.instance.executeOnContext(
          handler.contextID,
          new Runnable() {
            public void run() {
              VertxInternal.instance.setContextID(handler.contextID);
              NetSocket sock = new NetSocket(ch, handler.contextID, Thread.currentThread());
              socketMap.put(ch, sock);
              handler.handler.handle(sock);
            }
          });
    }
Beispiel #2
0
    @Override
    public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {

      final NioSocketChannel ch = (NioSocketChannel) e.getChannel();
      NioWorker worker = ch.getWorker();

      // Choose a handler
      final HandlerHolder handler = handlerManager.chooseHandler(worker);

      if (handler == null) {
        // Ignore
        return;
      }

      if (tcpHelper.isSSL()) {
        SslHandler sslHandler = (SslHandler) ch.getPipeline().get("ssl");

        ChannelFuture fut = sslHandler.handshake();
        fut.addListener(
            new ChannelFutureListener() {

              public void operationComplete(ChannelFuture channelFuture) throws Exception {
                if (channelFuture.isSuccess()) {
                  connected(ch, handler);
                } else {
                  log.error(
                      "Client from origin "
                          + ch.getRemoteAddress()
                          + " failed to connect over ssl");
                }
              }
            });

      } else {
        connected(ch, handler);
      }
    }
Beispiel #3
0
 /*
 Currently Netty does not provide all events for a connection on the same thread - e.g. connection open
 connection bound etc are provided on the acceptor thread.
 In vert.x we must ensure all events are executed on the correct event loop for the context
 This code will go away if Netty acts like a proper event loop.
  */
 public void runOnCorrectThread(NioSocketChannel nch, Runnable runnable) {
   nch.getWorker().executeInIoThread(runnable, false);
 }