use of org.webpieces.nio.api.channels.Channel in project webpieces by deanhiller.
the class HttpSocketImpl method actuallySendRequest.
private void actuallySendRequest(CompletableFuture<HttpChunkWriter> future, HttpRequest request, HttpResponseListener listener) {
HttpResponseListener l = new CatchResponseListener(listener);
ByteBuffer wrap = parser.marshalToByteBuffer(state, request);
//put this on the queue before the write to be completed from the listener below
responsesToComplete.offer(l);
log.info("sending request now. req=" + request.getRequestLine().getUri());
CompletableFuture<Channel> write = channel.write(wrap);
write.handle((c, t) -> chainToFuture(c, t, future));
}
use of org.webpieces.nio.api.channels.Channel in project webpieces by deanhiller.
the class IntegTestLocalhostThroughput method write.
private void write(Channel channel, String reason) {
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 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();
}
}
use of org.webpieces.nio.api.channels.Channel in project webpieces by deanhiller.
the class BasChannelImpl method write.
@Override
public CompletableFuture<Channel> write(ByteBuffer b) {
if (b.remaining() == 0)
throw new IllegalArgumentException("buffer has no data");
else if (!getSelectorManager().isRunning())
throw new IllegalStateException(this + "ChannelManager must be running and is stopped");
else if (isClosed) {
if (isRemoteEndInitiateClose)
throw new NioClosedChannelException(this + "Client cannot write after the remote end closed the socket");
else
throw new NioClosedChannelException(this + "Your Application cannot write after YOUR Application closed the socket");
} else if (doNotAllowWrites)
throw new IllegalStateException("This channel is in a failed state. " + "failure functions were called so look for exceptions from them");
apiLog.trace(() -> this + "Basic.write");
CompletableFuture<Channel> future = new CompletableFuture<Channel>();
boolean wroteAllData = writeSynchronized(b, future);
if (wroteAllData) {
//since we didn't switch and were not in this mode, complete the action outside sync block
pool.releaseBuffer(b);
future.complete(this);
log.trace(() -> this + " wrote bytes on client thread");
} else {
log.trace(() -> this + "sent write to queue");
}
return future;
}
use of org.webpieces.nio.api.channels.Channel in project webpieces by deanhiller.
the class EchoServer method stop.
public void stop() throws IOException, InterruptedException {
srvrChannel.closeServerChannel();
for (int i = 0; i < sockets.size(); i++) {
Channel channel = sockets.get(i);
channel.oldClose();
}
chanMgr.stop();
}
Aggregations