use of org.webpieces.nio.api.handlers.DataListener in project webpieces by deanhiller.
the class TestNewChannelManager method testBasic.
public void testBasic() throws Exception {
client1.bind(loopBackAnyPort);
InetSocketAddress remoteAddr = new InetSocketAddress(loopBack, srvrChannel.getLocalAddress().getPort());
FutureOperation future = client1.connect(remoteAddr);
future.setListener((OperationCallback) clientConnect);
clientConnect.expect("finished");
client1.registerForReads((DataListener) clientHandler);
//should return immediately since listener fired
future.waitForOperation();
serverHandler = MockObjectFactory.createMock(DataListener.class);
CalledMethod m = serverAccept.expect("connected");
serverTcpChannel = (Channel) m.getAllParams()[0];
serverTcpChannel.registerForReads((DataListener) serverHandler);
boolean isConnected = client1.isConnected();
assertTrue("Client should be connected", isConnected);
verifyDataPassing();
verifyTearDown();
}
use of org.webpieces.nio.api.handlers.DataListener 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.handlers.DataListener 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.handlers.DataListener in project webpieces by deanhiller.
the class BasTCPServerChannel method accept.
/* (non-Javadoc)
* @see api.biz.xsoftware.nio.TCPServerChannel#accept()
*/
public void accept(int newSocketNum) throws IOException {
try {
//special code...see information in close() method
if (isClosed())
return;
SocketChannel newChan = channel.accept();
if (newChan == null)
return;
newChan.configureBlocking(false);
org.webpieces.nio.api.testutil.chanapi.SocketChannel proxyChan = channelFactory.open(newChan);
SocketAddress remoteAddress = newChan.getRemoteAddress();
IdObject obj = new IdObject(getIdObject(), newSocketNum);
BasTCPChannel tcpChan = new BasTCPChannel(obj, proxyChan, remoteAddress, getSelectorManager(), pool);
log.trace(() -> tcpChan + "Accepted new incoming connection");
CompletableFuture<DataListener> connectFuture = connectionListener.connected(tcpChan, true);
connectFuture.thenAccept(l -> tcpChan.registerForReads(l));
} catch (Throwable e) {
log.error(this + "Failed to connect", e);
connectionListener.failed(this, e);
}
}
use of org.webpieces.nio.api.handlers.DataListener 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);
}
Aggregations