Search in sources :

Example 71 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project yyl_example by Relucent.

the class NettyServer method main.

public static void main(String[] args) {
    ServerBootstrap bootstrap = new //
    ServerBootstrap(new //
    NioServerSocketChannelFactory(// boss
    Executors.newCachedThreadPool(), // worker
    Executors.newCachedThreadPool()));
    // Set up the default event pipeline.
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new StringDecoder(), new StringEncoder(), new ServerHandler());
        }
    });
    // Bind and start to accept incoming connections.
    Channel bind = bootstrap.bind(new InetSocketAddress(8000));
    System.out.println("Server started, listening port: " + bind.getLocalAddress() + ", Waiting for client register...");
}
Also used : StringEncoder(org.jboss.netty.handler.codec.string.StringEncoder) InetSocketAddress(java.net.InetSocketAddress) StringDecoder(org.jboss.netty.handler.codec.string.StringDecoder) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 72 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project hive by apache.

the class ShuffleHandler method start.

public void start() throws Exception {
    ServerBootstrap bootstrap = new ServerBootstrap(selector);
    // Timer is shared across entire factory and must be released separately
    timer = new HashedWheelTimer();
    try {
        pipelineFact = new HttpPipelineFactory(conf, timer);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    bootstrap.setPipelineFactory(pipelineFact);
    bootstrap.setOption("backlog", NetUtil.SOMAXCONN);
    port = conf.getInt(SHUFFLE_PORT_CONFIG_KEY, DEFAULT_SHUFFLE_PORT);
    Channel ch = bootstrap.bind(new InetSocketAddress(port));
    accepted.add(ch);
    port = ((InetSocketAddress) ch.getLocalAddress()).getPort();
    conf.set(SHUFFLE_PORT_CONFIG_KEY, Integer.toString(port));
    pipelineFact.SHUFFLE.setPort(port);
    if (dirWatcher != null) {
        dirWatcher.start();
    }
    LOG.info("LlapShuffleHandler" + " listening on port " + port + " (SOMAXCONN: " + bootstrap.getOption("backlog") + ")");
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TooLongFrameException(org.jboss.netty.handler.codec.frame.TooLongFrameException) FileNotFoundException(java.io.FileNotFoundException)

Example 73 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project load-balancer by RestComm.

the class HeartbeatService method start.

public void start() {
    serverBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(executor, executor));
    serverBootstrap.setPipelineFactory(new ServerPipelineFactory(this));
    serverChannel = serverBootstrap.bind(new InetSocketAddress(heartBeatIp, heartBeatPort));
    this.started.set(true);
    logger.info("Heartbeat service listen on " + heartBeatIp + ":" + heartBeatPort + " (Node's side)");
}
Also used : ServerPipelineFactory(org.mobicents.tools.heartbeat.server.ServerPipelineFactory) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 74 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project load-balancer by RestComm.

the class AppServer method start.

public void start() {
    ExecutorService executor = Executors.newCachedThreadPool();
    protocolObjects = new ProtocolObjects(name, "gov.nist", transport, false, false, true);
    if (!isSendResponse) {
        sipListener = new TestSipListener(isIpv6, port, lbSIPint, protocolObjects, false);
        sipListener.abortProcessing = true;
    } else if (!isDummy) {
        if (!isMediaFailure || !isFirstStart) {
            sipListener = new TestSipListener(isIpv6, port, lbSIPint, protocolObjects, false);
        } else {
            sipListener = new TestSipListener(isIpv6, port, lbSIPint, protocolObjects, false);
            sipListener.setRespondWithError(Response.SERVICE_UNAVAILABLE);
        }
    } else {
        sipListener = new TestSipListener(isIpv6, port + 1, lbSIPint, protocolObjects, false);
    }
    sipListener.appServer = this;
    try {
        sipProvider = sipListener.createProvider();
        sipProvider.addSipListener(sipListener);
        protocolObjects.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // generate node
    if (!isIpv6)
        node = new Node(name, "127.0.0.1");
    else
        node = new Node(name, "::1");
    node.getProperties().put(transport.toLowerCase() + "Port", "" + port);
    node.getProperties().put(Protocol.VERSION, version);
    node.getProperties().put(Protocol.SESSION_ID, "" + System.currentTimeMillis());
    node.getProperties().put(Protocol.HEARTBEAT_PORT, "" + heartbeatPort);
    nioServerSocketChannelFactory = new NioServerSocketChannelFactory(executor, executor);
    serverBootstrap = new ServerBootstrap(nioServerSocketChannelFactory);
    serverBootstrap.setPipelineFactory(new ServerPipelineFactory(this));
    serverChannel = serverBootstrap.bind(new InetSocketAddress(node.getIp(), heartbeatPort));
    logger.info("Heartbeat service listen on " + heartbeatAddress + ":" + heartbeatPort + " (Node's side)");
    // start client
    if (balancers == null)
        clientController = new ClientController(this, lbAddress, lbPort, node, 5000, heartbeatPeriod, executor);
    else {
        String[] lbs = balancers.split(",");
        clientControllers = new ClientController[lbs.length];
        for (int i = 0; i < lbs.length; i++) {
            if (!isIpv6)
                node = new Node(name, "127.0.0.1");
            else
                node = new Node(name, "::1");
            node.getProperties().put(transport.toLowerCase() + "Port", "" + port);
            node.getProperties().put(Protocol.VERSION, version);
            node.getProperties().put(Protocol.HEARTBEAT_PORT, "" + heartbeatPort);
            clientControllers[i] = new ClientController(this, lbs[i].split(":")[0], Integer.parseInt(lbs[i].split(":")[1]), node, 5000, heartbeatPeriod, executor);
            clientControllers[i].startClient();
        }
    }
    if (sendHeartbeat) {
        if (balancers == null)
            clientController.startClient();
    }
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) Node(org.mobicents.tools.heartbeat.api.Node) ClientController(org.mobicents.tools.heartbeat.impl.ClientController) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ServerPipelineFactory(org.mobicents.tools.heartbeat.server.ServerPipelineFactory) ExecutorService(java.util.concurrent.ExecutorService)

Example 75 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project Protocol-Adapter-OSLP by OSGP.

the class ApplicationContext method serverBootstrapElster.

@Bean(destroyMethod = "releaseExternalResources")
public ServerBootstrap serverBootstrapElster() {
    final ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
    final ServerBootstrap bootstrap = new ServerBootstrap(factory);
    bootstrap.setPipelineFactory(() -> {
        final ChannelPipeline pipeline = ApplicationContext.this.createPipeLine();
        LOGGER.info("Created new server pipeline");
        return pipeline;
    });
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", false);
    bootstrap.bind(new InetSocketAddress(this.oslpElsterPortServer()));
    return bootstrap;
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ChannelFactory(org.jboss.netty.channel.ChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Aggregations

ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)94 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)58 TrackerServer (org.traccar.TrackerServer)42 InetSocketAddress (java.net.InetSocketAddress)38 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)34 ConnectionlessBootstrap (org.jboss.netty.bootstrap.ConnectionlessBootstrap)25 StringEncoder (org.jboss.netty.handler.codec.string.StringEncoder)16 Channel (org.jboss.netty.channel.Channel)13 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)12 StringDecoder (org.jboss.netty.handler.codec.string.StringDecoder)12 LengthFieldBasedFrameDecoder (org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder)11 ChannelFactory (org.jboss.netty.channel.ChannelFactory)8 ExecutorService (java.util.concurrent.ExecutorService)5 DefaultChannelGroup (org.jboss.netty.channel.group.DefaultChannelGroup)5 Test (org.junit.Test)5 HostnamePort (org.neo4j.helpers.HostnamePort)5 CharacterDelimiterFrameDecoder (org.traccar.CharacterDelimiterFrameDecoder)5 IOException (java.io.IOException)4 ChannelException (org.jboss.netty.channel.ChannelException)4 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)4