本文整理汇总了Java中io.netty.channel.socket.ServerSocketChannel类的典型用法代码示例。如果您正苦于以下问题:Java ServerSocketChannel类的具体用法?Java ServerSocketChannel怎么用?Java ServerSocketChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerSocketChannel类属于io.netty.channel.socket包,在下文中一共展示了ServerSocketChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bind
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
/**
* 启动端口绑定
* @param local
* @return
*/
protected final boolean bind(InetSocketAddress local)
{
boolean isBind=false;
try {
log.debug(getName()+"端口绑定中……"+local.toString());
ChannelFuture cf=doBind(local);
isBind=cf.channel()!=null && cf.channel().isActive();
if(isBind)
{
log.debug(getName()+"端口绑定成功!"+cf.channel());
serverCahnel=(ServerSocketChannel) cf.channel();
}else
{
log.debug(getName()+"端口绑定失败!"+cf.channel());
}
} catch (Exception e) {
log.error(e.getMessage(),e);
throw e;
}
return isBind;
}
示例2: init
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
@Override
public void init(final InetAddress address, final int port, final boolean useEpoll)
{
final Class<? extends ServerSocketChannel> socketChannelClass;
final LazyValue<? extends EventLoopGroup> lazyInit;
if ((Epoll.isAvailable()) && useEpoll)
{
socketChannelClass = EpollServerSocketChannel.class;
lazyInit = this.epollEventLoopGroupLazyValue;
CoreMain.debug("[Netty] Using epoll channel type");
}
else
{
socketChannelClass = NioServerSocketChannel.class;
lazyInit = this.nioEventLoopGroupLazyValue;
CoreMain.debug("[Netty] Using default channel type");
}
this.channelFuture = new ServerBootstrap().channel(socketChannelClass).childHandler(new ServerConnectionChannel(this)).group(lazyInit.get()).localAddress(address, port).bind().syncUninterruptibly();
}
示例3: startServer
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
protected void startServer() throws InterruptedException {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new LoggingHandler(LogLevel.DEBUG));
p.addLast(new NettySimpleMessageHandler());
p.addLast(new NettyMasterHandler(DefaultRedisKeeperServer.this, new CommandHandlerManager(), keeperConfig.getTrafficReportIntervalMillis()));
}
});
serverSocketChannel = (ServerSocketChannel) b.bind(currentKeeperMeta.getPort()).sync().channel();
}
示例4: ClassLoaderServer
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
public ClassLoaderServer(ClassLoader classLoader) throws UnknownHostException, InterruptedException {
String codeBase = System.getProperty("java.rmi.server.codebase", null);
if (codeBase == null || codeBase.matches("[0-9]+")) {
Transport transport = Modules.getInstance().getTransport();
int port = (codeBase == null) ? 0 : Integer.valueOf(codeBase);
httpChannel = ClassLoaderServer.run(transport.getAcceptGroup(), transport.getWorkerGroup(), port, classLoader);
InetSocketAddress inetSocketAddress = ((ServerSocketChannel) httpChannel).localAddress();
port = inetSocketAddress.getPort();
String hostName = Modules.getInstance().getConfiguration().getServerHostName();
if(hostName == null){
hostName = InetAddress.getLocalHost().getHostName();
}
System.setProperty("java.rmi.server.codebase", "http://" + hostName + ":" + port + "/");
LoaderHandler.loadCodeBaseProperty();
logger.info("Embedded HTTP server run at {} java.rmi.server.codebase is set to {} ", inetSocketAddress, System.getProperty("java.rmi.server.codebase"));
} else {
httpChannel = null;
}
}
示例5: RpcServer
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的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);
}
示例6: getServerSocketChannel
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
public static Class<? extends ServerSocketChannel> getServerSocketChannel(){
if(SUPPORTS_EPOLL){
return EpollServerSocketChannel.class;
}else{
return NioServerSocketChannel.class;
}
}
示例7: getServerSocketChannelClass
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
public static Class<? extends ServerSocketChannel> getServerSocketChannelClass(EventLoopGroup eventLoopGroup) {
if (eventLoopGroup instanceof EpollEventLoopGroup) {
return EpollServerSocketChannel.class;
} else {
return NioServerSocketChannel.class;
}
}
示例8: address
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
/**
* Return remote address if remote channel {@link NettyContext} otherwise local
* address if server selector channel.
*
* @return remote or local {@link InetSocketAddress}
*/
default InetSocketAddress address(){
Channel c = channel();
if (c instanceof SocketChannel) {
return ((SocketChannel) c).remoteAddress();
}
if (c instanceof ServerSocketChannel) {
return ((ServerSocketChannel) c).localAddress();
}
if (c instanceof DatagramChannel) {
InetSocketAddress a = ((DatagramChannel) c).remoteAddress();
return a != null ? a : ((DatagramChannel)c ).localAddress();
}
throw new IllegalStateException("Does not have an InetSocketAddress");
}
示例9: HttpServer
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
HttpServer(Supplier<EventLoopGroup> eventLoopFactory,
ServerChannelFactory<ServerSocketChannel> channelFactory,
ChannelInitializer channelInitializer,
HttpEventBus eventBus) {
super(eventLoopFactory, channelFactory, channelInitializer);
this.eventBus = eventBus;
}
示例10: Server
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
public Server(Supplier<EventLoopGroup> eventLoopFactory,
ServerChannelFactory<ServerSocketChannel> channelFactory,
ChannelInitializer channelInitializer) {
this.bossGroup = eventLoopFactory.get();
this.workerGroup = eventLoopFactory.get();
serverBootstrap = new ServerBootstrap()
.group(bossGroup, workerGroup)
.channelFactory(channelFactory)
.childHandler(channelInitializer);
}
示例11: isCompatible
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
@Override
protected boolean isCompatible(EventLoop loop) {
if (!(loop instanceof XnioEventLoop)) {
return false;
}
ServerSocketChannel parent = parent();
if (parent != null) {
// if this channel has a parent we need to ensure that both EventLoopGroups are the same for XNIO
// to be sure it uses a Thread from the correct Worker.
if (parent.eventLoop().parent() != loop.parent()) {
return false;
}
}
return true;
}
示例12: serverSocketChannel
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
public static Class<? extends ServerSocketChannel> serverSocketChannel()
{
return EPOLL ? EpollServerSocketChannel.class : NioServerSocketChannel.class;
}
示例13: addLanEndpoint
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
/**
* Adds a channel that listens on publicly accessible network ports
*/
public void addLanEndpoint(InetAddress address, int port) throws IOException
{
synchronized (this.endpoints)
{
Class <? extends ServerSocketChannel > oclass;
LazyLoadBase <? extends EventLoopGroup > lazyloadbase;
if (Epoll.isAvailable() && this.mcServer.func_181035_ah())
{
oclass = EpollServerSocketChannel.class;
lazyloadbase = field_181141_b;
logger.info("Using epoll channel type");
}
else
{
oclass = NioServerSocketChannel.class;
lazyloadbase = eventLoops;
logger.info("Using default channel type");
}
this.endpoints.add(((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(oclass)).childHandler(new ChannelInitializer<Channel>()
{
protected void initChannel(Channel p_initChannel_1_) throws Exception
{
try
{
p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
}
catch (ChannelException var3)
{
;
}
p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"legacy_query", (ChannelHandler)(new PingResponseHandler(NetworkSystem.this))).addLast((String)"splitter", (ChannelHandler)(new MessageDeserializer2())).addLast((String)"decoder", (ChannelHandler)(new MessageDeserializer(EnumPacketDirection.SERVERBOUND))).addLast((String)"prepender", (ChannelHandler)(new MessageSerializer2())).addLast((String)"encoder", (ChannelHandler)(new MessageSerializer(EnumPacketDirection.CLIENTBOUND)));
NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.SERVERBOUND);
NetworkSystem.this.networkManagers.add(networkmanager);
p_initChannel_1_.pipeline().addLast((String)"packet_handler", (ChannelHandler)networkmanager);
networkmanager.setNetHandler(new NetHandlerHandshakeTCP(NetworkSystem.this.mcServer, networkmanager));
}
}).group((EventLoopGroup)lazyloadbase.getValue()).localAddress(address, port)).bind().syncUninterruptibly());
}
}
示例14: addLanEndpoint
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
/**
* Adds a channel that listens on publicly accessible network ports
*/
public void addLanEndpoint(InetAddress address, int port) throws IOException
{
synchronized (this.endpoints)
{
Class <? extends ServerSocketChannel > oclass;
LazyLoadBase <? extends EventLoopGroup > lazyloadbase;
if (Epoll.isAvailable() && this.mcServer.shouldUseNativeTransport())
{
oclass = EpollServerSocketChannel.class;
lazyloadbase = SERVER_EPOLL_EVENTLOOP;
LOGGER.info("Using epoll channel type");
}
else
{
oclass = NioServerSocketChannel.class;
lazyloadbase = SERVER_NIO_EVENTLOOP;
LOGGER.info("Using default channel type");
}
this.endpoints.add(((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(oclass)).childHandler(new ChannelInitializer<Channel>()
{
protected void initChannel(Channel p_initChannel_1_) throws Exception
{
try
{
p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
}
catch (ChannelException var3)
{
;
}
p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"legacy_query", (ChannelHandler)(new LegacyPingHandler(NetworkSystem.this))).addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.CLIENTBOUND)));
NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.SERVERBOUND);
NetworkSystem.this.networkManagers.add(networkmanager);
p_initChannel_1_.pipeline().addLast((String)"packet_handler", (ChannelHandler)networkmanager);
networkmanager.setNetHandler(new NetHandlerHandshakeTCP(NetworkSystem.this.mcServer, networkmanager));
}
}).group((EventLoopGroup)lazyloadbase.getValue()).localAddress(address, port)).bind().syncUninterruptibly());
}
}
示例15: addLanEndpoint
import io.netty.channel.socket.ServerSocketChannel; //导入依赖的package包/类
/**
* Adds a channel that listens on publicly accessible network ports
*/
public void addLanEndpoint(InetAddress address, int port) throws IOException
{
synchronized (this.endpoints)
{
Class <? extends ServerSocketChannel > oclass;
LazyLoadBase <? extends EventLoopGroup > lazyloadbase;
if (Epoll.isAvailable() && this.mcServer.shouldUseNativeTransport())
{
oclass = EpollServerSocketChannel.class;
lazyloadbase = SERVER_EPOLL_EVENTLOOP;
LOGGER.info("Using epoll channel type");
}
else
{
oclass = NioServerSocketChannel.class;
lazyloadbase = SERVER_NIO_EVENTLOOP;
LOGGER.info("Using default channel type");
}
this.endpoints.add(((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(oclass)).childHandler(new ChannelInitializer<Channel>()
{
protected void initChannel(Channel p_initChannel_1_) throws Exception
{
try
{
p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
}
catch (ChannelException var3)
{
;
}
p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.READ_TIMEOUT))).addLast((String)"legacy_query", (ChannelHandler)(new LegacyPingHandler(NetworkSystem.this))).addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.CLIENTBOUND)));
NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.SERVERBOUND);
NetworkSystem.this.networkManagers.add(networkmanager);
p_initChannel_1_.pipeline().addLast((String)"packet_handler", (ChannelHandler)networkmanager);
networkmanager.setNetHandler(new NetHandlerHandshakeTCP(NetworkSystem.this.mcServer, networkmanager));
}
}).group((EventLoopGroup)lazyloadbase.getValue()).localAddress(address, port)).bind().syncUninterruptibly());
}
}