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...");
}
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") + ")");
}
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)");
}
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();
}
}
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;
}
Aggregations