use of org.webpieces.nio.api.channels.Channel 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);
}
use of org.webpieces.nio.api.channels.Channel in project webpieces by deanhiller.
the class IntegTestClientToEchoServer method testSoTimeoutOnSocket.
public void testSoTimeoutOnSocket() throws InterruptedException {
runEchoServer();
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(4444), listener);
connect.thenAccept(p -> runWriting(channel));
synchronized (this) {
this.wait();
}
}
use of org.webpieces.nio.api.channels.Channel in project webpieces by deanhiller.
the class IntegTestClientToEchoServer method write.
private void write(Channel channel, String reason) {
// counter++;
// if(counter % 100000 == 0)
// log.info("counter="+counter);
byte[] data = new byte[10240];
ByteBuffer buffer = ByteBuffer.wrap(data);
CompletableFuture<Channel> write = channel.write(buffer);
write.thenAccept(p -> write(channel, "wrote data from client")).whenComplete((r, e) -> finished(r, e)).exceptionally(e -> {
logIt(e);
return null;
});
}
use of org.webpieces.nio.api.channels.Channel in project webpieces by deanhiller.
the class ThreadChannel method connect.
@Override
public CompletableFuture<Channel> connect(SocketAddress addr, DataListener listener) {
DataListener threaded = new ThreadDataListener(listener, sessionExecutor);
CompletableFuture<Channel> future = tcpChannel.connect(addr, threaded);
//not need to synchronize the ChannelSession writes/reads
return future.thenApplyAsync(p -> this, executor);
}
use of org.webpieces.nio.api.channels.Channel 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));
}
}
Aggregations