本文整理汇总了Java中io.netty.channel.group.DefaultChannelGroup类的典型用法代码示例。如果您正苦于以下问题:Java DefaultChannelGroup类的具体用法?Java DefaultChannelGroup怎么用?Java DefaultChannelGroup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultChannelGroup类属于io.netty.channel.group包,在下文中一共展示了DefaultChannelGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: closeConnectionAsync
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
@Override
public CompletionStage<NodeConnectionReport> closeConnectionAsync(
SocketAddress connection, CloseType type) {
Optional<Channel> channel =
this.clientChannelGroup
.stream()
.filter(c -> c.remoteAddress().equals(connection))
.findFirst();
if (channel.isPresent()) {
ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
channelGroup.add(channel.get());
ClusterConnectionReport clusterReport = new ClusterConnectionReport(getCluster().getId());
NodeConnectionReport report =
clusterReport.addNode(this, Collections.singletonList(connection), getAddress());
return closeChannelGroup(channelGroup, type).thenApply(f -> report);
} else {
CompletableFuture<NodeConnectionReport> failedFuture = new CompletableFuture<>();
failedFuture.completeExceptionally(new IllegalArgumentException("Not found"));
return failedFuture;
}
}
示例2: RedisClient
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
@Deprecated
public RedisClient(final Timer timer, ExecutorService executor, EventLoopGroup group, Class<? extends SocketChannel> socketChannelClass, String host, int port,
int connectTimeout, int commandTimeout) {
RedisClientConfig config = new RedisClientConfig();
config.setTimer(timer).setExecutor(executor).setGroup(group).setSocketChannelClass(socketChannelClass)
.setAddress(host, port).setConnectTimeout(connectTimeout).setCommandTimeout(commandTimeout);
this.config = config;
this.executor = config.getExecutor();
this.timer = config.getTimer();
addr = new InetSocketAddress(config.getAddress().getHost(), config.getAddress().getPort());
channels = new DefaultChannelGroup(config.getGroup().next());
bootstrap = createBootstrap(config, Type.PLAIN);
pubSubBootstrap = createBootstrap(config, Type.PUBSUB);
this.commandTimeout = config.getCommandTimeout();
}
示例3: init
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
public void init() throws SyncException {
cg = new DefaultChannelGroup("Cluster Bootstrap", GlobalEventExecutor.INSTANCE);
workerExecutor = new NioEventLoopGroup();
timer = new HashedWheelTimer();
bootstrap = new Bootstrap()
.group(workerExecutor)
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_REUSEADDR, true)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_SNDBUF, RPCService.SEND_BUFFER_SIZE)
.option(ChannelOption.SO_RCVBUF, RPCService.SEND_BUFFER_SIZE)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, RPCService.CONNECT_TIMEOUT);
pipelineFactory = new BootstrapChannelInitializer(timer, this);
bootstrap.handler(pipelineFactory);
}
示例4: init
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
public void init() throws SyncException {
cg = new DefaultChannelGroup("Cluster Bootstrap", GlobalEventExecutor.INSTANCE);
workerExecutor = new NioEventLoopGroup();
timer = new HashedWheelTimer();
bootstrap = new Bootstrap()
.group(workerExecutor)
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_REUSEADDR, true)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_SNDBUF, RPCService.SEND_BUFFER_SIZE)
.option(ChannelOption.SO_RCVBUF, RPCService.SEND_BUFFER_SIZE)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, RPCService.CONNECT_TIMEOUT);
pipelineFactory = new BootstrapChannelInitializer(timer, this);
bootstrap.handler(pipelineFactory);
}
示例5: NettyIoAcceptor
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
public NettyIoAcceptor(NettyIoServiceFactory factory, IoHandler handler) {
this.factory = factory;
this.handler = handler;
channelGroup = new DefaultChannelGroup("sshd-acceptor-channels", GlobalEventExecutor.INSTANCE);;
bootstrap.group(factory.eventLoopGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new NettyIoSession(NettyIoAcceptor.this, handler).adapter);
}
});
}
示例6: ReplicatorService
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
/**
* ReplicatorService creates and starts fibers; it must be stopped (or failed) in
* order to dispose them.
*/
public ReplicatorService(EventLoopGroup bossGroup,
EventLoopGroup workerGroup,
long nodeId,
int port,
ModuleInformationProvider moduleInformationProvider,
FiberSupplier fiberSupplier,
QuorumFileReaderWriter quorumFileReaderWriter) {
this.bossGroup = bossGroup;
this.workerGroup = workerGroup;
this.nodeId = nodeId;
this.port = port;
this.moduleInformationProvider = moduleInformationProvider;
this.fiberSupplier = fiberSupplier;
this.allChannels = new DefaultChannelGroup(workerGroup.next());
this.persister = new Persister(quorumFileReaderWriter);
}
示例7: NettyIoAcceptor
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
public NettyIoAcceptor(NettyIoServiceFactory factory, IoHandler handler) {
this.factory = factory;
this.handler = handler;
channelGroup = new DefaultChannelGroup("sshd-acceptor-channels", GlobalEventExecutor.INSTANCE);;
bootstrap.group(factory.eventLoopGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new NettyIoSession(NettyIoAcceptor.this, handler).adapter);
}
});
}
示例8: AbstractRedisClient
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
/**
* Create a new instance with client resources.
*
* @param clientResources the client resources. If {@literal null}, the client will create a new dedicated instance of
* client resources and keep track of them.
*/
protected AbstractRedisClient(ClientResources clientResources) {
if (clientResources == null) {
sharedResources = false;
this.clientResources = DefaultClientResources.create();
} else {
sharedResources = true;
this.clientResources = clientResources;
}
unit = TimeUnit.SECONDS;
genericWorkerPool = this.clientResources.eventExecutorGroup();
channels = new DefaultChannelGroup(genericWorkerPool.next());
timer = (HashedWheelTimer) this.clientResources.timer();
}
示例9: RpcServer
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
<T extends ServerSocketChannel> RpcServer(EventLoopGroup eventLoopGroup, EventExecutorGroup eventExecutor, Class<T> channel, SocketAddress address) {
this.address = address;
this.allChannels = new DefaultChannelGroup(eventLoopGroup.next());
this.handler = new ServerHandler(allChannels);
this.bootstrap = new ServerBootstrap();
bootstrap.channel(channel);
bootstrap.childHandler(new ServerInitializer(eventExecutor, handler));
bootstrap.group(eventLoopGroup);
bootstrap.option(ChannelOption.TCP_NODELAY, true);
}
示例10: WebSocketServerThread
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
public WebSocketServerThread(Settings settings) {
this.PORT = settings.httpPort;
this.SSL = false; // TODO: support ssl?
this.blockBridge = null;
this.playersBridge = null;
this.webPlayerBridge = null;
this.allUsersGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
this.settings = settings;
}
示例11: WebImageViewer
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
public WebImageViewer(InetSocketAddress address) {
this.address = address;
this.bossGroup = new NioEventLoopGroup();
this.workerGroup = new NioEventLoopGroup();
this.allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
this.bootstrap = new ServerBootstrap()
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class);
}
示例12: startUp
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
@Override
protected void startUp() throws Exception {
channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
EventLoopGroup bossGroup = new NioEventLoopGroup(NUM_BOSS_THREADS,
new ThreadFactoryBuilder()
.setDaemon(true).setNameFormat("boss-thread").build());
EventLoopGroup workerGroup = new NioEventLoopGroup(NUM_WORKER_THREADS,
new ThreadFactoryBuilder()
.setDaemon(true).setNameFormat("worker-thread#%d").build());
bootstrap = new ServerBootstrap()
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
channelGroup.add(ch);
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("codec", new HttpServerCodec());
pipeline.addLast("compressor", new HttpContentCompressor());
pipeline.addLast("aggregator", new HttpObjectAggregator(MAX_INPUT_SIZE));
pipeline.addLast("handler", new ReportHandler());
}
});
Channel serverChannel = bootstrap.bind(new InetSocketAddress(host, 0)).sync().channel();
channelGroup.add(serverChannel);
bindAddress = (InetSocketAddress) serverChannel.localAddress();
url = URI.create(String.format("http://%s:%d", host, bindAddress.getPort())).toURL();
LOG.info("Tracker service started at {}", url);
}
示例13: configure
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see com.heliosapm.streams.tracing.AbstractMetricWriter#configure(java.util.Properties)
*/
@Override
public void configure(final Properties config) {
super.configure(config);
remotes = ConfigurationHelper.getArraySystemThenEnvProperty(CONFIG_REMOTE_URIS, DEFAULT_REMOTE_URIS, config);
Collections.addAll(remoteUris, remotes);
channelGroupThreads = ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_EXEC_THREADS, DEFAULT_EXEC_THREADS, config);
this.config.put("channelGroupThreads", channelGroupThreads);
eventLoopThreads = ConfigurationHelper.getIntSystemThenEnvProperty(CONFIG_ELOOP_THREADS, DEFAULT_ELOOP_THREADS, config);
this.config.put("eventLoopThreads", eventLoopThreads);
eventExecutor = new UnorderedThreadPoolEventExecutor(channelGroupThreads, groupThreadFactory, this);
channels = new DefaultChannelGroup(getClass().getSimpleName() + "Channels", eventExecutor);
group = new NioEventLoopGroup(eventLoopThreads, eventLoopThreadFactory);
bootstrap
.group(group)
.channel(channelType)
.handler(getChannelInitializer())
;
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000); // FIXME: config
bootstrap.option(ChannelOption.ALLOCATOR, BufferManager.getInstance());
this.config.put("connectTimeout", 5000);
// FIXME: Tweaks for channel configuration
}
示例14: startServer
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
/**
* Scotty, start me up!
* Initializes the netty data pipeline and starts the IO server
*
* @throws InterruptedException if interrupted while waiting for the startup
* @throws IllegalStateException is the Server is already running
*/
private void startServer() throws InterruptedException {
if (isChannelOpen()) {
throw new IllegalStateException("Server already running");
}
//Setup the Executor and Connection Pool
final ExecutionServiceComponent eventLoop = requireComponent(ExecutionServiceComponent.KEY);
connections = new DefaultChannelGroup(eventLoop.next());
ServerBootstrap b = new ServerBootstrap()
.group(eventLoop)
.channel(NioServerSocketChannel.class)
.childHandler(getHandshakeHandler())
.childOption(ChannelOption.SO_KEEPALIVE, true);
//Bind to ports and wait for the start of the server
final int localPort = getLocalPort();
if (localPort < 0 || localPort > 65535) {
throw new StartupException("Illegal localPort " + localPort);
}
localChannel = b.bind(localPort).sync();
final int publicPort = getPublicPort();
if (publicPort >= 0 && publicPort <= 65535 && localPort != publicPort) {
publicChannel = b.bind(publicPort).sync();
}
Log.i(getClass().getSimpleName(), "Server bound to port " + localChannel.channel() + (publicChannel != null ? " and " + publicChannel.channel() : ""));
}
示例15: init
import io.netty.channel.group.DefaultChannelGroup; //导入依赖的package包/类
public void init(CamelContext camelContext, NettyServerBootstrapConfiguration configuration, ChannelInitializer<Channel> pipelineFactory) {
this.camelContext = camelContext;
this.configuration = configuration;
this.pipelineFactory = pipelineFactory;
this.allChannels = configuration.getChannelGroup() != null
? configuration.getChannelGroup()
: new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName(), ImmediateEventExecutor.INSTANCE);
}