Java Code Examples for org.jboss.netty.channel.group.DefaultChannelGroup

The following are top voted examples for showing how to use org.jboss.netty.channel.group.DefaultChannelGroup. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: athena   File: Controller.java   Source Code and License 7 votes vote down vote up
/**
 * 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);
    }
}
 
Example 2
Project: athena   File: Controller.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
    }

}
 
Example 3
Project: iTAP-controller   File: Bootstrap.java   Source Code and License 6 votes vote down vote up
public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap");

    bossExecutor = Executors.newCachedThreadPool();
    workerExecutor = Executors.newCachedThreadPool();

    bootstrap =
            new ClientBootstrap(new NioClientSocketChannelFactory(bossExecutor,
                                                                  workerExecutor));
    bootstrap.setOption("child.reuseAddr", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.sendBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.receiveBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.connectTimeoutMillis", 
                        RPCService.CONNECT_TIMEOUT);
    pipelineFactory = new BootstrapPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);
}
 
Example 4
Project: iTAP-controller   File: OFSwitchManager.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 5
Project: QoS-floodlight   File: Bootstrap.java   Source Code and License 6 votes vote down vote up
public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap");

    bossExecutor = Executors.newCachedThreadPool();
    workerExecutor = Executors.newCachedThreadPool();

    bootstrap =
            new ClientBootstrap(new NioClientSocketChannelFactory(bossExecutor,
                                                                  workerExecutor));
    bootstrap.setOption("child.reuseAddr", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.sendBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.receiveBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.connectTimeoutMillis", 
                        RPCService.CONNECT_TIMEOUT);
    pipelineFactory = new BootstrapPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);
}
 
Example 6
Project: incubator-omid   File: ProgrammableTSOServer.java   Source Code and License 6 votes vote down vote up
@Inject
public ProgrammableTSOServer(int port) {
    // Setup netty listener
    factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(new ThreadFactoryBuilder()
            .setNameFormat("boss-%d").build()), Executors.newCachedThreadPool(new ThreadFactoryBuilder()
            .setNameFormat("worker-%d").build()), (Runtime.getRuntime().availableProcessors() * 2 + 1) * 2);

    // Create the global ChannelGroup
    channelGroup = new DefaultChannelGroup(ProgrammableTSOServer.class.getName());

    ServerBootstrap bootstrap = new ServerBootstrap(factory);
    bootstrap.setPipelineFactory(new TSOChannelHandler.TSOPipelineFactory(this));

    // Add the parent channel to the group
    Channel channel = bootstrap.bind(new InetSocketAddress(port));
    channelGroup.add(channel);

    LOG.info("********** Dumb TSO Server running on port {} **********", port);
}
 
Example 7
Project: fast-failover-demo   File: Bootstrap.java   Source Code and License 6 votes vote down vote up
public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap");

    bossExecutor = Executors.newCachedThreadPool();
    workerExecutor = Executors.newCachedThreadPool();

    bootstrap =
            new ClientBootstrap(new NioClientSocketChannelFactory(bossExecutor,
                                                                  workerExecutor));
    bootstrap.setOption("child.reuseAddr", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.sendBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.receiveBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.connectTimeoutMillis", 
                        RPCService.CONNECT_TIMEOUT);
    pipelineFactory = new BootstrapPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);
}
 
Example 8
Project: fast-failover-demo   File: OFSwitchManager.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 9
Project: ravikumaran201504   File: Controller.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
        bootstrap.setPipelineFactory(pfact);
        InetSocketAddress sa = new InetSocketAddress(openFlowPort);
        cg = new DefaultChannelGroup();
        cg.add(bootstrap.bind(sa));

        log.info("Listening for switch connections on {}", sa);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}
 
Example 10
Project: floodlightLB   File: Bootstrap.java   Source Code and License 6 votes vote down vote up
public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap");

    bossExecutor = Executors.newCachedThreadPool();
    workerExecutor = Executors.newCachedThreadPool();

    bootstrap =
            new ClientBootstrap(new NioClientSocketChannelFactory(bossExecutor,
                                                                  workerExecutor));
    bootstrap.setOption("child.reuseAddr", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.sendBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.receiveBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.connectTimeoutMillis", 
                        RPCService.CONNECT_TIMEOUT);
    pipelineFactory = new BootstrapPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);
}
 
Example 11
Project: floodlightLB   File: OFSwitchManager.java   Source Code and License 6 votes vote down vote up
/**
 * 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, ofBitmaps, defaultFactory, keyStore, keyStorePassword) :
			new OpenflowPipelineFactory(this, floodlightProvider.getTimer(), this, debugCounterService, ofBitmaps, defaultFactory);
		
		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);
	}
}
 
Example 12
Project: DSC   File: Bootstrap.java   Source Code and License 6 votes vote down vote up
public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap");

    bossExecutor = Executors.newCachedThreadPool();
    workerExecutor = Executors.newCachedThreadPool();

    bootstrap =
            new ClientBootstrap(new NioClientSocketChannelFactory(bossExecutor,
                                                                  workerExecutor));
    bootstrap.setOption("child.reuseAddr", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.sendBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.receiveBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.connectTimeoutMillis", 
                        RPCService.CONNECT_TIMEOUT);
    pipelineFactory = new BootstrapPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);
}
 
Example 13
Project: DSC   File: OFSwitchManager.java   Source Code and License 6 votes vote down vote up
/**
 * Bootstraps netty, the server that handles all openflow connections
 * 启动netty,处理所有OF连接
 */
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);
	}
}
 
Example 14
Project: floodlight_with_topoguard   File: Bootstrap.java   Source Code and License 6 votes vote down vote up
public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap");

    bossExecutor = Executors.newCachedThreadPool();
    workerExecutor = Executors.newCachedThreadPool();

    bootstrap =
            new ClientBootstrap(new NioClientSocketChannelFactory(bossExecutor,
                                                                  workerExecutor));
    bootstrap.setOption("child.reuseAddr", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.sendBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.receiveBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.connectTimeoutMillis", 
                        RPCService.CONNECT_TIMEOUT);
    pipelineFactory = new BootstrapPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);
}
 
Example 15
Project: floodlight   File: Bootstrap.java   Source Code and License 6 votes vote down vote up
public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap");

    bossExecutor = Executors.newCachedThreadPool();
    workerExecutor = Executors.newCachedThreadPool();

    bootstrap =
            new ClientBootstrap(new NioClientSocketChannelFactory(bossExecutor,
                                                                  workerExecutor));
    bootstrap.setOption("child.reuseAddr", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.sendBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.receiveBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.connectTimeoutMillis", 
                        RPCService.CONNECT_TIMEOUT);
    pipelineFactory = new BootstrapPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);
}
 
Example 16
Project: floodlight   File: OFSwitchManager.java   Source Code and License 6 votes vote down vote up
/**
 * 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 =
				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);
	}
}
 
Example 17
Project: tightrope   File: LoadBalancer.java   Source Code and License 6 votes vote down vote up
public synchronized void start() {
    final Executor bossPool = Executors.newCachedThreadPool();
    final Executor workerPool = Executors.newCachedThreadPool();
    bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(bossPool, workerPool));
    final ClientSocketChannelFactory clientSocketChannelFactory = new NioClientSocketChannelFactory(bossPool, workerPool);
    bootstrap.setOption("child.tcpNoDelay", true);
    allChannels = new DefaultChannelGroup("handler");

    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new FrontendHandler(allChannels, clientSocketChannelFactory, serverPool, statistics));
        }
    });

    log.info("Starting on port {}", port);
    acceptor = bootstrap.bind(new InetSocketAddress(port));

    if (acceptor.isBound()) {
        log.info("Server started successfully");
    }
}
 
Example 18
Project: FloodligtModule   File: Bootstrap.java   Source Code and License 6 votes vote down vote up
public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap");

    bossExecutor = Executors.newCachedThreadPool();
    workerExecutor = Executors.newCachedThreadPool();

    bootstrap =
            new ClientBootstrap(new NioClientSocketChannelFactory(bossExecutor,
                                                                  workerExecutor));
    bootstrap.setOption("child.reuseAddr", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.sendBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.receiveBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.connectTimeoutMillis", 
                        RPCService.CONNECT_TIMEOUT);
    pipelineFactory = new BootstrapPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);
}
 
Example 19
Project: pinpoint   File: HealthCheckManagerTest.java   Source Code and License 6 votes vote down vote up
@Test
public void withoutPacketTest() throws Exception {
    ChannelGroup channelGroup = new DefaultChannelGroup();

    HealthCheckManager healthCheckManager = new HealthCheckManager(timer, 3000, channelGroup);
    healthCheckManager.start(1000);

    Channel mockChannel = createMockChannel(HealthCheckState.WAIT);
    channelGroup.add(mockChannel);

    try {
        verify(mockChannel, timeout(5000).atLeastOnce()).close();
    } finally {
        healthCheckManager.stop();
    }
}
 
Example 20
Project: multicastSDN   File: Bootstrap.java   Source Code and License 6 votes vote down vote up
public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap");

    bossExecutor = Executors.newCachedThreadPool();
    workerExecutor = Executors.newCachedThreadPool();

    bootstrap =
            new ClientBootstrap(new NioClientSocketChannelFactory(bossExecutor,
                                                                  workerExecutor));
    bootstrap.setOption("child.reuseAddr", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.sendBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.receiveBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.connectTimeoutMillis", 
                        RPCService.CONNECT_TIMEOUT);
    pipelineFactory = new BootstrapPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);
}
 
Example 21
Project: onos   File: Controller.java   Source Code and License 6 votes vote down vote up
/**
 * 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.debug("Listening for PCC connection on {}", sa);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
 
Example 22
Project: httptunnel   File: HttpTunnelSoakTester.java   Source Code and License 6 votes vote down vote up
public HttpTunnelSoakTester() {
	scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
	executor = Executors.newCachedThreadPool();
	ServerSocketChannelFactory serverChannelFactory = new NioServerSocketChannelFactory(
			executor, executor);
	HttpTunnelServerChannelFactory serverTunnelFactory = new HttpTunnelServerChannelFactory(
			serverChannelFactory);

	serverBootstrap = new ServerBootstrap(serverTunnelFactory);
	serverBootstrap.setPipelineFactory(createServerPipelineFactory());

	ClientSocketChannelFactory clientChannelFactory = new NioClientSocketChannelFactory(
			executor, executor);
	HttpTunnelClientChannelFactory clientTunnelFactory = new HttpTunnelClientChannelFactory(
			clientChannelFactory);

	clientBootstrap = new ClientBootstrap(clientTunnelFactory);
	clientBootstrap.setPipelineFactory(createClientPipelineFactory());
	configureProxy();

	channels = new DefaultChannelGroup();
}
 
Example 23
Project: athena   File: Controller.java   Source Code and License 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 24
Project: NithPointsj   File: PeerGroup.java   Source Code and License 5 votes vote down vote up
/**
 * <p>Creates a PeerGroup for the given network and chain, using the provided Netty {@link ClientBootstrap} object.
 * </p>
 *
 * <p>A ClientBootstrap creates raw (TCP) connections to other nodes on the network. Normally you won't need to
 * provide one - use the other constructors. Providing your own bootstrap is useful if you want to control
 * details like how many network threads are used, the connection timeout value and so on. To do this, you can
 * use {@link PeerGroup#createClientBootstrap()} method and then customize the resulting object. Example:</p>
 *
 * <pre>
 *   ClientBootstrap bootstrap = PeerGroup.createClientBootstrap();
 *   bootstrap.setOption("connectTimeoutMillis", 3000);
 *   PeerGroup peerGroup = new PeerGroup(params, chain, bootstrap);
 * </pre>
 *
 * <p>The ClientBootstrap provided does not need a channel pipeline factory set. If one wasn't set, the provided
 * bootstrap will be modified to have one that sets up the pipelines correctly.</p>
 */
public PeerGroup(NetworkParameters params, AbstractBlockChain chain, ClientBootstrap bootstrap) {
    this.params = params;
    this.chain = chain;  // Can be null.
    this.fastCatchupTimeSecs = params.genesisBlock.getTimeSeconds();
    this.wallets = new CopyOnWriteArrayList<Wallet>();

    // This default sentinel value will be overridden by one of two actions:
    //   - adding a peer discovery source sets it to the default
    //   - using connectTo() will increment it by one
    this.maxConnections = 0;

    int height = chain == null ? 0 : chain.getBestChainHeight();
    // We never request that the remote node wait for a bloom filter yet, as we have no wallets
    this.versionMessage = new VersionMessage(params, height, true);

    memoryPool = new MemoryPool();

    // Configure Netty. The "ClientBootstrap" creates connections to other nodes. It can be configured in various
    // ways to control the network.
    if (bootstrap == null) {
        this.bootstrap = createClientBootstrap();
        this.bootstrap.setPipelineFactory(makePipelineFactory(params, chain));
    } else {
        this.bootstrap = bootstrap;
    }

    inactives = Collections.synchronizedList(new ArrayList<PeerAddress>());
    peers = new ArrayList<Peer>();
    pendingPeers = new ArrayList<Peer>();
    channels = new DefaultChannelGroup();
    peerDiscoverers = new CopyOnWriteArraySet<PeerDiscovery>(); 
    peerEventListeners = new CopyOnWriteArrayList<PeerEventListener>();
}
 
Example 25
Project: ikasoa   File: NettyIkasoaFactory.java   Source Code and License 5 votes vote down vote up
public NettyIkasoaFactory(NettyServerConfig nettyServerConfig, ChannelGroup channelGroup) {
	this.nettyServerConfig = nettyServerConfig;
	if (channelGroup == null)
		this.channelGroup = new DefaultChannelGroup();
	else
		this.channelGroup = channelGroup;
}
 
Example 26
Project: hadooparchitecturebook   File: EventClient.java   Source Code and License 5 votes vote down vote up
public void startClient() {
  ClientBootstrap bootstrap = new ClientBootstrap(
          new NioClientSocketChannelFactory(
                  Executors.newCachedThreadPool(),
                  Executors.newCachedThreadPool()));

  try {
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
      public ChannelPipeline getPipeline() {
        ChannelPipeline p = Channels.pipeline();

        handler = new NettyClientHandler();

        p.addLast("handler", handler);
        return p;
      }
    });

    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("receiveBufferSize", 1048576);
    bootstrap.setOption("sendBufferSize", 1048576);

    // Start the connection attempt.

    LOG.info("EventClient: Connecting " + host + "," + port);
    ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
    LOG.info("EventClient: Connected " + host + "," + port);

    allChannels = new DefaultChannelGroup();

    // Wait until the connection is closed or the connection attempt fails.
    allChannels.add(future.getChannel());
    LOG.info("EventClient: Added to Channels ");

  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
Example 27
Project: BJAF3.x   File: ServiceServer.java   Source Code and License 5 votes vote down vote up
public ServiceServer(int port) {
	this.port = port;
	this.channelGroup = new DefaultChannelGroup();
	bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
			Executors.newCachedThreadPool(new NamedThreadFactory(
					"ServiceServer-bossExecutor-", false)),
			Executors.newCachedThreadPool(new NamedThreadFactory(
					"ServiceServer-workerExecutor-", true))));
	bootstrap.setOption("tcpNoDelay", Boolean.parseBoolean(AppProperties
			.get("rpc_server_tcpNoDelay", "true")));
	bootstrap.setOption("reuseAddress", Boolean.parseBoolean(AppProperties
			.get("rpc_server_reuseAddress", "true")));
	String c1 = AppProperties.get("rpc_server_child_tcpNoDelay");
	if (c1 != null && c1.trim().length() > 0) {
		bootstrap.setOption("child.tcpNoDelay", Boolean.parseBoolean(c1));
	}
	c1 = AppProperties.get("rpc_server_child_receiveBufferSize");
	if (c1 != null && c1.trim().length() > 0) {
		bootstrap
				.setOption("child.receiveBufferSize", Integer.parseInt(c1));
	}
	this.taskThreadPool = new TaskThreadPool(AppProperties.getAsInt(
			"rpc_server_workThreadPool_coreSize", 50),
			AppProperties
					.getAsInt("rpc_server_workThreadPool_MaxSize", 200),
			AppProperties.getAsInt(
					"rpc_server_workThreadPool_keepAliveTime",
					60 * 1000 * 5), true, new CallerRunsPolicy());
}
 
Example 28
Project: Android-Airplay-Server   File: AirPlayServer.java   Source Code and License 5 votes vote down vote up
private AirPlayServer(){
	//create executor service
	executorService = Executors.newCachedThreadPool();
	
	//create channel execution handler
	channelExecutionHandler = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(4, 0, 0));

	//channel group
	channelGroup = new DefaultChannelGroup();
	
	//list of mDNS services
	jmDNSInstances = new java.util.LinkedList<JmDNS>();
}
 
Example 29
Project: Camel   File: SingleUDPNettyServerBootstrapFactory.java   Source Code and License 5 votes vote down vote up
public void init(CamelContext camelContext, NettyServerBootstrapConfiguration configuration, ChannelPipelineFactory pipelineFactory) {
    this.camelContext = camelContext;
    this.configuration = configuration;
    this.pipelineFactory = pipelineFactory;

    this.allChannels = configuration.getChannelGroup() != null
        ? configuration.getChannelGroup()
        : new DefaultChannelGroup(SingleUDPNettyServerBootstrapFactory.class.getName());
}
 
Example 30
Project: Camel   File: SingleUDPNettyServerBootstrapFactory.java   Source Code and License 5 votes vote down vote up
public void init(ThreadFactory threadFactory, NettyServerBootstrapConfiguration configuration, ChannelPipelineFactory pipelineFactory) {
    this.threadFactory = threadFactory;
    this.configuration = configuration;
    this.pipelineFactory = pipelineFactory;

    this.allChannels = configuration.getChannelGroup() != null
        ? configuration.getChannelGroup()
        : new DefaultChannelGroup(SingleUDPNettyServerBootstrapFactory.class.getName());
}
 
Example 31
Project: Camel   File: SingleTCPNettyServerBootstrapFactory.java   Source Code and License 5 votes vote down vote up
public void init(CamelContext camelContext, NettyServerBootstrapConfiguration configuration, ChannelPipelineFactory pipelineFactory) {
    this.camelContext = camelContext;
    this.configuration = configuration;
    this.pipelineFactory = pipelineFactory;

    this.allChannels = configuration.getChannelGroup() != null
        ? configuration.getChannelGroup()
        : new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName());
}
 
Example 32
Project: Camel   File: SingleTCPNettyServerBootstrapFactory.java   Source Code and License 5 votes vote down vote up
public void init(ThreadFactory threadFactory, NettyServerBootstrapConfiguration configuration, ChannelPipelineFactory pipelineFactory) {
    this.threadFactory = threadFactory;
    this.configuration = configuration;
    this.pipelineFactory = pipelineFactory;

    this.allChannels = configuration.getChannelGroup() != null
        ? configuration.getChannelGroup()
        : new DefaultChannelGroup(SingleTCPNettyServerBootstrapFactory.class.getName());
}
 
Example 33
Project: jmemcache-daemon   File: MemcachedPipelineFactory.java   Source Code and License 5 votes vote down vote up
public MemcachedPipelineFactory(Cache cache, String version, boolean verbose, int idleTime, int frameSize, DefaultChannelGroup channelGroup) {
    this.cache = cache;
    this.version = version;
    this.verbose = verbose;
    this.idleTime = idleTime;
    this.frameSize = frameSize;
    this.channelGroup = channelGroup;
    memcachedCommandHandler = new MemcachedCommandHandler(this.cache, this.version, this.verbose, this.idleTime, this.channelGroup);
}
 
Example 34
Project: jmemcache-daemon   File: MemCacheDaemon.java   Source Code and License 5 votes vote down vote up
/**
 * Bind the network connection and start the network processing threads.
 */
public void start() {
    // TODO provide tweakable options here for passing in custom executors.
    channelFactory =
            new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool());

    allChannels = new DefaultChannelGroup("jmemcachedChannelGroup");

    ServerBootstrap bootstrap = new ServerBootstrap(channelFactory);

    ChannelPipelineFactory pipelineFactory;
    if (binary)
        pipelineFactory = createMemcachedBinaryPipelineFactory(cache, memcachedVersion, verbose, idleTime, allChannels);
    else
        pipelineFactory = createMemcachedPipelineFactory(cache, memcachedVersion, verbose, idleTime, frameSize, allChannels);

    bootstrap.setPipelineFactory(pipelineFactory);
    bootstrap.setOption("sendBufferSize", 65536 );
    bootstrap.setOption("receiveBufferSize", 65536);

    Channel serverChannel = bootstrap.bind(addr);
    allChannels.add(serverChannel);

    log.info("Listening on " + String.valueOf(addr.getHostName()) + ":" + addr.getPort());

    running = true;
}
 
Example 35
Project: xap-openspaces   File: UnifiedProtocolDecoder.java   Source Code and License 5 votes vote down vote up
public UnifiedProtocolDecoder(SpaceCache cache, DefaultChannelGroup channelGroup, String version, int idle_limit, boolean verbose,
                              boolean threaded) {
    this.cache = cache;
    this.channelGroup = channelGroup;
    this.version = version;
    this.idle_limit = idle_limit;
    this.verbose = verbose;
    this.threaded = threaded;
}
 
Example 36
Project: xap-openspaces   File: MemcachedPipelineFactory.java   Source Code and License 5 votes vote down vote up
public MemcachedPipelineFactory(SpaceCache cache, String version, boolean verbose, int idleTime, int frameSize, DefaultChannelGroup channelGroup) {
    this.cache = cache;
    this.version = version;
    this.verbose = verbose;
    this.idleTime = idleTime;
    this.frameSize = frameSize;
    this.channelGroup = channelGroup;
    memcachedCommandHandler = new MemcachedCommandHandler(this.cache, this.version, this.verbose, this.idleTime, this.channelGroup);
}
 
Example 37
Project: fqueue   File: MemcachedPipelineFactory.java   Source Code and License 5 votes vote down vote up
public MemcachedPipelineFactory(Cache cache, String version,
		boolean verbose, int idleTime, int frameSize,
		DefaultChannelGroup channelGroup) {
	this.cache = cache;
	this.version = version;
	this.verbose = verbose;
	this.idleTime = idleTime;
	this.frameSize = frameSize;
	this.channelGroup = channelGroup;
	memcachedCommandHandler = new MemcachedCommandHandler(this.cache,
			this.version, this.verbose, this.idleTime, this.channelGroup);
}
 
Example 38
Project: fqueue   File: MemcachedBinaryPipelineFactory.java   Source Code and License 5 votes vote down vote up
public MemcachedBinaryPipelineFactory(Cache cache, String version, boolean verbose, int idleTime, DefaultChannelGroup channelGroup) {
    this.cache = cache;
    this.version = version;
    this.verbose = verbose;
    this.idleTime = idleTime;
    this.channelGroup = channelGroup;
    memcachedCommandHandler = new MemcachedCommandHandler(this.cache, this.version, this.verbose, this.idleTime, this.channelGroup);
}
 
Example 39
Project: fqueue   File: MemCacheDaemon.java   Source Code and License 5 votes vote down vote up
/**
 * Bind the network connection and start the network processing threads.
 */
public void start() {
	// TODO provide tweakable options here for passing in custom executors.
	channelFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors
			.newCachedThreadPool());

	allChannels = new DefaultChannelGroup("jmemcachedChannelGroup");

	ServerBootstrap bootstrap = new ServerBootstrap(channelFactory);

	ChannelPipelineFactory pipelineFactory;
	if (binary)
		pipelineFactory = createMemcachedBinaryPipelineFactory(cache, memcachedVersion, verbose, idleTime,
				allChannels);
	else
		pipelineFactory = createMemcachedPipelineFactory(cache, memcachedVersion, verbose, idleTime, frameSize,
				allChannels);

	bootstrap.setOption("child.tcpNoDelay", true);
	bootstrap.setOption("child.keepAlive", true);
	bootstrap.setOption("child.receiveBufferSize", 1024 * 64);
	bootstrap.setPipelineFactory(pipelineFactory);

	Channel serverChannel = bootstrap.bind(addr);
	allChannels.add(serverChannel);

	log.info("Listening on " + String.valueOf(addr.getHostName()) + ":" + addr.getPort());

	running = true;
}
 
Example 40
Project: incubator-tajo   File: HttpDataServer.java   Source Code and License 5 votes vote down vote up
public HttpDataServer(final InetSocketAddress addr, 
    final DataRetriever retriever) {
  this.addr = addr;
  this.factory = new NioServerSocketChannelFactory(
      Executors.newCachedThreadPool(), Executors.newCachedThreadPool(),
      Runtime.getRuntime().availableProcessors() * 2);

  // Configure the server.
  this.bootstrap = new ServerBootstrap(factory);
  // Set up the event pipeline factory.
  this.bootstrap.setPipelineFactory(
      new HttpDataServerPipelineFactory(retriever));    
  this.channelGroup = new DefaultChannelGroup();
}