@Override public ServerBootstrap validate() { super.validate(); if (childHandler == null) { throw new IllegalStateException("childHandler not set"); } if (childGroup == null) { logger.warn("childGroup is not set. Using parentGroup instead."); childGroup = config.group(); } return this; }
@Override public void shutdown() { channel.close(); bootstrap.config().group().shutdownGracefully(); bootstrap.config().childGroup().shutdownGracefully(); try { bootstrap.config().group().terminationFuture().sync(); bootstrap.config().childGroup().terminationFuture().sync(); } catch (InterruptedException e) { GlowServer.logger.log(Level.SEVERE, "Socket server shutdown process interrupted!", e); } } }
buf.setLength(buf.length() - 1); buf.append(", "); EventLoopGroup childGroup = childGroup(); if (childGroup != null) { buf.append("childGroup: "); buf.append(", "); Map<ChannelOption<?>, Object> childOptions = childOptions(); if (!childOptions.isEmpty()) { buf.append("childOptions: "); buf.append(", "); Map<AttributeKey<?>, Object> childAttrs = childAttrs(); if (!childAttrs.isEmpty()) { buf.append("childAttrs: "); buf.append(", "); ChannelHandler childHandler = childHandler(); if (childHandler != null) { buf.append("childHandler: ");
/** * 动态添加aesToken * * @param aesToken * @return */ public boolean addAesToken(AesToken aesToken) { if (bootstrap == null) { return false; } ServerBootstrapConfig c = bootstrap.config(); ((WeixinServerInitializer) c.childHandler()).addAesToken(aesToken); return true; }
@Override public void initChannel(final Channel ch) throws Exception { final ChannelPipeline pipeline = ch.pipeline(); ChannelHandler handler = config.handler(); if (handler != null) { pipeline.addLast(handler); } ch.eventLoop().execute(new Runnable() { @Override public void run() { pipeline.addLast(new ServerBootstrapAcceptor( ch, currentChildGroup, currentChildHandler, currentChildOptions, currentChildAttrs)); } }); } });
/** * Obtain and remove the current childHandler {@link ConnectionObserver} from the * bootstrap. * * @param b the bootstrap to scan * * @return current {@link ConnectionObserver} or null * */ @SuppressWarnings("unchecked") public static ConnectionObserver childConnectionObserver(ServerBootstrap b) { Objects.requireNonNull(b, "bootstrap"); ConnectionObserver obs = (ConnectionObserver) b.config() .childOptions() .get(OBSERVER_OPTION); b.childOption(OBSERVER_OPTION, null); if (obs == null) { return ConnectionObserver.emptyListener(); //will not be triggered in } return obs; }
/** * Remove a configuration given its unique name from the given {@link * ServerBootstrap} * * @param b a server bootstrap * @param name a configuration name */ public static ServerBootstrap removeConfiguration(ServerBootstrap b, String name) { Objects.requireNonNull(b, "bootstrap"); Objects.requireNonNull(name, "name"); b.childHandler(removeConfiguration(b.config().childHandler(), name)); return b; }
@Override public void initChannel(final Channel ch) throws Exception { final ChannelPipeline pipeline = ch.pipeline(); ChannelHandler handler = config.handler(); if (handler != null) { pipeline.addLast(handler); } ch.eventLoop().execute(new Runnable() { @Override public void run() { pipeline.addLast(new ServerBootstrapAcceptor( ch, currentChildGroup, currentChildHandler, currentChildOptions, currentChildAttrs)); } }); } });
/** * Obtain and remove the current childHandler {@link ConnectionObserver} from the * bootstrap. * * @param b the bootstrap to scan * * @return current {@link ConnectionObserver} or null * */ @SuppressWarnings("unchecked") public static ConnectionObserver childConnectionObserver(ServerBootstrap b) { Objects.requireNonNull(b, "bootstrap"); ConnectionObserver obs = (ConnectionObserver) b.config() .childOptions() .get(OBSERVER_OPTION); b.childOption(OBSERVER_OPTION, null); if (obs == null) { return ConnectionObserver.emptyListener(); //will not be triggered in } return obs; }
@Override public ServerBootstrap validate() { super.validate(); if (childHandler == null) { throw new IllegalStateException("childHandler not set"); } if (childGroup == null) { logger.warn("childGroup is not set. Using parentGroup instead."); childGroup = config.group(); } return this; }
final EventLoopGroup bossGroup = bootstrap.config().group(); final EventLoopGroup workerGroup = bootstrap.config().childGroup();
buf.setLength(buf.length() - 1); buf.append(", "); EventLoopGroup childGroup = childGroup(); if (childGroup != null) { buf.append("childGroup: "); buf.append(", "); Map<ChannelOption<?>, Object> childOptions = childOptions(); if (!childOptions.isEmpty()) { buf.append("childOptions: "); buf.append(", "); Map<AttributeKey<?>, Object> childAttrs = childAttrs(); if (!childAttrs.isEmpty()) { buf.append("childAttrs: "); buf.append(", "); ChannelHandler childHandler = childHandler(); if (childHandler != null) { buf.append("childHandler: ");
/** * Remove a configuration given its unique name from the given {@link * ServerBootstrap} * * @param b a server bootstrap * @param name a configuration name */ public static ServerBootstrap removeConfiguration(ServerBootstrap b, String name) { Objects.requireNonNull(b, "bootstrap"); Objects.requireNonNull(name, "name"); b.childHandler(removeConfiguration(b.config().childHandler(), name)); return b; }
@Override public void initChannel(final Channel ch) throws Exception { final ChannelPipeline pipeline = ch.pipeline(); ChannelHandler handler = config.handler(); if (handler != null) { pipeline.addLast(handler); } ch.eventLoop().execute(new Runnable() { @Override public void run() { pipeline.addLast(new ServerBootstrapAcceptor( ch, currentChildGroup, currentChildHandler, currentChildOptions, currentChildAttrs)); } }); } });
@Override public void operationComplete(final Future<Void> future) throws Exception { BaseHttp2Server.this.bootstrap.config().group().shutdownGracefully(); } });
/** * 关闭微信服务 * * @param blocking * 阻塞关闭 * @return */ public boolean shutdown(boolean blocking) { if (bootstrap == null) { return false; } ServerBootstrapConfig c = bootstrap.config(); Future<?> bossF = c.group().shutdownGracefully(); Future<?> workerF = c.childGroup().shutdownGracefully(); if (blocking) { bossF.awaitUninterruptibly(); workerF.awaitUninterruptibly(); } messageHandlerList = null; messageInterceptorList = null; messageDispatcher = null; bootstrap = null; return true; }
buf.setLength(buf.length() - 1); buf.append(", "); EventLoopGroup childGroup = childGroup(); if (childGroup != null) { buf.append("childGroup: "); buf.append(", "); Map<ChannelOption<?>, Object> childOptions = childOptions(); if (!childOptions.isEmpty()) { buf.append("childOptions: "); buf.append(", "); Map<AttributeKey<?>, Object> childAttrs = childAttrs(); if (!childAttrs.isEmpty()) { buf.append("childAttrs: "); buf.append(", "); ChannelHandler childHandler = childHandler(); if (childHandler != null) { buf.append("childHandler: ");
/** * Add the configuration consumer to this {@link ServerBootstrap} given a unique * configuration name. Configuration will be run on child channel init. * * @param b a server bootstrap * @param name a configuration name * @param c a configuration consumer * @return the mutated bootstrap */ public static ServerBootstrap updateConfiguration(ServerBootstrap b, String name, BiConsumer<ConnectionObserver, ? super Channel> c) { Objects.requireNonNull(b, "bootstrap"); Objects.requireNonNull(name, "name"); Objects.requireNonNull(c, "configuration"); b.childHandler(updateConfiguration(b.config().childHandler(), name, c)); return b; }
@Override public void initChannel(final Channel ch) throws Exception { final ChannelPipeline pipeline = ch.pipeline(); ChannelHandler handler = config.handler(); if (handler != null) { pipeline.addLast(handler); } ch.eventLoop().execute(new Runnable() { @Override public void run() { pipeline.addLast(new ServerBootstrapAcceptor( ch, currentChildGroup, currentChildHandler, currentChildOptions, currentChildAttrs)); } }); } });
@Override public ServerBootstrap validate() { super.validate(); if (childHandler == null) { throw new IllegalStateException("childHandler not set"); } if (childGroup == null) { logger.warn("childGroup is not set. Using parentGroup instead."); childGroup = config.group(); } return this; }