Examples of ServerBootstrap


Examples of org.jboss.netty.bootstrap.ServerBootstrap

  public AHessianJmxServer(MBeanServer mbeanServer, String ipFilter, String serviceDiscoveryName, int port, Logger log)
  {
    Executor executor = Executors.newFixedThreadPool(10);

    // Configure the server.
    ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(executor, executor));

    bootstrap
        .setPipelineFactory(new AHessianServerPipelineFactory(executor, new IpFilterRuleHandler(new IpFilterRuleList(ipFilter)), mbeanServer, log));

    int serverPort = port;
    // Bind and start to accept incoming connections.
    Channel channel = bootstrap.bind(new InetSocketAddress(serverPort));
    if (serverPort == 0)
      serverPort = ((InetSocketAddress) channel.getLocalAddress()).getPort();

    log.info("ahessian jmx service bound to port " + serverPort);
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

  {
    _proxies = proxies;
        Executor executor = Executors.newFixedThreadPool(200);

        // Configure the server.
        ServerBootstrap bootstrap = new ServerBootstrap(
                new OioServerSocketChannelFactory(
                    executor,
                    executor));

        HessianRPCServiceHandler factory =  new HessianRPCServiceHandler(executor);
        factory.addService("default", new ImmediateInvokeService(this, HubService.class, factory));

       
        bootstrap.setPipelineFactory(
               new RPCServerPipelineFactory(executor, factory, acl));

        // Bind and start to accept incoming connections.
        Channel channel =  bootstrap.bind(new InetSocketAddress(port));
  }
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

    ChannelFactory factory =
            new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool());

        ServerBootstrap bootstrap = new ServerBootstrap(factory);
       
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() {
                return Channels.pipeline(new SimpleChannelUpstreamHandler()
                {
            @Override
            public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
            {
              if (mcast != null && mcast.isInit())
                mcast.send((ChannelBuffer) e.getMessage());
            }
           
            @Override
              public void childChannelOpen(ChannelHandlerContext ctx, ChildChannelStateEvent e)
            {
              remoteChannels.add(ctx.getChannel());
              }
           
            @Override
              public void childChannelClosed(ChannelHandlerContext ctx, ChildChannelStateEvent e)
            {
              remoteChannels.add(ctx.getChannel());
              }
           
            @Override
              public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
                  Throwable cause = e.getCause();
                  System.out.println(e);           
              }
                });
            }
        });
        bootstrap.bind(new InetSocketAddress(port));
       
        try
    {
      mcast.init(new ChannelPipelineFactory() {
          public ChannelPipeline getPipeline() {
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

    /**
     * {@inheritDoc}
     */
    public void start(int port) throws IOException {
        factory = new NioServerSocketChannelFactory();
        ServerBootstrap bootstrap = new ServerBootstrap(factory);
        bootstrap.setOption("receiveBufferSize", 128 * 1024);
        bootstrap.setOption("tcpNoDelay", true);
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                return Channels.pipeline(new SimpleChannelUpstreamHandler() {
                    @Override
                    public void childChannelOpen(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception {
                        System.out.println("childChannelOpen");
                        setAttribute(ctx, STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
                    }

                    @Override
                    public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
                        System.out.println("channelOpen");
                        setAttribute(ctx, STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
                        allChannels.add(ctx.getChannel());
                    }

                    public void writeComplete(ChannelHandlerContext ctx, WriteCompletionEvent e) throws Exception {
                        CounterFilter.messageSent.getAndIncrement();
                    }

                    @Override
                    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
                        if (e.getMessage() instanceof ChannelBuffer) {
                            ChannelBuffer buffer = (ChannelBuffer) e.getMessage();

                            State state = (State) getAttribute(ctx, STATE_ATTRIBUTE);
                            int length = 0;
                            if (getAttributesMap(ctx).containsKey(LENGTH_ATTRIBUTE)) {
                                length = (Integer) getAttribute(ctx, LENGTH_ATTRIBUTE);
                            }
                            while (buffer.readableBytes() > 0) {
                                switch (state) {
                                case WAIT_FOR_FIRST_BYTE_LENGTH:
                                    length = (buffer.readByte() & 255) << 24;
                                    state = State.WAIT_FOR_SECOND_BYTE_LENGTH;
                                    break;
                                case WAIT_FOR_SECOND_BYTE_LENGTH:
                                    length += (buffer.readByte() & 255) << 16;
                                    state = State.WAIT_FOR_THIRD_BYTE_LENGTH;
                                    break;
                                case WAIT_FOR_THIRD_BYTE_LENGTH:
                                    length += (buffer.readByte() & 255) << 8;
                                    state = State.WAIT_FOR_FOURTH_BYTE_LENGTH;
                                    break;
                                case WAIT_FOR_FOURTH_BYTE_LENGTH:
                                    length += (buffer.readByte() & 255);
                                    state = State.READING;
                                    if ((length == 0) && (buffer.readableBytes() == 0)) {
                                        ctx.getChannel().write(ACK.slice());
                                        state = State.WAIT_FOR_FIRST_BYTE_LENGTH;
                                    }
                                    break;
                                case READING:
                                    int remaining = buffer.readableBytes();
                                    if (length > remaining) {
                                        length -= remaining;
                                        buffer.skipBytes(remaining);
                                    } else {
                                        buffer.skipBytes(length);
                                        ctx.getChannel().write(ACK.slice());
                                        state = State.WAIT_FOR_FIRST_BYTE_LENGTH;
                                        length = 0;
                                    }
                                }
                            }
                            setAttribute(ctx, STATE_ATTRIBUTE, state);
                            setAttribute(ctx, LENGTH_ATTRIBUTE, length);
                        }
                    }

                    @Override
                    public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
                        allChannels.remove(ctx.getChannel());
                    }

                    @Override
                    public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
                        e.getCause().printStackTrace();
                    }
                });
            }
        });
        allChannels.add(bootstrap.bind(new InetSocketAddress(port)));
    }
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

                                                         Executors.newCachedThreadPool());
      break;
    }
    default: throw new RuntimeException("unsupported server type: " + serverType );
    }
    _srvBootstrap = new ServerBootstrap(channelFactory);
    _srvBootstrap.setOption("child.bufferFactory",
                            DirectChannelBufferFactory.getInstance(bufferByteOrder));
    _srvBootstrap.setParentHandler(new ChildChannelTracker());
  }
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

    processorRegistry.register(GenerateDataEventsRequestProcessor.COMMAND_NAME,
                               new GenerateDataEventsRequestProcessor(null, _relay,
                                                                      randomEventProducer));

    // Configure the server.
    _bootstrap = new ServerBootstrap(new DefaultLocalServerChannelFactory());
    // Set up the event pipeline factory.
    _bootstrap.setPipelineFactory(new HttpServerPipelineFactory(_relay));
    _serverAddress = new LocalAddress(10);
    _serverChannel = _bootstrap.bind(_serverAddress);
  }
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

      ExecutorService bossExecutor = config.bossExecutor();
      if (bossExecutor == null) { bossExecutor = Executors.newCachedThreadPool(); }
      ExecutorService workerExecutor = config.workerExecutor();
      if (workerExecutor == null) { workerExecutor = Executors.newCachedThreadPool(); }
     
        final ServerBootstrap bootstrap = new ServerBootstrap(
                new NioServerSocketChannelFactory(bossExecutor, workerExecutor));

        bootstrap.setPipelineFactory(pipelineFactory);
        return bootstrap;
    }
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

        return bootstrap;
    }

    private ServerBootstrap buildBootstrapFlashPolicy() {
        // Configure the server.
        final ServerBootstrap bootstrap = new ServerBootstrap(
                new NioServerSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool()));

        // Set up the event pipeline factory.
        bootstrap.setPipelineFactory(new FlashPolicyServerPipelineFactory());
        return bootstrap;
    }
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

    setupServer(requestHandler);
  }

  private void setupServer(DummyHttpRequestHandler requestHandler)
  {
    _serverBootstrap = new ServerBootstrap(new DefaultLocalServerChannelFactory());
    ChannelPipeline serverPipeline = pipeline();
    serverPipeline.addLast("server logger 1", new LoggingHandler("server logger 1", InternalLogLevel.DEBUG, true));
    serverPipeline.addLast("decoder", new HttpRequestDecoder());
    serverPipeline.addLast("encoder", new HttpResponseEncoder());
    serverPipeline.addLast("server loggger 5", new LoggingHandler("server logger 5", InternalLogLevel.DEBUG, true));
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

    }

    @Override
    public void run()
    {
      _bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
          Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));

      // Set up the event pipeline factory.
      _bootstrap.setPipelineFactory(new HttpServerPipelineFactory());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.