本文整理汇总了Java中org.jboss.netty.channel.group.DefaultChannelGroup.add方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultChannelGroup.add方法的具体用法?Java DefaultChannelGroup.add怎么用?Java DefaultChannelGroup.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.channel.group.DefaultChannelGroup
的用法示例。
在下文中一共展示了DefaultChannelGroup.add方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.jboss.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
/**
* Tell controller that we're ready to accept pcc connections.
*/
public void run() {
try {
final ServerBootstrap bootstrap = createServerBootStrap();
bootstrap.setOption("reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
ChannelPipelineFactory pfact = new PcepPipelineFactory(this);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa = new InetSocketAddress(pcepPort);
cg = new DefaultChannelGroup();
cg.add(bootstrap.bind(sa));
log.info("Listening for PCC connection on {}", sa);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例2: ProgrammableTSOServer
import org.jboss.netty.channel.group.DefaultChannelGroup; //导入方法依赖的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);
}
示例3: run
import org.jboss.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
/**
* Tell controller that we're ready to accept switches loop.
*/
public void run() {
try {
final ServerBootstrap bootstrap = createServerBootStrap();
bootstrap.setOption("reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
ChannelPipelineFactory pfact =
new OpenflowPipelineFactory(this, null);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa = new InetSocketAddress(openFlowPort);
cg = new DefaultChannelGroup();
cg.add(bootstrap.bind(sa));
log.info("Listening for switch connections on {}", sa);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例4: run
import org.jboss.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
/**
* Tell controller that we're ready to accept pcc connections.
*/
public void run() {
try {
final ServerBootstrap bootstrap = createServerBootStrap();
bootstrap.setOption("reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
ChannelPipelineFactory pfact = new PcepPipelineFactory(this);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa = new InetSocketAddress(pcepPort);
cg = new DefaultChannelGroup();
cg.add(bootstrap.bind(sa));
log.debug("Listening for PCC connection on {}", sa);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
示例5: run
import org.jboss.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
/**
* Tell controller that we're ready to accept bgp peer connections.
*/
public void run() {
try {
peerBootstrap = createPeerBootStrap();
peerBootstrap.setOption("reuseAddr", true);
peerBootstrap.setOption("child.keepAlive", true);
peerBootstrap.setOption("child.tcpNoDelay", true);
peerBootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
final ServerBootstrap bootstrap = createServerBootStrap();
bootstrap.setOption("reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
ChannelPipelineFactory pfact = new BgpPipelineFactory(bgpController, true);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa = new InetSocketAddress(getBgpPortNum());
cg = new DefaultChannelGroup();
serverChannel = bootstrap.bind(sa);
cg.add(serverChannel);
log.info("Listening for Peer connection on {}", sa);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例6: startClient
import org.jboss.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
public void startClient() {
ClientBootstrap bootstrap = new ClientBootstrap(
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
try {
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() {
ChannelPipeline p = Channels.pipeline();
handler = new NettyClientHandler();
p.addLast("handler", handler);
return p;
}
});
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("receiveBufferSize", 1048576);
bootstrap.setOption("sendBufferSize", 1048576);
// Start the connection attempt.
LOG.info("EventClient: Connecting " + host + "," + port);
ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
LOG.info("EventClient: Connected " + host + "," + port);
allChannels = new DefaultChannelGroup();
// Wait until the connection is closed or the connection attempt fails.
allChannels.add(future.getChannel());
LOG.info("EventClient: Added to Channels ");
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: start
import org.jboss.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
/**
* Bind the network connection and start the network processing threads.
*/
public void start() {
// TODO provide tweakable options here for passing in custom executors.
channelFactory =
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
allChannels = new DefaultChannelGroup("jmemcachedChannelGroup");
ServerBootstrap bootstrap = new ServerBootstrap(channelFactory);
ChannelPipelineFactory pipelineFactory;
if (binary)
pipelineFactory = createMemcachedBinaryPipelineFactory(cache, memcachedVersion, verbose, idleTime, allChannels);
else
pipelineFactory = createMemcachedPipelineFactory(cache, memcachedVersion, verbose, idleTime, frameSize, allChannels);
bootstrap.setPipelineFactory(pipelineFactory);
bootstrap.setOption("sendBufferSize", 65536 );
bootstrap.setOption("receiveBufferSize", 65536);
Channel serverChannel = bootstrap.bind(addr);
allChannels.add(serverChannel);
log.info("Listening on " + String.valueOf(addr.getHostName()) + ":" + addr.getPort());
running = true;
}
示例8: start
import org.jboss.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
/**
* Bind the network connection and start the network processing threads.
*/
public void start() {
// TODO provide tweakable options here for passing in custom executors.
channelFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors
.newCachedThreadPool());
allChannels = new DefaultChannelGroup("jmemcachedChannelGroup");
ServerBootstrap bootstrap = new ServerBootstrap(channelFactory);
ChannelPipelineFactory pipelineFactory;
if (binary)
pipelineFactory = createMemcachedBinaryPipelineFactory(cache, memcachedVersion, verbose, idleTime,
allChannels);
else
pipelineFactory = createMemcachedPipelineFactory(cache, memcachedVersion, verbose, idleTime, frameSize,
allChannels);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.receiveBufferSize", 1024 * 64);
bootstrap.setPipelineFactory(pipelineFactory);
Channel serverChannel = bootstrap.bind(addr);
allChannels.add(serverChannel);
log.info("Listening on " + String.valueOf(addr.getHostName()) + ":" + addr.getPort());
running = true;
}
示例9: run
import org.jboss.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
/**
* Tell controller that we're ready to accept bgp peer connections.
*/
public void run() {
try {
peerBootstrap = createPeerBootStrap();
peerBootstrap.setOption("reuseAddr", true);
peerBootstrap.setOption("child.keepAlive", true);
peerBootstrap.setOption("child.tcpNoDelay", true);
peerBootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
final ServerBootstrap bootstrap = createServerBootStrap();
bootstrap.setOption("reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
ChannelPipelineFactory pfact = new BgpPipelineFactory(bgpController, true);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa = new InetSocketAddress(getBgpPortNum());
cg = new DefaultChannelGroup();
serverChannel = bootstrap.bind(sa);
cg.add(serverChannel);
log.info("Listening for Peer connection on {}", sa);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
示例10: start
import org.jboss.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
public boolean start() throws IOException {
hostname = configuration.getServerHostname();
InetSocketAddress address;
if (StringUtils.isNotBlank(hostname)) {
LOGGER.info("Using forced address " + hostname);
InetAddress tempIA = InetAddress.getByName(hostname);
if (tempIA != null && networkInterface != null && networkInterface.equals(NetworkInterface.getByInetAddress(tempIA))) {
address = new InetSocketAddress(tempIA, port);
} else {
address = new InetSocketAddress(hostname, port);
}
} else if (isAddressFromInterfaceFound(configuration.getNetworkInterface())) { // XXX sets iafinal and networkInterface
LOGGER.info("Using address {} found on network interface: {}", iafinal, networkInterface.toString().trim().replace('\n', ' '));
address = new InetSocketAddress(iafinal, port);
} else {
LOGGER.info("Using localhost address");
address = new InetSocketAddress(port);
}
LOGGER.info("Created socket: {}", address);
if (configuration.isHTTPEngineV2()) { // HTTP Engine V2
ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
group = new DefaultChannelGroup("HTTPServer");
factory = new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(new NettyBossThreadFactory()),
Executors.newCachedThreadPool(new NettyWorkerThreadFactory())
);
ServerBootstrap bootstrap = new ServerBootstrap(factory);
HttpServerPipelineFactory pipeline = new HttpServerPipelineFactory(group);
bootstrap.setPipelineFactory(pipeline);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("reuseAddress", true);
bootstrap.setOption("child.reuseAddress", true);
bootstrap.setOption("child.sendBufferSize", 65536);
bootstrap.setOption("child.receiveBufferSize", 65536);
try {
channel = bootstrap.bind(address);
group.add(channel);
} catch (Exception e) {
LOGGER.error("Another program is using port " + port + ", which DMS needs.");
LOGGER.error("You can change the port DMS uses on the General Configuration tab.");
LOGGER.trace("The error was: " + e);
PMS.get().getFrame().setConnectionState(ConnectionState.BLOCKED);
}
if (hostname == null && iafinal != null) {
hostname = iafinal.getHostAddress();
} else if (hostname == null) {
hostname = InetAddress.getLocalHost().getHostAddress();
}
} else { // HTTP Engine V1
serverSocketChannel = ServerSocketChannel.open();
serverSocket = serverSocketChannel.socket();
serverSocket.setReuseAddress(true);
serverSocket.bind(address);
if (hostname == null && iafinal != null) {
hostname = iafinal.getHostAddress();
} else if (hostname == null) {
hostname = InetAddress.getLocalHost().getHostAddress();
}
runnable = new Thread(this, "HTTPv1 Request Handler");
runnable.setDaemon(false);
runnable.start();
}
return true;
}
示例11: afterPropertiesSet
import org.jboss.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
public void afterPropertiesSet() throws Exception {
cache = new SpaceCache(space);
channelFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
allChannels = new DefaultChannelGroup("memcachedChannelGroup");
ServerBootstrap bootstrap = new ServerBootstrap(channelFactory);
ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new UnifiedProtocolDecoder(cache, allChannels, memcachedVersion, idleTime, false, threaded));
}
};
if ("binary".equalsIgnoreCase(protocol)) {
pipelineFactory = createMemcachedBinaryPipelineFactory(cache, memcachedVersion, false, idleTime, allChannels);
} else if ("text".equalsIgnoreCase(protocol)) {
pipelineFactory = createMemcachedPipelineFactory(cache, memcachedVersion, false, idleTime, frameSize, allChannels);
}
bootstrap.setPipelineFactory(pipelineFactory);
bootstrap.setOption("sendBufferSize", 65536);
bootstrap.setOption("receiveBufferSize", 65536);
InetAddress address = null;
if (host != null) {
address = InetAddress.getByName(host);
}
Exception lastException = null;
boolean success = false;
int i;
for (i = 0; i < portRetries; i++) {
try {
Channel serverChannel = bootstrap.bind(new InetSocketAddress(address, port + i));
allChannels.add(serverChannel);
success = true;
break;
} catch (Exception e) {
lastException = e;
}
}
if (!success) {
throw lastException;
}
boundedPort = port + i;
logger.info("memcached started on port [" + boundedPort + "]");
}