Search in sources :

Example 1 with DataListener

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();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DataListener(org.webpieces.nio.api.handlers.DataListener) FutureOperation(org.webpieces.nio.api.handlers.FutureOperation) CalledMethod(biz.xsoftware.mock.CalledMethod)

Example 2 with DataListener

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();
    }
}
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 3 with DataListener

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();
    }
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) Executor(java.util.concurrent.Executor) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) InetSocketAddress(java.net.InetSocketAddress) Channel(org.webpieces.nio.api.channels.Channel) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) DataListener(org.webpieces.nio.api.handlers.DataListener) BufferCreationPool(org.webpieces.data.api.BufferCreationPool)

Example 4 with DataListener

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);
    }
}
Also used : ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) DataListener(org.webpieces.nio.api.handlers.DataListener) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 5 with DataListener

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);
}
Also used : Channel(org.webpieces.nio.api.channels.Channel) DataListener(org.webpieces.nio.api.handlers.DataListener)

Aggregations

DataListener (org.webpieces.nio.api.handlers.DataListener)13 InetSocketAddress (java.net.InetSocketAddress)5 ConnectionListener (org.webpieces.nio.api.handlers.ConnectionListener)5 Channel (org.webpieces.nio.api.channels.Channel)3 ByteBuffer (java.nio.ByteBuffer)2 Executor (java.util.concurrent.Executor)2 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)2 BufferPool (org.webpieces.data.api.BufferPool)2 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)2 NamedThreadFactory (org.webpieces.util.threading.NamedThreadFactory)2 CalledMethod (biz.xsoftware.mock.CalledMethod)1 Http2Config (com.webpieces.http2engine.api.client.Http2Config)1 InjectionConfig (com.webpieces.http2engine.api.client.InjectionConfig)1 IOException (java.io.IOException)1 PortUnreachableException (java.net.PortUnreachableException)1 SocketAddress (java.net.SocketAddress)1 NotYetConnectedException (java.nio.channels.NotYetConnectedException)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 Before (org.junit.Before)1