當前位置: 首頁>>代碼示例>>Java>>正文


Java ServerBootstrap類代碼示例

本文整理匯總了Java中org.jboss.netty.bootstrap.ServerBootstrap的典型用法代碼示例。如果您正苦於以下問題:Java ServerBootstrap類的具體用法?Java ServerBootstrap怎麽用?Java ServerBootstrap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ServerBootstrap類屬於org.jboss.netty.bootstrap包,在下文中一共展示了ServerBootstrap類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的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);
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:24,代碼來源:Controller.java

示例2: main

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的package包/類
public static void main(String[] args) {
    // Server服務啟動器
    ServerBootstrap bootstrap = new ServerBootstrap(
            new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool()));
    // 設置一個處理客戶端消息和各種消息事件的類(Handler)
    bootstrap
            .setPipelineFactory(new ChannelPipelineFactory() {
                @Override
                public ChannelPipeline getPipeline()
                        throws Exception {
                    return Channels
                            .pipeline(new HelloServerHandler());
                }
            });
    // 開放8000端口供客戶端訪問。
    bootstrap.bind(new InetSocketAddress(8000));
}
 
開發者ID:lihengming,項目名稱:java-codes,代碼行數:20,代碼來源:NettyTest.java

示例3: run

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的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, sslContext);
        bootstrap.setPipelineFactory(pfact);
        cg = new DefaultChannelGroup();
        openFlowPorts.forEach(port -> {
            InetSocketAddress sa = new InetSocketAddress(port);
            cg.add(bootstrap.bind(sa));
            log.info("Listening for switch connections on {}", sa);
        });

    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:29,代碼來源:Controller.java

示例4: initTrackerServers

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的package包/類
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new CellocatorFrameDecoder());
            pipeline.addLast("objectEncoder", new CellocatorProtocolEncoder());
            pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);

    server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("objectEncoder", new CellocatorProtocolEncoder());
            pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:24,代碼來源:CellocatorProtocol.java

示例5: initTrackerServers

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的package包/類
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            boolean full = Context.getConfig().getBoolean(getName() + ".extended");
            if (full) {
                pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); // tracker bug \n\r
            } else {
                pipeline.addLast("frameDecoder", new XexunFrameDecoder());
            }
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("stringDecoder", new StringDecoder());
            pipeline.addLast("objectEncoder", new XexunProtocolEncoder());
            pipeline.addLast("objectDecoder", new XexunProtocolDecoder(XexunProtocol.this, full));
        }
    });
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:19,代碼來源:XexunProtocol.java

示例6: startHttpServer

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的package包/類
private ServerBootstrap startHttpServer(int port,
    final Token<DelegationTokenIdentifier> token, final URI url) {
  ServerBootstrap bootstrap = new ServerBootstrap(
      new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
          Executors.newCachedThreadPool()));

  bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
    @Override
    public ChannelPipeline getPipeline() throws Exception {
      return Channels.pipeline(new HttpRequestDecoder(),
          new HttpChunkAggregator(65536), new HttpResponseEncoder(),
          new CredentialsLogicHandler(token, url.toString()));
    }
  });
  bootstrap.bind(new InetSocketAddress("localhost", port));
  return bootstrap;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestDelegationTokenRemoteFetcher.java

示例7: bootstrapNetty

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的package包/類
/**
 * Bootstraps netty, the server that handles all openflow connections
 */
public void bootstrapNetty() {
	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 = useSsl ? new OpenflowPipelineFactory(this, floodlightProvider.getTimer(), this, debugCounterService, keyStore, keyStorePassword) :
			new OpenflowPipelineFactory(this, floodlightProvider.getTimer(), this, debugCounterService);

		bootstrap.setPipelineFactory(pfact);
		InetSocketAddress sa = new InetSocketAddress(floodlightProvider.getOFPort());
		final ChannelGroup cg = new DefaultChannelGroup();
		cg.add(bootstrap.bind(sa));

		log.info("Listening for switch connections on {}", sa);
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:26,代碼來源:OFSwitchManager.java

示例8: initTrackerServers

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的package包/類
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new MeitrackFrameDecoder());
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("objectEncoder", new MeitrackProtocolEncoder());
            pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(MeitrackProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
    server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("objectEncoder", new MeitrackProtocolEncoder());
            pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(MeitrackProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:25,代碼來源:MeitrackProtocol.java

示例9: start

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的package包/類
@Override
public void start() throws KairosDBException
{
	// Configure the server.
	serverBootstrap = new ServerBootstrap(
			new NioServerSocketChannelFactory(
					Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("telnet-boss-%d").build()),
					Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("telnet-worker-%d").build())));

	// Configure the pipeline factory.
	serverBootstrap.setPipelineFactory(this);
	serverBootstrap.setOption("child.tcpNoDelay", true);
	serverBootstrap.setOption("child.keepAlive", true);
	serverBootstrap.setOption("reuseAddress", true);

	// Bind and start to accept incoming connections.
	serverBootstrap.bind(new InetSocketAddress(address, port));
}
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:19,代碼來源:TelnetServer.java

示例10: initTrackerServers

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的package包/類
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(4 * 1024));
            pipeline.addLast("stringEncoder", new StringEncoder());
            boolean utf8 = Context.getConfig().getBoolean(getName() + ".utf8");
            if (utf8) {
                pipeline.addLast("stringDecoder", new StringDecoder(StandardCharsets.UTF_8));
            } else {
                pipeline.addLast("stringDecoder", new StringDecoder());
            }
            pipeline.addLast("objectEncoder", new WialonProtocolEncoder());
            pipeline.addLast("objectDecoder", new WialonProtocolDecoder(WialonProtocol.this));
        }
    });
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:19,代碼來源:WialonProtocol.java

示例11: initTrackerServers

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的package包/類
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0));
            pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);

    server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:22,代碼來源:CastelProtocol.java

示例12: doOpen

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的package包/類
@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerBoss", true));
    ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerWorker", true));
    ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS));
    bootstrap = new ServerBootstrap(channelFactory);
    
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    channels = nettyHandler.getChannels();
    // https://issues.jboss.org/browse/NETTY-365
    // https://issues.jboss.org/browse/NETTY-379
    // final Timer timer = new HashedWheelTimer(new NamedThreadFactory("NettyIdleTimer", true));
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec() ,getUrl(), NettyServer.this);
            ChannelPipeline pipeline = Channels.pipeline();
            /*int idleTimeout = getIdleTimeout();
            if (idleTimeout > 10000) {
                pipeline.addLast("timer", new IdleStateHandler(timer, idleTimeout / 1000, 0, 0));
            }*/
            pipeline.addLast("decoder", adapter.getDecoder());
            pipeline.addLast("encoder", adapter.getEncoder());
            pipeline.addLast("handler", nettyHandler);
            return pipeline;
        }
    });
    // bind
    channel = bootstrap.bind(getBindAddress());
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:31,代碼來源:NettyServer.java

示例13: NettyServerCnxnFactory

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的package包/類
NettyServerCnxnFactory() {
    bootstrap = new ServerBootstrap(
            new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool()));
    // parent channel
    bootstrap.setOption("reuseAddress", true);
    // child channels
    bootstrap.setOption("child.tcpNoDelay", true);
    /* set socket linger to off, so that socket close does not block */
    bootstrap.setOption("child.soLinger", -1);

    bootstrap.getPipeline().addLast("servercnxnfactory", channelHandler);
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:15,代碼來源:NettyServerCnxnFactory.java

示例14: run

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的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);
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:34,代碼來源:Controller.java

示例15: initTrackerServers

import org.jboss.netty.bootstrap.ServerBootstrap; //導入依賴的package包/類
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("httpEncoder", new HttpResponseEncoder());
            pipeline.addLast("httpDecoder", new HttpRequestDecoder());
            pipeline.addLast("httpAggregator", new HttpChunkAggregator(16384));
            pipeline.addLast("objectDecoder", new PiligrimProtocolDecoder(PiligrimProtocol.this));
        }
    });
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:13,代碼來源:PiligrimProtocol.java


注:本文中的org.jboss.netty.bootstrap.ServerBootstrap類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。