Example usage for io.netty.buffer PooledByteBufAllocator DEFAULT

List of usage examples for io.netty.buffer PooledByteBufAllocator DEFAULT

Introduction

In this page you can find the example usage for io.netty.buffer PooledByteBufAllocator DEFAULT.

Prototype

PooledByteBufAllocator DEFAULT

To view the source code for io.netty.buffer PooledByteBufAllocator DEFAULT.

Click Source Link

Usage

From source file:com.floragunn.searchguard.ssl.DefaultSearchGuardKeyStore.java

License:Apache License

@Override
public SSLEngine createHTTPSSLEngine() throws SSLException {
    final SSLEngine engine = httpSslContext.newEngine(PooledByteBufAllocator.DEFAULT);
    engine.setEnabledProtocols(SSLConfigConstants.getSecureSSLProtocols(settings, true));
    // engine.setNeedClientAuth(enforceHTTPClientAuth);
    return engine;

}

From source file:com.floragunn.searchguard.ssl.DefaultSearchGuardKeyStore.java

License:Apache License

@Override
public SSLEngine createServerTransportSSLEngine() throws SSLException {

    final SSLEngine engine = transportServerSslContext.newEngine(PooledByteBufAllocator.DEFAULT);
    engine.setEnabledProtocols(SSLConfigConstants.getSecureSSLProtocols(settings, false));
    // engine.setNeedClientAuth(true);
    return engine;

}

From source file:com.floragunn.searchguard.ssl.DefaultSearchGuardKeyStore.java

License:Apache License

@Override
public SSLEngine createClientTransportSSLEngine(final String peerHost, final int peerPort) throws SSLException {

    if (peerHost != null) {
        final SSLEngine engine = transportClientSslContext.newEngine(PooledByteBufAllocator.DEFAULT, peerHost,
                peerPort);//from ww  w  .  j a v a 2s .  co m

        final SSLParameters sslParams = new SSLParameters();
        sslParams.setEndpointIdentificationAlgorithm("HTTPS");
        engine.setSSLParameters(sslParams);
        engine.setEnabledProtocols(SSLConfigConstants.getSecureSSLProtocols(settings, false));
        return engine;
    } else {
        final SSLEngine engine = transportClientSslContext.newEngine(PooledByteBufAllocator.DEFAULT);
        engine.setEnabledProtocols(SSLConfigConstants.getSecureSSLProtocols(settings, false));
        return engine;
    }

}

From source file:com.floragunn.searchguard.ssl.SearchGuardKeyStore.java

License:Apache License

public SSLEngine createHTTPSSLEngine() throws SSLException {
    final SSLEngine engine = httpSslContext.newEngine(PooledByteBufAllocator.DEFAULT);
    engine.setEnabledProtocols(SSLConfigConstants.getSecureSSLProtocols(settings, true));
    // engine.setNeedClientAuth(enforceHTTPClientAuth);
    return engine;

}

From source file:com.floragunn.searchguard.ssl.SearchGuardKeyStore.java

License:Apache License

public SSLEngine createServerTransportSSLEngine() throws SSLException {

    final SSLEngine engine = transportServerSslContext.newEngine(PooledByteBufAllocator.DEFAULT);
    engine.setEnabledProtocols(SSLConfigConstants.getSecureSSLProtocols(settings, false));
    // engine.setNeedClientAuth(true);
    return engine;

}

From source file:com.floragunn.searchguard.ssl.SearchGuardKeyStore.java

License:Apache License

public SSLEngine createClientTransportSSLEngine(final String peerHost, final int peerPort) throws SSLException {

    if (peerHost != null) {
        final SSLEngine engine = transportClientSslContext.newEngine(PooledByteBufAllocator.DEFAULT, peerHost,
                peerPort);/*from w  w  w  .  j a v a 2s  .c  o  m*/

        final SSLParameters sslParams = new SSLParameters();
        sslParams.setEndpointIdentificationAlgorithm("HTTPS");
        engine.setSSLParameters(sslParams);
        engine.setEnabledProtocols(SSLConfigConstants.getSecureSSLProtocols(settings, false));
        return engine;
    } else {
        final SSLEngine engine = transportClientSslContext.newEngine(PooledByteBufAllocator.DEFAULT);
        engine.setEnabledProtocols(SSLConfigConstants.getSecureSSLProtocols(settings, false));
        return engine;
    }

}

From source file:com.gemstone.gemfire.redis.GemFireRedisServer.java

License:Apache License

/**
 * Helper method to start the server listening for connections. The
 * server is bound to the port specified by {@link GemFireRedisServer#serverPort}
 * /*from w  w w  . ja va2s.  co  m*/
 * @throws IOException
 * @throws InterruptedException
 */
private void startRedisServer() throws IOException, InterruptedException {
    ThreadFactory selectorThreadFactory = new ThreadFactory() {
        private final AtomicInteger counter = new AtomicInteger();

        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName("GemFireRedisServer-SelectorThread-" + counter.incrementAndGet());
            t.setDaemon(true);
            return t;
        }

    };

    ThreadFactory workerThreadFactory = new ThreadFactory() {
        private final AtomicInteger counter = new AtomicInteger();

        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName("GemFireRedisServer-WorkerThread-" + counter.incrementAndGet());
            return t;
        }

    };

    bossGroup = null;
    workerGroup = null;
    Class<? extends ServerChannel> socketClass = null;
    if (singleThreadPerConnection) {
        bossGroup = new OioEventLoopGroup(Integer.MAX_VALUE, selectorThreadFactory);
        workerGroup = new OioEventLoopGroup(Integer.MAX_VALUE, workerThreadFactory);
        socketClass = OioServerSocketChannel.class;
    } else {
        bossGroup = new NioEventLoopGroup(this.numSelectorThreads, selectorThreadFactory);
        workerGroup = new NioEventLoopGroup(this.numWorkerThreads, workerThreadFactory);
        socketClass = NioServerSocketChannel.class;
    }
    InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
    String pwd = system.getConfig().getRedisPassword();
    final byte[] pwdB = Coder.stringToBytes(pwd);
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(socketClass).childHandler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            if (logger.fineEnabled())
                logger.fine("GemFireRedisServer-Connection established with " + ch.remoteAddress());
            ChannelPipeline p = ch.pipeline();
            p.addLast(ByteToCommandDecoder.class.getSimpleName(), new ByteToCommandDecoder());
            p.addLast(ExecutionHandlerContext.class.getSimpleName(),
                    new ExecutionHandlerContext(ch, cache, regionCache, GemFireRedisServer.this, pwdB));
        }
    }).option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_RCVBUF, getBufferSize())
            .childOption(ChannelOption.SO_KEEPALIVE, true)
            .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, GemFireRedisServer.connectTimeoutMillis)
            .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    // Bind and start to accept incoming connections.
    ChannelFuture f = b.bind(new InetSocketAddress(getBindAddress(), serverPort)).sync();
    if (this.logger.infoEnabled()) {
        String logMessage = "GemFireRedisServer started {" + getBindAddress() + ":" + serverPort
                + "}, Selector threads: " + this.numSelectorThreads;
        if (this.singleThreadPerConnection)
            logMessage += ", One worker thread per connection";
        else
            logMessage += ", Worker threads: " + this.numWorkerThreads;
        this.logger.info(logMessage);
    }
    this.serverChannel = f.channel();
}

From source file:com.github.milenkovicm.kafka.util.Allocator.java

License:Apache License

/** Used to get defaults from Netty's private static fields. */
private static int getPrivateStaticField(String name) {
    try {/*  w ww  .  ja  va 2s  .co m*/
        Field f = PooledByteBufAllocator.DEFAULT.getClass().getDeclaredField(name);
        f.setAccessible(true);
        return f.getInt(null);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.github.sinsinpub.pero.manual.proxyhandler.ProxyHandlerTest.java

License:Apache License

@Parameters(name = "{index}: {0}")
public static List<Object[]> testItems() {
    List<TestItem> items = Arrays.asList(

            // HTTP -------------------------------------------------------

            new SuccessTestItem("Anonymous HTTP proxy: successful connection", DESTINATION,
                    new HttpProxyHandler(anonHttpProxy.address())),

            new FailureTestItem("Anonymous HTTP proxy: rejected connection", BAD_DESTINATION, "status: 403",
                    new HttpProxyHandler(anonHttpProxy.address())),

            new FailureTestItem("HTTP proxy: rejected anonymous connection", DESTINATION, "status: 401",
                    new HttpProxyHandler(httpProxy.address())),

            new SuccessTestItem("HTTP proxy: successful connection", DESTINATION,
                    new HttpProxyHandler(httpProxy.address(), USERNAME, PASSWORD)),

            new FailureTestItem("HTTP proxy: rejected connection", BAD_DESTINATION, "status: 403",
                    new HttpProxyHandler(httpProxy.address(), USERNAME, PASSWORD)),

            new FailureTestItem("HTTP proxy: authentication failure", DESTINATION, "status: 401",
                    new HttpProxyHandler(httpProxy.address(), BAD_USERNAME, BAD_PASSWORD)),

            new TimeoutTestItem("HTTP proxy: timeout", new HttpProxyHandler(deadHttpProxy.address())),

            // HTTPS ------------------------------------------------------

            new SuccessTestItem("Anonymous HTTPS proxy: successful connection", DESTINATION,
                    clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT),
                    new HttpProxyHandler(anonHttpsProxy.address())),

            new FailureTestItem("Anonymous HTTPS proxy: rejected connection", BAD_DESTINATION, "status: 403",
                    clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT),
                    new HttpProxyHandler(anonHttpsProxy.address())),

            new FailureTestItem("HTTPS proxy: rejected anonymous connection", DESTINATION, "status: 401",
                    clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT),
                    new HttpProxyHandler(httpsProxy.address())),

            new SuccessTestItem("HTTPS proxy: successful connection", DESTINATION,
                    clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT),
                    new HttpProxyHandler(httpsProxy.address(), USERNAME, PASSWORD)),

            new FailureTestItem("HTTPS proxy: rejected connection", BAD_DESTINATION, "status: 403",
                    clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT),
                    new HttpProxyHandler(httpsProxy.address(), USERNAME, PASSWORD)),

            new FailureTestItem("HTTPS proxy: authentication failure", DESTINATION, "status: 401",
                    clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT),
                    new HttpProxyHandler(httpsProxy.address(), BAD_USERNAME, BAD_PASSWORD)),

            new TimeoutTestItem("HTTPS proxy: timeout", clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT),
                    new HttpProxyHandler(deadHttpsProxy.address())),

            // SOCKS5 -----------------------------------------------------

            new SuccessTestItem("Anonymous SOCKS5: successful connection", DESTINATION,
                    new Socks5ProxyHandler(anonSocks5Proxy.address())),

            new FailureTestItem("Anonymous SOCKS5: rejected connection", BAD_DESTINATION, "status: FORBIDDEN",
                    new Socks5ProxyHandler(anonSocks5Proxy.address())),

            new FailureTestItem("SOCKS5: rejected anonymous connection", DESTINATION,
                    "unexpected authMethod: PASSWORD", new Socks5ProxyHandler(socks5Proxy.address())),

            new SuccessTestItem("SOCKS5: successful connection", DESTINATION,
                    new Socks5ProxyHandler(socks5Proxy.address(), USERNAME, PASSWORD)),

            new FailureTestItem("SOCKS5: rejected connection", BAD_DESTINATION, "status: FORBIDDEN",
                    new Socks5ProxyHandler(socks5Proxy.address(), USERNAME, PASSWORD)),

            new FailureTestItem("SOCKS5: authentication failure", DESTINATION, "authStatus: FAILURE",
                    new Socks5ProxyHandler(socks5Proxy.address(), BAD_USERNAME, BAD_PASSWORD)),

            new TimeoutTestItem("SOCKS5: timeout", new Socks5ProxyHandler(deadSocks5Proxy.address())),

            // HTTP + HTTPS + SOCKS5

            new SuccessTestItem("Single-chain: successful connection", DESTINATION,
                    new Socks5ProxyHandler(interSocks5Proxy.address()), // SOCKS5
                    clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT),
                    new HttpProxyHandler(interHttpsProxy.address()), // HTTPS
                    new HttpProxyHandler(interHttpProxy.address()), // HTTP
                    new HttpProxyHandler(anonHttpProxy.address())),

            // (HTTP + HTTPS + SOCKS5) * 2

            new SuccessTestItem("Double-chain: successful connection", DESTINATION,
                    new Socks5ProxyHandler(interSocks5Proxy.address()), // SOCKS5
                    clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT),
                    new HttpProxyHandler(interHttpsProxy.address()), // HTTPS
                    new HttpProxyHandler(interHttpProxy.address()), // HTTP
                    new Socks5ProxyHandler(interSocks5Proxy.address()), // SOCKS5
                    clientSslCtx.newHandler(PooledByteBufAllocator.DEFAULT),
                    new HttpProxyHandler(interHttpsProxy.address()), // HTTPS
                    new HttpProxyHandler(interHttpProxy.address()), // HTTP
                    new HttpProxyHandler(anonHttpProxy.address()))

    );//w  w  w .j a v a 2 s . co m

    // Convert the test items to the list of constructor parameters.
    List<Object[]> params = new ArrayList<Object[]>(items.size());
    for (Object i : items) {
        params.add(new Object[] { i });
    }

    // Randomize the execution order to increase the possibility of exposing failure
    // dependencies.
    Collections.shuffle(params);

    return params;
}

From source file:com.goodgamenow.source.serverquery.MasterClientBootstrap.java

License:Open Source License

public MasterClientBootstrap(EventLoopGroup eventLoopGroup, MasterQuery query,
        ChannelHandlerContext parentContext) {

    this.queryHandler = new MasterQueryHandler(query, parentContext);

    this.group(eventLoopGroup).channel(NioDatagramChannel.class)
            .option(ChannelOption.SO_BROADCAST, Boolean.TRUE)
            .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).handler(queryHandler);
}