Example usage for io.netty.channel.group DefaultChannelGroup DefaultChannelGroup

List of usage examples for io.netty.channel.group DefaultChannelGroup DefaultChannelGroup

Introduction

In this page you can find the example usage for io.netty.channel.group DefaultChannelGroup DefaultChannelGroup.

Prototype

public DefaultChannelGroup(EventExecutor executor) 

Source Link

Document

Creates a new group with a generated name and the provided EventExecutor to notify the ChannelGroupFuture s.

Usage

From source file:adalightserver.http.HttpServer.java

License:Apache License

public HttpServer(IController ledController) {
    this.bossGroup = new NioEventLoopGroup(1);
    this.clientGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors());
    this.scheduler = Schedulers.from(bossGroup);
    this.connections = new DefaultChannelGroup(bossGroup.next());
    this.wsConnections = new DefaultChannelGroup(bossGroup.next());

    this.ledController = ledController;
}

From source file:c5db.replication.ReplicatorService.java

License:Apache License

/**
 * ReplicatorService creates and starts fibers; it must be stopped (or failed) in
 * order to dispose them./*from w  w  w  . j  av a  2s.  c o  m*/
 */
public ReplicatorService(EventLoopGroup bossGroup, EventLoopGroup workerGroup, long nodeId, int port,
        ModuleInformationProvider moduleInformationProvider, FiberSupplier fiberSupplier,
        QuorumFileReaderWriter quorumFileReaderWriter) {
    this.bossGroup = bossGroup;
    this.workerGroup = workerGroup;
    this.nodeId = nodeId;
    this.port = port;
    this.moduleInformationProvider = moduleInformationProvider;
    this.fiberSupplier = fiberSupplier;

    this.allChannels = new DefaultChannelGroup(workerGroup.next());
    this.persister = new Persister(quorumFileReaderWriter);
}

From source file:com.cloudhopper.smpp.impl.DefaultSmppClient.java

License:Apache License

/**
 * Creates a new default SmppClient.//from ww w.j a  v a2  s .c om
 * @param workerGroup The max number of concurrent sessions expected
 *      to be active at any time.  This number controls the max number of worker
 *      threads that the underlying Netty library will use.  If processing
 *      occurs in a sessionHandler (a blocking op), be <b>VERY</b> careful
 *      setting this to the correct number of concurrent sessions you expect.
 * @param monitorExecutor The scheduled executor that all sessions will share
 *      to monitor themselves and expire requests.  If null monitoring will
 *      be disabled.
 */
public DefaultSmppClient(NioEventLoopGroup workerGroup, ScheduledExecutorService monitorExecutor) {
    this.channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    this.workerGroup = workerGroup;
    this.clientBootstrap = new Bootstrap();
    this.clientBootstrap.group(this.workerGroup);
    this.clientBootstrap.channel(NioSocketChannel.class);
    // we use the same default pipeline for all new channels - no need for a factory
    this.clientConnector = new SmppClientConnector(this.channels);

    this.clientBootstrap.handler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast(SmppChannelConstants.PIPELINE_CLIENT_CONNECTOR_NAME, clientConnector);
        }
    });

    this.monitorExecutor = monitorExecutor;
}

From source file:com.cloudhopper.smpp.impl.DefaultSmppServer.java

License:Apache License

/**
 * Creates a new default SmppServer.// ww  w.jav a 2s. c om
 * @param configuration The server configuration to create this server with
 * @param serverHandler The handler implementation for handling bind requests
 *      and creating/destroying sessions.
 * @param monitorExecutor The scheduled executor that all sessions will share
 *      to monitor themselves and expire requests. If null monitoring will
 *      be disabled.
 * @param bossGroup Specify the EventLoopGroup to accept new connections and
 *      handle accepted connections. The {@link EventLoopGroup} is used to handle
 *      all the events and IO for {@link SocketChannel}.
 * @param workerGroup The {@link EventLoopGroup} is used to handle all the events
 *      and IO for {@link Channel}.
 */
public DefaultSmppServer(final SmppServerConfiguration configuration, SmppServerHandler serverHandler,
        ScheduledExecutorService monitorExecutor, EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
    this.configuration = configuration;
    // the same group we'll put every server channel
    this.channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    this.serverHandler = serverHandler;

    // tie the server bootstrap to this server socket channel factory
    this.serverBootstrap = new ServerBootstrap();

    // a factory for creating channels (connections)
    if (configuration.isNonBlockingSocketsEnabled()) {
        this.serverBootstrap.channel(NioServerSocketChannel.class);
    } else {
        this.serverBootstrap.channel(OioServerSocketChannel.class);
    }

    this.bossGroup = bossGroup;
    this.workerGroup = workerGroup;
    this.serverBootstrap.group(this.bossGroup, this.workerGroup);

    // set options for the server socket that are useful
    this.serverBootstrap.option(ChannelOption.SO_REUSEADDR, configuration.isReuseAddress());

    // we use the same default pipeline for all new channels - no need for a factory
    this.serverConnector = new SmppServerConnector(channels, this);

    this.serverBootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast(SmppChannelConstants.PIPELINE_SERVER_CONNECTOR_NAME, serverConnector);
        }
    });

    // a shared timer used to make sure new channels are bound within X milliseconds
    this.bindTimer = new Timer(configuration.getName() + "-BindTimer0", true);
    // NOTE: this would permit us to customize the "transcoding" context for a server if needed
    this.transcoder = new DefaultPduTranscoder(new DefaultPduTranscoderContext());
    this.sessionIdSequence = new AtomicLong(0);
    this.monitorExecutor = monitorExecutor;
    this.counters = new DefaultSmppServerCounters();
    if (configuration.isJmxEnabled()) {
        registerMBean();
    }
}

From source file:com.cloudhopper.smpp.simulator.SmppSimulatorServer.java

License:Apache License

public SmppSimulatorServer() {
    // used for tracking any child channels (sessions)
    this.sessionChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    // we'll put the "boss" worker for a server in its own pool
    bossGroup = new NioEventLoopGroup();
    workerGroup = new NioEventLoopGroup();

    // tie the server bootstrap to this server socket channel factory
    this.serverBootstrap = new ServerBootstrap();
    this.serverBootstrap.channel(NioServerSocketChannel.class);
    this.serverBootstrap.group(bossGroup, workerGroup);

    // the handler to use when new child connections are accepted
    this.serverHandler = new SmppSimulatorServerHandler(this.sessionChannels);
    // set up the event pipeline factory for new connections
    this.serverBootstrap.childHandler(serverHandler);
}

From source file:com.codebullets.external.party.simulator.connections.websocket.inbound.InboundWebSocketConnection.java

License:Apache License

/**
 * {@inheritDoc}//  ww  w .ja v  a2s  . c  om
 */
@Override
public void start(final ConnectionConfig config) {
    URI endpoint = URI.create(config.getEndpoint());

    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    connectedChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);

    ServerBootstrap serverBootstrap = new ServerBootstrap();
    serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(
            new WebSocketServerInitializer(endpoint, connectionMonitor, config, connectedChannels));

    try {
        serverBootstrap.bind(endpoint.getPort()).sync().channel();
        LOG.info("Web socket server started at port {}.", endpoint.getPort());
    } catch (InterruptedException e) {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();

        throw new IllegalStateException("Error starting web socket endpoint.", e);
    }
}

From source file:com.heliosapm.shorthand.caster.broadcast.BroadcastListener.java

License:Open Source License

private BroadcastListener() {
    group = new NioEventLoopGroup(0, this);
    bootstrap = new Bootstrap();
    taskThreadPool = Executors.newFixedThreadPool(
            ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors(), new ThreadFactory() {
                final AtomicInteger serial = new AtomicInteger();

                @Override//  www .  j a  v  a 2  s . c  o  m
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r, "TaskExecutionThread#" + serial.incrementAndGet());
                    t.setDaemon(true);
                    return t;
                }
            });
    router = new BroadcastListenerRouter(taskThreadPool);
    boundChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    NetworkInterface nic = null;
    try {
        nic = NetworkInterface.getByName(ConfigurationHelper.getSystemThenEnvProperty(
                ShorthandProperties.AGENT_BROADCAST_NIC_PROP, ShorthandProperties.DEFAULT_AGENT_BROADCAST_NIC));
    } catch (Exception ex) {
        try {
            nic = NetworkInterface.getByIndex(0);
        } catch (SocketException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    String[] addresses = ConfigurationHelper.getSystemThenEnvPropertyArray(AGENT_BROADCAST_NETWORK_PROP,
            DEFAULT_AGENT_BROADCAST_NETWORK);
    int[] ports = ConfigurationHelper.getIntSystemThenEnvPropertyArray(AGENT_BROADCAST_PORT_PROP,
            "" + DEFAULT_AGENT_BROADCAST_PORT);
    if (addresses.length != ports.length) {
        throw new RuntimeException(
                "Invalid broadcast configuration. Number of addresses != Number of ports. Addresses:"
                        + Arrays.toString(addresses) + " Ports:" + Arrays.toString(ports));
    }
    for (int i = 0; i < addresses.length; i++) {
        try {
            startListener(new InetSocketAddress(addresses[i], ports[i]), nic);
        } catch (Exception ex) {
            loge("Failed to start listener on [%s:%s]", ex, addresses[i], ports[i]);
        }
    }

}

From source file:com.lambdaworks.redis.AbstractRedisClient.java

License:Apache License

/**
 * Create a new instance with client resources.
 *
 * @param clientResources the client resources. If {@literal null}, the client will create a new dedicated instance of
 *        client resources and keep track of them.
 *//*from w  ww  .  j  a va  2s .c  om*/
protected AbstractRedisClient(ClientResources clientResources) {

    if (clientResources == null) {
        sharedResources = false;
        this.clientResources = DefaultClientResources.create();
    } else {
        sharedResources = true;
        this.clientResources = clientResources;
    }

    unit = TimeUnit.SECONDS;

    genericWorkerPool = this.clientResources.eventExecutorGroup();
    channels = new DefaultChannelGroup(genericWorkerPool.next());
    timer = (HashedWheelTimer) this.clientResources.timer();
}

From source file:com.seventh_root.ld33.server.network.LD33ServerHandler.java

License:Apache License

public LD33ServerHandler(LD33Server server) {
    this.server = server;
    this.channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
}

From source file:com.trinity.engine.protocol.detail.TrinityConnectionManager.java

License:Apache License

/**
 * Default constructor for {@link TrinityConnectionManager}
 *//*w  ww .  j  a  v a 2s . c  o  m*/
public TrinityConnectionManager() {
    this.mRegistry = new ConcurrentHashMap<>();
    this.mGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    this.mBossGroup = new NioEventLoopGroup();
    this.mWorkerGroup = new NioEventLoopGroup();
    this.mBootstrap = new ServerBootstrap();
    this.mUncaughtExceptionHandler = new AtomicReference<>(new DefaultUncaughtExceptionHandler());
}