Search in sources :

Example 16 with Channel

use of org.webpieces.nio.api.channels.Channel in project webpieces by deanhiller.

the class IntegTestClientNotRead method write.

private void write(Channel channel, String reason, final int counter) {
    log.info("write from client. reason=" + reason);
    byte[] data = new byte[2000];
    ByteBuffer buffer = ByteBuffer.wrap(data);
    CompletableFuture<Channel> write = channel.write(buffer);
    final int count = counter + 1;
    if (counter >= 100) {
        write.thenAccept(p -> write(channel, "wrote data from client", count)).whenComplete((r, e) -> finished(r, e));
    } else {
        write.thenAcceptAsync(p -> write(channel, "wrote data async", 0), executor).whenComplete((r, e) -> finished(r, e));
    }
}
Also used : Channel(org.webpieces.nio.api.channels.Channel) Logger(org.webpieces.util.logging.Logger) DataListener(org.webpieces.nio.api.handlers.DataListener) Executor(java.util.concurrent.Executor) AsyncConfig(org.webpieces.asyncserver.api.AsyncConfig) Timer(java.util.Timer) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncServer(org.webpieces.asyncserver.api.AsyncServer) InetSocketAddress(java.net.InetSocketAddress) AsyncServerMgrFactory(org.webpieces.asyncserver.api.AsyncServerMgrFactory) ByteBuffer(java.nio.ByteBuffer) Executors(java.util.concurrent.Executors) ChannelManager(org.webpieces.nio.api.ChannelManager) AsyncServerManager(org.webpieces.asyncserver.api.AsyncServerManager) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) LoggerFactory(org.webpieces.util.logging.LoggerFactory) TimerTask(java.util.TimerTask) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) Channel(org.webpieces.nio.api.channels.Channel) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Channel (org.webpieces.nio.api.channels.Channel)16 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)11 InetSocketAddress (java.net.InetSocketAddress)8 CompletableFuture (java.util.concurrent.CompletableFuture)7 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)7 ByteBuffer (java.nio.ByteBuffer)6 DataListener (org.webpieces.nio.api.handlers.DataListener)6 Executor (java.util.concurrent.Executor)5 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)5 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)5 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)5 ChannelManager (org.webpieces.nio.api.ChannelManager)5 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)5 BufferPool (org.webpieces.data.api.BufferPool)4 NamedThreadFactory (org.webpieces.util.threading.NamedThreadFactory)4 SelectableChannel (java.nio.channels.SelectableChannel)3 Executors (java.util.concurrent.Executors)3 Logger (org.webpieces.util.logging.Logger)3 LoggerFactory (org.webpieces.util.logging.LoggerFactory)3 ArrayList (java.util.ArrayList)2