Examples of ServerBootstrap


Examples of org.jboss.netty.bootstrap.ServerBootstrap

  @Override
  public void init() throws AnalysisException
{
      InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());
        bootstrap =
                new ServerBootstrap(factory);

        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() {
                ChannelPipeline pipe =
                        Channels.pipeline(
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

  public static synchronized void startupNettyServer(int httpPort) {
    if (nettyStarted)
      return;
    nettyStarted = true;
    ServerBootstrap server = new ServerBootstrap(
        new NioServerSocketChannelFactory(
            Executors.newCachedThreadPool(),
            Executors.newCachedThreadPool()));

    server.setPipelineFactory(new CountandraHttpServerPipelineFactory());
    server.bind(new InetSocketAddress(httpPort));

  }
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

                Executors.newCachedThreadPool(workerFactory));
        }
       
        LOG.info("Create Netty Server " + name() + ", buffer_size: " + buffer_size + ", maxWorkers: " + maxWorkers);
       
        bootstrap = new ServerBootstrap(factory);
        bootstrap.setOption("child.tcpNoDelay", true);
        bootstrap.setOption("child.receiveBufferSize", buffer_size);
        bootstrap.setOption("child.keepAlive", true);

        // Set up the pipeline factory.
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

        // *** Start the Netty configuration ***
        // Start server with Nb of active threads = 2*NB CPU + 1 as maximum.
        ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
                Executors.newCachedThreadPool(), (Runtime.getRuntime().availableProcessors() * 2 + 1) * 2);

        ServerBootstrap bootstrap = new ServerBootstrap(factory);
        // Create the global ChannelGroup
        ChannelGroup channelGroup = new DefaultChannelGroup(TSOServer.class.getName());
        // threads max
        // int maxThreads = Runtime.getRuntime().availableProcessors() *2 + 1;
        int maxThreads = 5;
        // Memory limitation: 1MB by channel, 1GB global, 100 ms of timeout
        ThreadPoolExecutor pipelineExecutor = new OrderedMemoryAwareThreadPoolExecutor(maxThreads, 1048576, 1073741824,
                100, TimeUnit.MILLISECONDS, new ObjectSizeEstimator() {
                  @Override
                  public int estimateSize(Object o) {
                     return 1000;
                  }
               }, Executors.defaultThreadFactory());

        // This is the only object of timestamp oracle
        // TODO: make it singleton
        //TimestampOracle timestampOracle = new TimestampOracle();
        // The wrapper for the shared state of TSO
        state = BookKeeperStateBuilder.getState(this.config);
       
        if(state == null){
            LOG.error("Couldn't build state");
            return;
        }

        state.addRecord(new byte[] { LoggerProtocol.LOGSTART }, new AddRecordCallback() {
            @Override
            public void addRecordComplete(int rc, Object ctx) {
            }
        }, null);

        TSOState.BATCH_SIZE = config.getBatchSize();
        System.out.println("PARAM MAX_ITEMS: " + TSOState.MAX_ITEMS);
        System.out.println("PARAM BATCH_SIZE: " + TSOState.BATCH_SIZE);
        System.out.println("PARAM LOAD_FACTOR: " + TSOState.LOAD_FACTOR);
        System.out.println("PARAM MAX_THREADS: " + maxThreads);

        final TSOHandler handler = new TSOHandler(channelGroup, state);
        handler.start();

        bootstrap.setPipelineFactory(new TSOPipelineFactory(pipelineExecutor, handler));
        bootstrap.setOption("tcpNoDelay", false);
        //setting buffer size can improve I/O
        bootstrap.setOption("child.sendBufferSize", 1048576);
        bootstrap.setOption("child.receiveBufferSize", 1048576);
        // better to have an receive buffer predictor
        bootstrap.setOption("receiveBufferSizePredictorFactory",
              new AdaptiveReceiveBufferSizePredictorFactory());
        //if the server is sending 1000 messages per sec, optimum write buffer water marks will
        //prevent unnecessary throttling, Check NioSocketChannelConfig doc
        bootstrap.setOption("writeBufferLowWaterMark", 32 * 1024);
        bootstrap.setOption("writeBufferHighWaterMark", 64 * 1024);

        bootstrap.setOption("child.tcpNoDelay", false);
        bootstrap.setOption("child.keepAlive", true);
        bootstrap.setOption("child.reuseAddress", true);
        bootstrap.setOption("child.connectTimeoutMillis", 60000);

        // *** Start the Netty running ***

        // Create the monitor
        ThroughputMonitor monitor = new ThroughputMonitor(state);
        // Add the parent channel to the group
        Channel channel = bootstrap.bind(new InetSocketAddress(config.getPort()));
        channelGroup.add(channel);
       
        // Compacter handler
        ChannelFactory comFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
              Executors.newCachedThreadPool(), (Runtime.getRuntime().availableProcessors() * 2 + 1) * 2);
        ServerBootstrap comBootstrap = new ServerBootstrap(comFactory);
        ChannelGroup comGroup = new DefaultChannelGroup("compacter");
        final CompacterHandler comHandler = new CompacterHandler(comGroup, state);
        comBootstrap.setPipelineFactory(new ChannelPipelineFactory() {

           @Override
           public ChannelPipeline getPipeline() throws Exception {
              ChannelPipeline pipeline = Channels.pipeline();
              pipeline.addLast("decoder", new ObjectDecoder());
              pipeline.addLast("encoder", new ObjectEncoder());
              pipeline.addLast("handler", comHandler);
              return pipeline;
           }
        });       
        comBootstrap.setOption("tcpNoDelay", false);
        comBootstrap.setOption("child.tcpNoDelay", false);
        comBootstrap.setOption("child.keepAlive", true);
        comBootstrap.setOption("child.reuseAddress", true);
        comBootstrap.setOption("child.connectTimeoutMillis", 100);
        comBootstrap.setOption("readWriteFair", true);
        channel = comBootstrap.bind(new InetSocketAddress(config.getPort() + 1));

        // Starts the monitor
        monitor.start();
        synchronized (lock) {
            while (!finish) {
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

    public void run()
    {
        // Configure the server.
        executionHandler = new ExecutionHandler(new RequestThreadPoolExecutor());
        factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
        ServerBootstrap bootstrap = new ServerBootstrap(factory);

        bootstrap.setOption("child.tcpNoDelay", true);

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

        // Bind and start to accept incoming connections.
        logger.info("Starting listening for CQL clients on " + socket + "...");
        Channel channel = bootstrap.bind(socket);
        connectionTracker.allChannels.add(channel);
    }
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

    private void run()
    {
        // Configure the server.
        executionHandler = new ExecutionHandler(new RequestThreadPoolExecutor());
        factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
        ServerBootstrap bootstrap = new ServerBootstrap(factory);

        bootstrap.setOption("child.tcpNoDelay", true);

        // Set up the event pipeline factory.
        final EncryptionOptions.ClientEncryptionOptions clientEnc = DatabaseDescriptor.getClientEncryptionOptions();
        if (clientEnc.enabled)
        {
            logger.info("Enabling encrypted CQL connections between client and server");
            bootstrap.setPipelineFactory(new SecurePipelineFactory(this, clientEnc));
        }
        else
        {
            bootstrap.setPipelineFactory(new PipelineFactory(this));
        }

        // Bind and start to accept incoming connections.
        logger.info("Starting listening for CQL clients on {}...", socket);
        Channel channel = bootstrap.bind(socket);
        connectionTracker.allChannels.add(channel);
    }
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

    }
   
    CnxnChannelHandler channelHandler = new CnxnChannelHandler();
   
    NettyServerCnxnFactory() {
        bootstrap = new ServerBootstrap(
                new NioServerSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool()));
        // parent channel
        bootstrap.setOption("reuseAddress", true);
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

    ChannelFactory factory = RpcChannelFactory.createServerChannelFactory(serviceName, workerNum);

    DefaultChannelFuture.setUseDeadLockChecker(false);

    pipelineFactory = pipeline;
    bootstrap = new ServerBootstrap(factory);
    bootstrap.setPipelineFactory(pipelineFactory);
    // TODO - should be configurable
    bootstrap.setOption("reuseAddress", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", true);
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

      else
      {
         channelFactory = new OioServerSocketChannelFactory(bossExecutor, workerExecutor);
      }

      bootstrap = new ServerBootstrap(channelFactory);

      final SSLContext context;
      if (sslEnabled)
      {
         try
View Full Code Here

Examples of org.jboss.netty.bootstrap.ServerBootstrap

    public void start() throws JBNodeException {
        if(host == null || port == null || "".equals(host.trim()) || port == 0) {
            throw new JBNodeException("Both host and port must be specified.");
        }

        ServerBootstrap bootstrap = new ServerBootstrap(
                new NioServerSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool(), 10));



        ChannelPipelineFactory channelPipelineFactory = new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                return Channels.pipeline(
                        new RequestDecoder(),

                        new ServerHandler() {
                            @Override
                            protected Object getService(String serviceName) {
                                return serviceConfiguration.getService(serviceName);
                            }

                            @Override
                            protected Method getServiceMethod(String serviceName, String methodName) {
                                return serviceConfiguration.getServiceMethod(serviceName, methodName);
                            }

                            @Override
                            protected byte[] executeMethod(String serviceName, String methodName, Object service,
                                                           Method serviceMethod, byte[] data) throws Exception {
                                Object result = serviceMethod.invoke(service, data);
                                if (result != null) {
                                    return (byte[]) result;
                                } else {
                                    return new byte[]{};
                                }
                            }

                            @Override
                            protected boolean isDebugMode() {
                                return isDebugModeEnabled();
                            }
                        },

                        new ResponseEncoder()
                );
            }
        };
       
        bootstrap.setPipelineFactory(channelPipelineFactory);

        bootstrap.setOption("tcpNoDelay", isTcpNoDelay());
        bootstrap.setOption("keepAlive", isKeepAlive());

        try {
            logger.log(Level.INFO, "Binding to [" + getHost() + ":" + getPort() + "]...");

            Channel channel = bootstrap.bind(new InetSocketAddress(InetAddress.getByName(host), port));
            logger.log(Level.INFO, "Listening on [" + getHost() + ":" + getPort() + "].");
            channelGroup.add(channel);

        } catch (UnknownHostException e) {
            throw new JBNodeException("Unknown host '" + host + "'", e);
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.