Search in sources :

Example 1 with ChannelManager

use of org.webpieces.nio.api.ChannelManager in project webpieces by deanhiller.

the class WebServerModule method providesChanMgr.

@Provides
@Singleton
public ChannelManager providesChanMgr(WebServerConfig config, BufferPool pool) {
    String id = "webpieces";
    Executor executor = Executors.newFixedThreadPool(config.getNumFrontendServerThreads(), new NamedThreadFactory(id));
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
    ChannelManager chanMgr = factory.createMultiThreadedChanMgr(id, pool, executor);
    return chanMgr;
}
Also used : Executor(java.util.concurrent.Executor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ChannelManager(org.webpieces.nio.api.ChannelManager) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 2 with ChannelManager

use of org.webpieces.nio.api.ChannelManager in project webpieces by deanhiller.

the class IntegSingleRequest method createHttpClient.

public static Http2Socket createHttpClient(String id, boolean isHttp, InetSocketAddress addr) {
    BufferPool pool2 = new BufferCreationPool();
    HpackParser hpackParser = HpackParserFactory.createParser(pool2, false);
    Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
    ChannelManager mgr = factory.createMultiThreadedChanMgr("client", pool2, executor2);
    InjectionConfig injConfig = new InjectionConfig(hpackParser);
    String host = addr.getHostName();
    int port = addr.getPort();
    ForTestSslClientEngineFactory ssl = new ForTestSslClientEngineFactory();
    SSLEngine engine = ssl.createSslEngine(host, port);
    Http2Client client = Http2ClientFactory.createHttpClient(mgr, injConfig);
    Http2Socket socket;
    if (isHttp) {
        socket = client.createHttpSocket(id);
    } else {
        socket = client.createHttpsSocket(id, engine);
    }
    return socket;
}
Also used : HpackParser(com.webpieces.hpack.api.HpackParser) ChannelManager(org.webpieces.nio.api.ChannelManager) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) SSLEngine(javax.net.ssl.SSLEngine) InjectionConfig(com.webpieces.http2engine.api.client.InjectionConfig) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) BufferPool(org.webpieces.data.api.BufferPool) Executor(java.util.concurrent.Executor) Http2Socket(org.webpieces.http2client.api.Http2Socket) Http2Client(org.webpieces.http2client.api.Http2Client)

Example 3 with ChannelManager

use of org.webpieces.nio.api.ChannelManager in project webpieces by deanhiller.

the class IntegTestLocalhostThroughput method testSoTimeoutOnSocket.

public void testSoTimeoutOnSocket() throws InterruptedException {
    Executor executor = Executors.newFixedThreadPool(10, new NamedThreadFactory("serverThread"));
    BufferPool pool = new BufferCreationPool();
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
    ChannelManager mgr = factory.createMultiThreadedChanMgr("server", pool, executor);
    AsyncServerManager serverMgr = AsyncServerMgrFactory.createAsyncServer(mgr);
    AsyncServer server = serverMgr.createTcpServer(new AsyncConfig("tcpServer"), new IntegTestLocalhostServerListener());
    server.start(new InetSocketAddress(8080));
    BufferPool pool2 = new BufferCreationPool();
    DataListener listener = new ClientDataListener(pool2, recorder);
    Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
    TCPChannel channel = createClientChannel(pool2, executor2);
    //TCPChannel channel = createNettyChannel();
    recorder.start();
    CompletableFuture<Channel> connect = channel.connect(new InetSocketAddress(8080), listener);
    connect.thenAccept(p -> runWriting(channel));
    synchronized (this) {
        this.wait();
    }
}
Also used : ChannelManager(org.webpieces.nio.api.ChannelManager) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) InetSocketAddress(java.net.InetSocketAddress) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) AsyncServer(org.webpieces.asyncserver.api.AsyncServer) Channel(org.webpieces.nio.api.channels.Channel) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) AsyncConfig(org.webpieces.asyncserver.api.AsyncConfig) AsyncServerManager(org.webpieces.asyncserver.api.AsyncServerManager) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) Executor(java.util.concurrent.Executor) BufferPool(org.webpieces.data.api.BufferPool) DataListener(org.webpieces.nio.api.handlers.DataListener)

Example 4 with ChannelManager

use of org.webpieces.nio.api.ChannelManager in project webpieces by deanhiller.

the class BasChanSvcFactory method createMultiThreadedChanMgr.

@Override
public ChannelManager createMultiThreadedChanMgr(String threadName, BufferPool pool, Executor executor) {
    ChannelManager mgr = createSingleThreadedChanMgr(threadName, pool);
    ThreadedChannelService mgr2 = new ThreadedChannelService(mgr, executor);
    return new SslChannelService(mgr2, pool);
}
Also used : SslChannelService(org.webpieces.nio.impl.ssl.SslChannelService) ChannelManager(org.webpieces.nio.api.ChannelManager) ThreadedChannelService(org.webpieces.nio.impl.threading.ThreadedChannelService)

Example 5 with ChannelManager

use of org.webpieces.nio.api.ChannelManager in project webpieces by deanhiller.

the class IntegTestClientNotRead method testSoTimeoutOnSocket.

public void testSoTimeoutOnSocket() throws InterruptedException {
    BufferCreationPool pool = new BufferCreationPool();
    AsyncServerManager serverMgr = AsyncServerMgrFactory.createAsyncServer("server", pool);
    AsyncServer server = serverMgr.createTcpServer(new AsyncConfig("tcpServer"), new IntegTestClientNotReadListener());
    server.start(new InetSocketAddress(8080));
    BufferCreationPool pool2 = new BufferCreationPool();
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
    ChannelManager mgr = factory.createSingleThreadedChanMgr("client", pool2);
    TCPChannel channel = mgr.createTCPChannel("clientChan");
    log.info("client");
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            logBytesTxfrd();
        }
    }, 1000, 5000);
    CompletableFuture<Channel> connect = channel.connect(new InetSocketAddress(8080), new ClientDataListener());
    connect.thenAccept(p -> runWriting(channel));
    Thread.sleep(1000000000);
}
Also used : ChannelManager(org.webpieces.nio.api.ChannelManager) InetSocketAddress(java.net.InetSocketAddress) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) AsyncServer(org.webpieces.asyncserver.api.AsyncServer) Channel(org.webpieces.nio.api.channels.Channel) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) AsyncConfig(org.webpieces.asyncserver.api.AsyncConfig) AsyncServerManager(org.webpieces.asyncserver.api.AsyncServerManager) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) TimerTask(java.util.TimerTask)

Aggregations

ChannelManager (org.webpieces.nio.api.ChannelManager)13 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)12 Executor (java.util.concurrent.Executor)8 NamedThreadFactory (org.webpieces.util.threading.NamedThreadFactory)8 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)7 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)4 BufferPool (org.webpieces.data.api.BufferPool)4 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)4 HpackParser (com.webpieces.hpack.api.HpackParser)3 InjectionConfig (com.webpieces.http2engine.api.client.InjectionConfig)3 InetSocketAddress (java.net.InetSocketAddress)3 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)3 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)3 HttpParser (org.webpieces.httpparser.api.HttpParser)3 Http2Config (com.webpieces.http2engine.api.client.Http2Config)2 TimeImpl (com.webpieces.util.time.TimeImpl)2 Channel (org.webpieces.nio.api.channels.Channel)2 Provides (com.google.inject.Provides)1 Http2ServerEngineFactory (com.webpieces.http2engine.api.server.Http2ServerEngineFactory)1 TimerTask (java.util.TimerTask)1