Package org.jboss.netty.bootstrap

Examples of org.jboss.netty.bootstrap.ServerBootstrap


          maxWorkers = Runtime.getRuntime().availableProcessors();
        }
   
        ChannelFactory factory = new NioServerSocketChannelFactory(this.nettyPool, this.nettyPool, maxWorkers);
       
        ServerBootstrap bootstrap = new ServerBootstrap(factory);
        this.channelHandler = createChannelPipelineFactory(config, storageManager);
        bootstrap.setPipelineFactory(channelHandler);
        if (inputBufferSize != 0) {
          bootstrap.setOption("receiveBufferSize", new Integer(inputBufferSize)); //$NON-NLS-1$
        }
        if (outputBufferSize != 0) {
          bootstrap.setOption("sendBufferSize", new Integer(outputBufferSize)); //$NON-NLS-1$
        }
        bootstrap.setOption("keepAlive", Boolean.TRUE); //$NON-NLS-1$
       
        this.serverChanel = bootstrap.bind(new InetSocketAddress(bindAddress, port));
    }
View Full Code Here


        // Default behavior is to silently discard any exceptions caused
        // when reading/writing to the client. The Internet is flaky - it happens.
        connectionExceptionHandler(new SilentExceptionHandler());

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

        // Set up the event pipeline factory.
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            @Override
            public ChannelPipeline getPipeline() throws Exception {
View Full Code Here

*/
public class FactorialServer {

    public static void main(String[] args) throws Exception {
        // Configure the server.
        ServerBootstrap bootstrap = new ServerBootstrap(
                new NioServerSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool()));

        // Set up the event pipeline factory.
        bootstrap.setPipelineFactory(new FactorialServerPipelineFactory());

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

    public static void main(String[] args)
    {
        Executor executor = Executors.newFixedThreadPool(200);

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

        bootstrap.setPipelineFactory(
               new RPCServerSessionPipelineFactory( new RPCServerMixinPipelineFactory(executor)));

        // Bind and start to accept incoming connections.
        bootstrap.bind(new InetSocketAddress(8080));

    }
View Full Code Here

   * Inits the.
   */
  private void initInternal()
  {
    _acceptor = null;
    _acceptor = new ServerBootstrap(new OioServerSocketChannelFactory(executor, executor));

    // ???do not allow multiple servers to bind on the same port
    _acceptor.setOption("reuseAddress", false);
    _acceptor.setOption("tcpNoDelay", true);
    _acceptor.setPipelineFactory(new ControllerPipelineFactory(this, _debug));
View Full Code Here

   
   
        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(getServiceManagerServer(), ServiceManagerServer.class, factory));

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

        // Bind and start to accept incoming connections.
        Channel channel =  bootstrap.bind(new InetSocketAddress(serverPort));
        if (serverPort == 0)
          serverPort = ((InetSocketAddress)channel.getLocalAddress()).getPort();
       
        System.out.println("bound to port "+serverPort);
       
View Full Code Here

  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

  {
    _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

    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

    /**
     * {@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

TOP

Related Classes of org.jboss.netty.bootstrap.ServerBootstrap

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.