本文整理了Java中io.netty.bootstrap.Bootstrap.group()
方法的一些代码示例,展示了Bootstrap.group()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bootstrap.group()
方法的具体详情如下:
包路径:io.netty.bootstrap.Bootstrap
类名称:Bootstrap
方法名:group
暂无
代码示例来源:origin: spring-projects/spring-framework
private Bootstrap buildBootstrap(URI uri, boolean isSecure) {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(this.eventLoopGroup).channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel channel) throws Exception {
configureChannel(channel.config());
ChannelPipeline pipeline = channel.pipeline();
if (isSecure) {
Assert.notNull(sslContext, "sslContext should not be null");
pipeline.addLast(sslContext.newHandler(channel.alloc(), uri.getHost(), uri.getPort()));
}
pipeline.addLast(new HttpClientCodec());
pipeline.addLast(new HttpObjectAggregator(maxResponseSize));
if (readTimeout > 0) {
pipeline.addLast(new ReadTimeoutHandler(readTimeout,
TimeUnit.MILLISECONDS));
}
}
});
return bootstrap;
}
代码示例来源:origin: apache/incubator-shardingsphere
private void groupsEpoll(final Bootstrap bootstrap) {
bootstrap.group(workerGroup)
.channel(EpollSocketChannel.class)
.option(EpollChannelOption.TCP_CORK, true)
.option(EpollChannelOption.SO_KEEPALIVE, true)
.option(EpollChannelOption.SO_BACKLOG, 128)
.option(EpollChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
}
代码示例来源:origin: testcontainers/testcontainers-java
public EventLoopGroup kqueueGroup() {
EventLoopGroup nioEventLoopGroup = new KQueueEventLoopGroup(0, createThreadFactory());
bootstrap.group(nioEventLoopGroup).channel(KQueueDomainSocketChannel.class)
.handler(new ChannelInitializer<KQueueDomainSocketChannel>() {
@Override
protected void initChannel(final KQueueDomainSocketChannel channel) throws Exception {
channel.pipeline().addLast(new HttpClientCodec());
channel.pipeline().addLast(new HttpContentDecompressor());
}
});
return nioEventLoopGroup;
}
代码示例来源:origin: mpusher/mpush
private void createClient(Listener listener, EventLoopGroup workerGroup, ChannelFactory<? extends Channel> channelFactory) {
this.workerGroup = workerGroup;
this.bootstrap = new Bootstrap();
bootstrap.group(workerGroup)//
.option(ChannelOption.SO_REUSEADDR, true)//
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)//
.channelFactory(channelFactory);
bootstrap.handler(new ChannelInitializer<Channel>() { // (4)
@Override
public void initChannel(Channel ch) throws Exception {
initPipeline(ch.pipeline());
}
});
initOptions(bootstrap);
listener.onSuccess();
}
代码示例来源:origin: eclipse-vertx/vert.x
AtomicReference<Thread> channelThread = new AtomicReference<>();
CountDownLatch connectLatch = new CountDownLatch(1);
Bootstrap bootstrap = new Bootstrap();
bootstrap.channelFactory(((VertxInternal)vertx).transport().channelFactory(false));
bootstrap.group(vertx.nettyEventLoopGroup());
bootstrap.resolver(((VertxInternal) vertx).nettyAddressResolverGroup());
bootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelFuture channelFut = bootstrap.connect("localhost", 1234);
awaitLatch(connectLatch);
channelFut.addListener(v -> {
代码示例来源:origin: testcontainers/testcontainers-java
@Override
public EventLoopGroup init(Bootstrap bootstrap, final DockerClientConfig dockerClientConfig) {
EventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(0, createThreadFactory());
// TODO do we really need BouncyCastle?
Security.addProvider(new BouncyCastleProvider());
ChannelFactory<NioSocketChannel> factory = () -> configure(new NioSocketChannel());
bootstrap.group(nioEventLoopGroup).channelFactory(factory)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(final SocketChannel channel) throws Exception {
channel.pipeline().addLast(new HttpClientCodec());
channel.pipeline().addLast(new HttpContentDecompressor());
}
});
return nioEventLoopGroup;
}
代码示例来源:origin: lettuce-io/lettuce-core
protected void channelType(ConnectionBuilder connectionBuilder, ConnectionPoint connectionPoint) {
LettuceAssert.notNull(connectionPoint, "ConnectionPoint must not be null");
connectionBuilder.bootstrap().group(getEventLoopGroup(connectionPoint));
if (connectionPoint.getSocket() != null) {
NativeTransports.assertAvailable();
connectionBuilder.bootstrap().channel(NativeTransports.domainSocketChannelClass());
} else {
connectionBuilder.bootstrap().channel(Transports.socketChannelClass());
}
}
代码示例来源:origin: fengjiachun/Jupiter
protected void init() {
ThreadFactory workerFactory = workerThreadFactory("jupiter.connector");
worker = initEventLoopGroup(nWorkers, workerFactory);
bootstrap = new Bootstrap().group(worker);
JConfig child = config();
child.setOption(JOption.IO_RATIO, 100);
doInit();
}
代码示例来源:origin: eclipse-vertx/vert.x
ContextInternal context = vertx.getOrCreateContext();
sslHelper.validate(vertx);
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(context.nettyEventLoop());
bootstrap.channelFactory(vertx.transport().channelFactory(remoteAddress.path() != null));
代码示例来源:origin: org.springframework/spring-web
private Bootstrap buildBootstrap(URI uri, boolean isSecure) {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(this.eventLoopGroup).channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel channel) throws Exception {
configureChannel(channel.config());
ChannelPipeline pipeline = channel.pipeline();
if (isSecure) {
Assert.notNull(sslContext, "sslContext should not be null");
pipeline.addLast(sslContext.newHandler(channel.alloc(), uri.getHost(), uri.getPort()));
}
pipeline.addLast(new HttpClientCodec());
pipeline.addLast(new HttpObjectAggregator(maxResponseSize));
if (readTimeout > 0) {
pipeline.addLast(new ReadTimeoutHandler(readTimeout,
TimeUnit.MILLISECONDS));
}
}
});
return bootstrap;
}
代码示例来源:origin: atomix/atomix
private CompletableFuture<Void> bootstrapServer() {
Bootstrap serverBootstrap = new Bootstrap()
.group(group)
.channelFactory(() -> new NioDatagramChannel(InternetProtocolFamily.IPv4))
.handler(new SimpleChannelInboundHandler<Object>() {
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
// Nothing will be sent.
}
})
.option(ChannelOption.IP_MULTICAST_IF, iface)
.option(ChannelOption.SO_REUSEADDR, true);
CompletableFuture<Void> future = new CompletableFuture<>();
serverBootstrap.bind(localAddress).addListener((ChannelFutureListener) f -> {
if (f.isSuccess()) {
serverChannel = f.channel();
future.complete(null);
} else {
future.completeExceptionally(f.cause());
}
});
return future;
}
代码示例来源:origin: linkedin/flashback
/**
* Establishing TCP connection to server
*
* @param remoteAddress remote address
* */
public ChannelFuture connectToServer(final InetSocketAddress remoteAddress) {
if (remoteAddress == null) {
throw new IllegalStateException("remote address is null");
}
Bootstrap bootstrap = new Bootstrap().group(_upstreamWorkerGroup);
bootstrap.channelFactory(NioSocketChannel::new);
ServerChannelHandler serverChannelHandler = new ServerChannelHandler(this);
bootstrap.handler(new ChannelInitializer<Channel>() {
protected void initChannel(Channel ch)
throws Exception {
initChannelPipeline(ch.pipeline(), serverChannelHandler, _serverConnectionIdleTimeoutMsec);
_serverChannel = ch;
}
});
LOG.debug("Server channel is ready. About to connect....");
return bootstrap.connect(remoteAddress);
}
代码示例来源:origin: apache/incubator-shardingsphere
private void groupsNio(final Bootstrap bootstrap) {
bootstrap.group(workerGroup)
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 100)
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
}
代码示例来源:origin: docker-java/docker-java
public EventLoopGroup kqueueGroup() {
EventLoopGroup nioEventLoopGroup = new KQueueEventLoopGroup(0, new DefaultThreadFactory(threadPrefix));
bootstrap.group(nioEventLoopGroup).channel(KQueueDomainSocketChannel.class)
.handler(new ChannelInitializer<KQueueDomainSocketChannel>() {
@Override
protected void initChannel(final KQueueDomainSocketChannel channel) throws Exception {
channel.pipeline().addLast(new LoggingHandler(getClass()));
channel.pipeline().addLast(new HttpClientCodec());
channel.pipeline().addLast(new HttpContentDecompressor());
}
});
return nioEventLoopGroup;
}
代码示例来源:origin: testcontainers/testcontainers-java
public EventLoopGroup epollGroup() {
EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup(0, createThreadFactory());
ChannelFactory<EpollDomainSocketChannel> factory = () -> configure(new EpollDomainSocketChannel());
bootstrap.group(epollEventLoopGroup).channelFactory(factory).handler(new ChannelInitializer<UnixChannel>() {
@Override
protected void initChannel(final UnixChannel channel) throws Exception {
channel.pipeline().addLast(new HttpClientCodec());
channel.pipeline().addLast(new HttpContentDecompressor());
}
});
return epollEventLoopGroup;
}
代码示例来源:origin: fengjiachun/Jupiter
protected void init() {
ThreadFactory workerFactory = workerThreadFactory("jupiter.connector");
worker = initEventLoopGroup(nWorkers, workerFactory);
bootstrap = new Bootstrap().group(worker);
JConfig child = config();
child.setOption(JOption.IO_RATIO, 100);
doInit();
}
代码示例来源:origin: blynkkk/blynk-server
public void start() {
Bootstrap b = new Bootstrap();
b.group(nioEventLoopGroup).channel(NioSocketChannel.class).handler(getChannelInitializer());
try {
// Start the connection attempt.
this.channel = b.connect(host, port).sync().channel();
} catch (InterruptedException e) {
log.error(e);
}
}
代码示例来源:origin: Graylog2/graylog2-server
@VisibleForTesting
Bootstrap getBootstrap(MessageInput input) {
LOG.debug("Setting UDP receive buffer size to {} bytes", getRecvBufferSize());
final NettyTransportType transportType = nettyTransportConfiguration.getType();
eventLoopGroup = eventLoopGroupFactory.create(workerThreads, localRegistry, "workers");
return new Bootstrap()
.group(eventLoopGroup)
.channelFactory(new DatagramChannelFactory(transportType))
.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(getRecvBufferSize()))
.option(ChannelOption.SO_RCVBUF, getRecvBufferSize())
.option(UnixChannelOption.SO_REUSEPORT, true)
.handler(getChannelInitializer(getChannelHandlers(input)))
.validate();
}
代码示例来源:origin: io.vertx/vertx-core
AtomicReference<Thread> channelThread = new AtomicReference<>();
CountDownLatch connectLatch = new CountDownLatch(1);
Bootstrap bootstrap = new Bootstrap();
bootstrap.channelFactory(((VertxInternal)vertx).transport().channelFactory(false));
bootstrap.group(vertx.nettyEventLoopGroup());
bootstrap.resolver(((VertxInternal) vertx).nettyAddressResolverGroup());
bootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelFuture channelFut = bootstrap.connect("localhost", 1234);
awaitLatch(connectLatch);
channelFut.addListener(v -> {
代码示例来源:origin: apache/incubator-shardingsphere
private void groupsEpoll(final Bootstrap bootstrap) {
bootstrap.group(workerGroup)
.channel(EpollSocketChannel.class)
.option(EpollChannelOption.TCP_CORK, true)
.option(EpollChannelOption.SO_KEEPALIVE, true)
.option(EpollChannelOption.SO_BACKLOG, 128)
.option(EpollChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
}
内容来源于网络,如有侵权,请联系作者删除!