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

The following examples show how to use org.jboss.netty.channel.group.ChannelGroup. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: pinpoint   Source File: HealthCheckManagerTest.java    License: Apache License 2.0 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 2
Source Project: hadoop   Source File: RpcProgramPortmap.java    License: Apache License 2.0 5 votes vote down vote up
RpcProgramPortmap(ChannelGroup allChannels) {
  this.allChannels = allChannels;
  PortmapMapping m = new PortmapMapping(PROGRAM, VERSION,
      PortmapMapping.TRANSPORT_TCP, RpcProgram.RPCB_PORT);
  PortmapMapping m1 = new PortmapMapping(PROGRAM, VERSION,
      PortmapMapping.TRANSPORT_UDP, RpcProgram.RPCB_PORT);
  map.put(PortmapMapping.key(m), m);
  map.put(PortmapMapping.key(m1), m1);
}
 
Example 3
Source Project: big-c   Source File: RpcProgramPortmap.java    License: Apache License 2.0 5 votes vote down vote up
RpcProgramPortmap(ChannelGroup allChannels) {
  this.allChannels = allChannels;
  PortmapMapping m = new PortmapMapping(PROGRAM, VERSION,
      PortmapMapping.TRANSPORT_TCP, RpcProgram.RPCB_PORT);
  PortmapMapping m1 = new PortmapMapping(PROGRAM, VERSION,
      PortmapMapping.TRANSPORT_UDP, RpcProgram.RPCB_PORT);
  map.put(PortmapMapping.key(m), m);
  map.put(PortmapMapping.key(m1), m1);
}
 
Example 4
Source Project: ikasoa   Source File: NettyServerImpl.java    License: MIT License 5 votes vote down vote up
public NettyServerImpl(final String serverName, final int serverPort, final NettyServerConfiguration configuration,
		final TProcessor processor, final ChannelGroup allChannels) {
	setServerName(serverName);
	requestedPort = serverPort;
	setConfiguration(ObjectUtil.isNull(configuration)
			? new NettyServerConfiguration(new TProcessorFactory(processor)) : configuration);
	setProcessor(processor);
	this.allChannels = allChannels;
}
 
Example 5
Source Project: james-project   Source File: NettyServer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected ChannelPipelineFactory createPipelineFactory(ChannelGroup group) {

    return new AbstractSSLAwareChannelPipelineFactory(
        getTimeout(),
        maxCurConnections,
        maxCurConnectionsPerIP,
        group,
        secure != null ? secure.getEnabledCipherSuites() : null,
        eHandler,
        getFrameHandlerFactory(),
        hashedWheelTimer) {

        @Override
        protected ChannelUpstreamHandler createHandler() {
            return coreHandler;
        }

        @Override
        protected boolean isSSLSocket() {
            return getSSLContext() != null && secure != null && !secure.isStartTLS();
        }

        @Override
        protected SSLContext getSSLContext() {
            if (secure != null) {
                return secure.getContext();
            } else  {
                return null;
            }
        }
    };

}
 
Example 6
public AbstractSSLAwareChannelPipelineFactory(int timeout,
        int maxConnections, int maxConnectsPerIp, ChannelGroup group, String[] enabledCipherSuites, ExecutionHandler eHandler,
        ChannelHandlerFactory frameHandlerFactory, HashedWheelTimer hashedWheelTimer) {
    this(timeout, maxConnections, maxConnectsPerIp, group, eHandler, frameHandlerFactory, hashedWheelTimer);
    
    // We need to copy the String array because of possible security issues.
    // See https://issues.apache.org/jira/browse/PROTOCOLS-18
    this.enabledCipherSuites = ArrayUtils.clone(enabledCipherSuites);
}
 
Example 7
public AbstractChannelPipelineFactory(int timeout, int maxConnections, int maxConnectsPerIp, ChannelGroup channels,
                                      ExecutionHandler eHandler, ChannelHandlerFactory frameHandlerFactory,
                                      HashedWheelTimer hashedWheelTimer) {
    this.connectionLimitHandler = new ConnectionLimitUpstreamHandler(maxConnections);
    this.connectionPerIpLimitHandler = new ConnectionPerIpLimitUpstreamHandler(maxConnectsPerIp);
    this.groupHandler = new ChannelGroupHandler(channels);
    this.timeout = timeout;
    this.eHandler = eHandler;
    this.frameHandlerFactory = frameHandlerFactory;
    this.timer = hashedWheelTimer;
}
 
Example 8
@Override
protected ChannelPipelineFactory createPipelineFactory(ChannelGroup group) {
    return new AbstractExecutorAwareChannelPipelineFactory(getTimeout(), connectionLimit, connPerIP, group,
        enabledCipherSuites, getExecutionHandler(), getFrameHandlerFactory(), timer) {
        @Override
        protected SSLContext getSSLContext() {
            if (encryption == null) {
                return null;
            } else {
                return encryption.getContext();
            }
        }

        @Override
        protected boolean isSSLSocket() {
            return encryption != null && !encryption.isStartTLS();
        }


        @Override
        protected ChannelUpstreamHandler createHandler() {
            return AbstractConfigurableAsyncServer.this.createCoreHandler();

        }

        @Override
        protected ConnectionCountHandler getConnectionCountHandler() {
            return AbstractConfigurableAsyncServer.this.getConnectionCountHandler();
        }

    };
}
 
Example 9
Source Project: pinpoint   Source File: HealthCheckManager.java    License: Apache License 2.0 5 votes vote down vote up
public HealthCheckManager(Timer timer, long waitTimeMillis, ChannelGroup channelGroup) {
    Assert.requireNonNull(timer, "timer");
    Assert.isTrue(waitTimeMillis > 0, "waitTimeMillis is must greater than 0");
    Assert.requireNonNull(channelGroup, "channelGroup");

    this.timer = timer;
    this.waitTimeMillis = waitTimeMillis;

    this.channelGroup = channelGroup;
}
 
Example 10
Source Project: pinpoint   Source File: HealthCheckManagerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void legacyPingPacketTest() throws Exception {
    ChannelGroup channelGroup = new DefaultChannelGroup();

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

    Channel mockChannel = createMockChannel(HealthCheckState.RECEIVED_LEGACY);
    channelGroup.add(mockChannel);
    try {
        verify(mockChannel, timeout(3000).atLeastOnce()).write(PingPacket.PING_PACKET);
    } finally {
        healthCheckManager.stop();
    }
}
 
Example 11
Source Project: pinpoint   Source File: HealthCheckManagerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void pingPacketTest() throws Exception {
    ChannelGroup channelGroup = new DefaultChannelGroup();

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

    Channel mockChannel = createMockChannel(HealthCheckState.RECEIVED);
    channelGroup.add(mockChannel);
    try {
        verify(mockChannel, timeout(3000).atLeastOnce()).write(PingSimplePacket.PING_PACKET);
    } finally {
        healthCheckManager.stop();
    }
}
 
Example 12
Source Project: usergrid   Source File: WebSocketChannelHandler.java    License: Apache License 2.0 5 votes vote down vote up
private ChannelGroup getChannelGroupWithDefault( String path ) {
    ChannelGroup group = subscribers.get( path );

    if ( group == null ) {
        group = subscribers.putIfAbsent( path, new DefaultChannelGroup() );
    }

    return group;
}
 
Example 13
Source Project: usergrid   Source File: WebSocketChannelHandler.java    License: Apache License 2.0 5 votes vote down vote up
public void removeSubscription( String path, Channel channel ) {
    ChannelGroup group = subscribers.get( path );
    synchronized ( group ) {
        group.remove( channel );
        if ( group.isEmpty() ) {
            subscribers.remove( path, group );
        }
    }
}
 
Example 14
public HandshakeInitializationHandler(ChannelGroup childGroups){
    this.childGroups = childGroups;
}
 
Example 15
Source Project: voyage   Source File: NettyRpcServerHandler.java    License: Apache License 2.0 4 votes vote down vote up
public NettyRpcServerHandler(ChannelGroup channelGroups) {
	this.channelGroups = channelGroups;
}
 
Example 16
Source Project: voyage   Source File: RpcServerBootstrap.java    License: Apache License 2.0 4 votes vote down vote up
private void initHttpBootstrap(int myport) {
	logger.info("initHttpBootstrap...........");
	final ServerConfig serverConfig = new ServerConfig(myport);
	final ChannelGroup channelGroup = new DefaultChannelGroup(getClass().getName());
	bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
			//建议用ThreadPoolExecutor代替
			Executors.newCachedThreadPool(),
			Executors.newCachedThreadPool(), serverConfig.getThreadCnt()));
	//设置常见参数
	bootstrap.setOption("tcpNoDelay","true");//禁用nagle算法
	bootstrap.setOption("reuseAddress", "true");
	bootstrap.setOption("SO_RCVBUF",1024*128);
	bootstrap.setOption("SO_SNDBUF",1024*128);
	timer = new HashedWheelTimer();
	bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		public ChannelPipeline getPipeline() throws Exception {
			ChannelPipeline pipeline = Channels.pipeline();
			int readTimeout = serverConfig.getReadTimeout();
			if (readTimeout > 0) {
				pipeline.addLast("timeout", new ReadTimeoutHandler(timer, readTimeout, TimeUnit.MILLISECONDS));
			}
			pipeline.addLast("decoder", new RpcRequestDecode());
			pipeline.addLast("encoder", new RpcResponseEncode());
			pipeline.addLast("handler", new NettyRpcServerHandler(channelGroup));
			return pipeline;
		}
	});
	
	int port = serverConfig.getPort();
	if (!checkPortConfig(port)) {
		throw new IllegalStateException("port: " + port + " already in use!");
	}

	Channel channel = bootstrap.bind(new InetSocketAddress(port));
	channelGroup.add(channel);
	logger.info("voyage server started");

	waitForShutdownCommand();
	ChannelGroupFuture future = channelGroup.close();
	future.awaitUninterruptibly();
	bootstrap.releaseExternalResources();
	timer.stop();
	timer = null;

	logger.info("voyage server stoped");

}
 
Example 17
Source Project: ikasoa   Source File: NettyIkasoaFactory.java    License: MIT License 4 votes vote down vote up
public NettyIkasoaFactory(NettyServerConfiguration configuration, ChannelGroup channelGroup) {
	this.configuration = configuration;
	this.channelGroup = ObjectUtil.isNull(channelGroup) ? new DefaultChannelGroup() : channelGroup;
}
 
Example 18
Source Project: Android-Airplay-Server   Source File: AirPlayServer.java    License: MIT License 4 votes vote down vote up
public ChannelGroup getChannelGroup() {
	return channelGroup;
}
 
Example 19
public AbstractSSLAwareChannelPipelineFactory(int timeout,
                                              int maxConnections, int maxConnectsPerIp, ChannelGroup group, ExecutionHandler eHandler,
                                              ChannelHandlerFactory frameHandlerFactory, HashedWheelTimer hashedWheelTimer) {
    super(timeout, maxConnections, maxConnectsPerIp, group, eHandler, frameHandlerFactory, hashedWheelTimer);
}
 
Example 20
Source Project: james-project   Source File: ChannelGroupHandler.java    License: Apache License 2.0 4 votes vote down vote up
public ChannelGroupHandler(ChannelGroup channels) {
    this.channels = channels;
}
 
Example 21
public AbstractExecutorAwareChannelPipelineFactory(int timeout, int maxConnections, int maxConnectsPerIp,
                                                   ChannelGroup group, String[] enabledCipherSuites,
                                                   ExecutionHandler eHandler, ChannelHandlerFactory frameHandlerFactory,
                                                   HashedWheelTimer hashedWheelTimer) {
    super(timeout, maxConnections, maxConnectsPerIp, group, enabledCipherSuites, eHandler, frameHandlerFactory, hashedWheelTimer);
}
 
Example 22
Source Project: james-project   Source File: ManageSieveServer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected ChannelPipelineFactory createPipelineFactory(final ChannelGroup group) {

    return new ChannelPipelineFactory() {

        private final ChannelGroupHandler groupHandler = new ChannelGroupHandler(group);

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipeline();
            Encryption secure = getEncryption();
            if (secure != null && !secure.isStartTLS()) {
                // We need to set clientMode to false.
                // See https://issues.apache.org/jira/browse/JAMES-1025
                SSLEngine engine = secure.getContext().createSSLEngine();
                engine.setUseClientMode(false);
                pipeline.addFirst(SSL_HANDLER, new SslHandler(engine));

            }
            pipeline.addLast(GROUP_HANDLER, groupHandler);
            pipeline.addLast(CONNECTION_LIMIT_HANDLER, new ConnectionLimitUpstreamHandler(ManageSieveServer.this.connectionLimit));
            pipeline.addLast(CONNECTION_LIMIT_PER_IP_HANDLER, new ConnectionPerIpLimitUpstreamHandler(ManageSieveServer.this.connPerIP));
            // Add the text line decoder which limit the max line length,
            // don't strip the delimiter and use CRLF as delimiter
            // Use a SwitchableDelimiterBasedFrameDecoder, see JAMES-1436
            pipeline.addLast(FRAMER, getFrameHandlerFactory().create(pipeline));
            pipeline.addLast(CONNECTION_COUNT_HANDLER, getConnectionCountHandler());
            pipeline.addLast(CHUNK_WRITE_HANDLER, new ChunkedWriteHandler());

            ExecutionHandler ehandler = getExecutionHandler();
            if (ehandler  != null) {
                pipeline.addLast(EXECUTION_HANDLER, ehandler);

            }
            pipeline.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));
            pipeline.addLast(CORE_HANDLER, createCoreHandler());
            pipeline.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8));
            return pipeline;
        }

    };
}
 
Example 23
Source Project: james-project   Source File: IMAPServer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected ChannelPipelineFactory createPipelineFactory(final ChannelGroup group) {
    
    return new ChannelPipelineFactory() {
        
        private final ChannelGroupHandler groupHandler = new ChannelGroupHandler(group);
        private final HashedWheelTimer timer = new HashedWheelTimer();
        
        private final TimeUnit timeoutUnit = TimeUnit.SECONDS;

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipeline();
            pipeline.addLast(GROUP_HANDLER, groupHandler);
            pipeline.addLast("idleHandler", new IdleStateHandler(timer, 0, 0, timeout, timeoutUnit));
            pipeline.addLast(TIMEOUT_HANDLER, new ImapIdleStateHandler());
            pipeline.addLast(CONNECTION_LIMIT_HANDLER, new ConnectionLimitUpstreamHandler(IMAPServer.this.connectionLimit));

            pipeline.addLast(CONNECTION_LIMIT_PER_IP_HANDLER, new ConnectionPerIpLimitUpstreamHandler(IMAPServer.this.connPerIP));

            // Add the text line decoder which limit the max line length,
            // don't strip the delimiter and use CRLF as delimiter
            // Use a SwitchableDelimiterBasedFrameDecoder, see JAMES-1436
            pipeline.addLast(FRAMER, getFrameHandlerFactory().create(pipeline));
           
            Encryption secure = getEncryption();
            if (secure != null && !secure.isStartTLS()) {
                // We need to set clientMode to false.
                // See https://issues.apache.org/jira/browse/JAMES-1025
                SSLEngine engine = secure.getContext().createSSLEngine();
                engine.setUseClientMode(false);
                pipeline.addFirst(SSL_HANDLER, new SslHandler(engine));

            }
            pipeline.addLast(CONNECTION_COUNT_HANDLER, getConnectionCountHandler());

            pipeline.addLast(CHUNK_WRITE_HANDLER, new ChunkedWriteHandler());

            ExecutionHandler ehandler = getExecutionHandler();
            if (ehandler  != null) {
                pipeline.addLast(EXECUTION_HANDLER, ehandler);

            }
            pipeline.addLast(REQUEST_DECODER, new ImapRequestFrameDecoder(decoder, inMemorySizeLimit, literalSizeLimit));

            pipeline.addLast(CORE_HANDLER, createCoreHandler());
            return pipeline;
        }

    };
}
 
Example 24
Source Project: canal   Source File: HandshakeInitializationHandler.java    License: Apache License 2.0 4 votes vote down vote up
public HandshakeInitializationHandler(ChannelGroup childGroups){
    this.childGroups = childGroups;
}
 
Example 25
Source Project: canal   Source File: HandshakeInitializationHandler.java    License: Apache License 2.0 4 votes vote down vote up
public HandshakeInitializationHandler(ChannelGroup childGroups){
    this.childGroups = childGroups;
}
 
Example 26
Source Project: usergrid   Source File: WebSocketChannelHandler.java    License: Apache License 2.0 4 votes vote down vote up
public void addSubscription( String path, Channel channel ) {
    ChannelGroup group = subscribers.get( path );
    synchronized ( group ) {
        group.add( channel );
    }
}
 
Example 27
Source Project: usergrid   Source File: WebSocketChannelHandler.java    License: Apache License 2.0 4 votes vote down vote up
public ChannelGroup getSubscriptionGroup( String path ) {
    return subscribers.get( path );
}
 
Example 28
Source Project: james-project   Source File: AbstractAsyncServer.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create ChannelPipelineFactory to use by this Server implementation
 */
protected abstract ChannelPipelineFactory createPipelineFactory(ChannelGroup group);