本文整理汇总了Java中org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory类的典型用法代码示例。如果您正苦于以下问题:Java NioServerSocketChannelFactory类的具体用法?Java NioServerSocketChannelFactory怎么用?Java NioServerSocketChannelFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NioServerSocketChannelFactory类属于org.jboss.netty.channel.socket.nio包,在下文中一共展示了NioServerSocketChannelFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
public static void main(String[] args) {
// Server服务启动器
ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
// 设置一个处理客户端消息和各种消息事件的类(Handler)
bootstrap
.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline()
throws Exception {
return Channels
.pipeline(new HelloServerHandler());
}
});
// 开放8000端口供客户端访问。
bootstrap.bind(new InetSocketAddress(8000));
}
示例2: NettyServerCnxnFactory
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
NettyServerCnxnFactory() {
bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
// parent channel
bootstrap.setOption("reuseAddress", true);
// child channels
bootstrap.setOption("child.tcpNoDelay", true);
/* set socket linger to off, so that socket close does not block */
bootstrap.setOption("child.soLinger", -1);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline p = Channels.pipeline();
if (secure) {
initSSL(p);
}
p.addLast("servercnxnfactory", channelHandler);
return p;
}
});
}
示例3: startHttpServer
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
private ServerBootstrap startHttpServer(int port,
final Token<DelegationTokenIdentifier> token, final URI url) {
ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new HttpRequestDecoder(),
new HttpChunkAggregator(65536), new HttpResponseEncoder(),
new CredentialsLogicHandler(token, url.toString()));
}
});
bootstrap.bind(new InetSocketAddress("localhost", port));
return bootstrap;
}
示例4: start
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
@Override
public void start() throws KairosDBException
{
// Configure the server.
serverBootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("telnet-boss-%d").build()),
Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("telnet-worker-%d").build())));
// Configure the pipeline factory.
serverBootstrap.setPipelineFactory(this);
serverBootstrap.setOption("child.tcpNoDelay", true);
serverBootstrap.setOption("child.keepAlive", true);
serverBootstrap.setOption("reuseAddress", true);
// Bind and start to accept incoming connections.
serverBootstrap.bind(new InetSocketAddress(address, port));
}
示例5: main
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
public static void main(String[] args) {
String hostname = "127.0.0.1";
int port = 5044;
if (args.length >= 2) {
hostname = args[0];
port = firstNonNull(Ints.tryParse(args[1]), 5044);
}
if (args.length >= 1) {
port = firstNonNull(Ints.tryParse(args[1]), 5044);
}
final ChannelFactory factory =
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
final ServerBootstrap b = new ServerBootstrap(factory);
b.getPipeline().addLast("beats-frame-decoder", new BeatsFrameDecoder());
b.getPipeline().addLast("beats-codec", new BeatsCodecHandler());
b.getPipeline().addLast("logging", new LoggingHandler());
System.out.println("Starting listener on " + hostname + ":" + port);
b.bind(new InetSocketAddress(hostname, port));
}
示例6: connect
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
/**
* Startup a ServerBootstrap with NioServerSocketChannelFactory using the
* portNo specified in the constructor.
*
* @return
*/
public ServerBootstrap connect() {
bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new MessageFrameDecoder(), new MessageEventBagHandler(bagList));
}
});
System.out.println("Binding to: localhost:" + portNo);
bootstrap.bind(new InetSocketAddress("localhost", portNo));
return bootstrap;
}
示例7: connectServer
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
private ServerBootstrap connectServer(boolean simulateConflict,
boolean simulateConflictErrorPointer) {
ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
final MessageEventBagHandler messagEventBagHandler = new MessageEventBagHandler(
bagList, simulateConflict, simulateConflictErrorPointer);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new MessageFrameDecoder(),
messagEventBagHandler);
}
});
bootstrap.bind(new InetSocketAddress(testPort));
return bootstrap;
}
示例8: connectServer
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
private ServerBootstrap connectServer() {
ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new MessageFrameDecoder(),
new MessageEventBagHandler(bagList));
}
});
bootstrap.bind(new InetSocketAddress(testPort));
return bootstrap;
}
示例9: connect
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
@Override
public void connect() {
workerService = createWorkerService(getThreadPoolType(CollectorProperties.WRITER.COLLECTOR_WORKER_THREAD_POOL));
workerbossService = createWorkderBossService(getThreadPoolType(CollectorProperties.WRITER.COLLECTOR_WORKERBOSS_THREAD_POOL));
channelFactory = new NioServerSocketChannelFactory(workerbossService,
workerService);
bootstrap = new ServerBootstrap(channelFactory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(ipFilterHandler,
new MessageFrameDecoder(), new ReadTimeoutHandler(
HashedWheelTimerFactory.getInstance(),
readTimeout, TimeUnit.MILLISECONDS),
metricsHandler, channelHandler);
}
});
bootstrap.bind(new InetSocketAddress(port));
}
示例10: connectLockBootstrap
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
/**
* Startup a ServerBootstrap with NioServerSocketChannelFactory using the
* portNo specified in the constructor.
*
*/
private void connectLockBootstrap() {
lockBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
lockBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new MessageFrameDecoder(),
metricHandler, lockHandler);
}
});
lockBootstrap.bind(new InetSocketAddress(lockPort));
}
示例11: connectUnlockBootstrap
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
/**
* Startup a ServerBootstrap with NioServerSocketChannelFactory using the
* portNo specified in the constructor.
*
*/
private void connectUnlockBootstrap() {
unlockBootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
unlockBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new MessageFrameDecoder(),
unlockHandler);
}
});
unlockBootstrap.bind(new InetSocketAddress(releaseLockPort));
}
示例12: TSOChannelHandler
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
@Inject
public TSOChannelHandler(TSOServerConfig config, RequestProcessor requestProcessor, MetricsRegistry metrics) {
this.config = config;
this.metrics = metrics;
this.requestProcessor = requestProcessor;
// Setup netty listener
this.factory = new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("boss-%d").build()),
Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("worker-%d").build()),
(Runtime.getRuntime().availableProcessors() * 2 + 1) * 2);
this.bootstrap = new ServerBootstrap(factory);
bootstrap.setPipelineFactory(new TSOPipelineFactory(this));
}
示例13: ProgrammableTSOServer
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
@Inject
public ProgrammableTSOServer(int port) {
// Setup netty listener
factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(new ThreadFactoryBuilder()
.setNameFormat("boss-%d").build()), Executors.newCachedThreadPool(new ThreadFactoryBuilder()
.setNameFormat("worker-%d").build()), (Runtime.getRuntime().availableProcessors() * 2 + 1) * 2);
// Create the global ChannelGroup
channelGroup = new DefaultChannelGroup(ProgrammableTSOServer.class.getName());
ServerBootstrap bootstrap = new ServerBootstrap(factory);
bootstrap.setPipelineFactory(new TSOChannelHandler.TSOPipelineFactory(this));
// Add the parent channel to the group
Channel channel = bootstrap.bind(new InetSocketAddress(port));
channelGroup.add(channel);
LOG.info("********** Dumb TSO Server running on port {} **********", port);
}
示例14: start
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
public void start()
{
//Configure the server
NioServerSocketChannelFactory nioFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
ServerBootstrap bootstrap = new ServerBootstrap(nioFactory);
// Configure the pipeline factory.
bootstrap.setPipelineFactory(new TextProtocolPipelineFactory());
//some more options
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
// Bind and start to accept incoming connections.
this.channel = bootstrap.bind(new InetSocketAddress(1504));
System.out.println("--------------------------------------------");
System.out.println("Netty Http Server successfully loaded on port ("+1504+").....");
System.out.println("--------------------------------------------");
}
示例15: doLoad
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //导入依赖的package包/类
@Override
protected boolean doLoad() throws ModuleException {
serverBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool(),
workerCount));
serverBootstrap.setPipelineFactory(new MyChannelPipelineFactory(this));
serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
serverBootstrap.setOption("child.keepAlive", tcpKeepAlive);
if (tcpSendBufferSize > 0) {
serverBootstrap.setOption("child.sendBufferSize", tcpSendBufferSize);
}
if (tcpReceiveBufferSize > 0) {
serverBootstrap.setOption("child.receiveBufferSize", tcpReceiveBufferSize);
}
serverBootstrap.setOption("reuseAddress", reuseAddress);
serverBootstrap.setOption("child.reuseAddress", reuseAddress);
serverChannel = serverBootstrap.bind(new InetSocketAddress(port));
logger.debug("Bound to port [{}]", port);
return true;
}