Search in sources :

Example 1 with AsyncConfig

use of org.webpieces.asyncserver.api.AsyncConfig 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 2 with AsyncConfig

use of org.webpieces.asyncserver.api.AsyncConfig 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)

Example 3 with AsyncConfig

use of org.webpieces.asyncserver.api.AsyncConfig in project webpieces by deanhiller.

the class TestBasicSslClientServer method testBasic.

@Test
public void testBasic() throws InterruptedException {
    pool = new BufferCreationPool();
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
    ChannelManager mgr = factory.createSingleThreadedChanMgr("sslChanMgr", pool);
    AsyncServerManager svrFactory = AsyncServerMgrFactory.createAsyncServer(mgr);
    SSLEngineFactoryForTest f = new SSLEngineFactoryForTest();
    InetSocketAddress addr = new InetSocketAddress("localhost", 0);
    AsyncServer svr = svrFactory.createTcpServer(new AsyncConfig("sslTcpSvr"), new SvrDataListener(), f);
    svr.start(addr);
    InetSocketAddress bound = svr.getUnderlyingChannel().getLocalAddress();
    System.out.println("port=" + bound.getPort());
    TCPChannel channel = mgr.createTCPChannel("client", f.createEngineForSocket());
    CompletableFuture<Channel> connect = channel.connect(bound, new ClientListener());
    connect.thenAccept(c -> writeData(c));
    synchronized (pool) {
        while (values.size() < 10) pool.wait();
    }
    for (int i = 0; i < values.size(); i++) {
        Assert.assertEquals(new Integer(i), values.get(i));
    }
}
Also used : 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) Test(org.junit.Test)

Example 4 with AsyncConfig

use of org.webpieces.asyncserver.api.AsyncConfig in project webpieces by deanhiller.

the class IntegTestEchoClientToOurServer method testSoTimeoutOnSocket.

public void testSoTimeoutOnSocket() throws InterruptedException {
    EchoClient client = new EchoClient();
    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));
    client.start(8080);
    synchronized (this) {
        this.wait();
    }
}
Also used : Executor(java.util.concurrent.Executor) BufferPool(org.webpieces.data.api.BufferPool) ChannelManager(org.webpieces.nio.api.ChannelManager) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) InetSocketAddress(java.net.InetSocketAddress) AsyncServer(org.webpieces.asyncserver.api.AsyncServer) AsyncConfig(org.webpieces.asyncserver.api.AsyncConfig) AsyncServerManager(org.webpieces.asyncserver.api.AsyncServerManager) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)4 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)4 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)4 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)4 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)4 ChannelManager (org.webpieces.nio.api.ChannelManager)3 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)3 Channel (org.webpieces.nio.api.channels.Channel)3 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)3 Executor (java.util.concurrent.Executor)2 BufferPool (org.webpieces.data.api.BufferPool)2 NamedThreadFactory (org.webpieces.util.threading.NamedThreadFactory)2 TimerTask (java.util.TimerTask)1 Test (org.junit.Test)1 DataListener (org.webpieces.nio.api.handlers.DataListener)1