Search in sources :

Example 1 with Waiter

use of com.generallycloud.baseio.concurrent.Waiter in project baseio by generallycloud.

the class HttpClient method request.

public synchronized HttpFuture request(HttpFuture future, long timeout) throws IOException {
    Waiter waiter = ioEventHandle.newWaiter();
    session.flush(future);
    if (waiter.await(timeout)) {
        throw new TimeoutException("timeout");
    }
    return (HttpFuture) waiter.getResponse();
}
Also used : Waiter(com.generallycloud.baseio.concurrent.Waiter) HttpFuture(com.generallycloud.baseio.codec.http11.future.HttpFuture) TimeoutException(com.generallycloud.baseio.TimeoutException)

Example 2 with Waiter

use of com.generallycloud.baseio.concurrent.Waiter in project baseio by generallycloud.

the class HttpIOEventHandle method accept.

@Override
public void accept(SocketSession session, Future future) throws Exception {
    HttpFuture f = (HttpFuture) future;
    Waiter waiter = this.waiter;
    if (waiter != null) {
        this.waiter = null;
        waiter.response(f);
    }
}
Also used : Waiter(com.generallycloud.baseio.concurrent.Waiter) HttpFuture(com.generallycloud.baseio.codec.http11.future.HttpFuture)

Example 3 with Waiter

use of com.generallycloud.baseio.concurrent.Waiter in project baseio by generallycloud.

the class AbstractSocketChannelConnector method initService.

@Override
protected void initService(ServerConfiguration configuration) throws IOException {
    String SERVER_HOST = configuration.getSERVER_HOST();
    int SERVER_PORT = configuration.getSERVER_PORT();
    this.waiter = new Waiter();
    this.serverAddress = new InetSocketAddress(SERVER_HOST, SERVER_PORT);
    this.connect(getServerSocketAddress());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Waiter(com.generallycloud.baseio.concurrent.Waiter)

Example 4 with Waiter

use of com.generallycloud.baseio.concurrent.Waiter in project baseio by generallycloud.

the class RedisClient method sendCommand.

private synchronized RedisNode sendCommand(byte[] command, byte[]... args) throws IOException {
    RedisFuture future = new RedisCmdFuture(context);
    future.writeCommand(command, args);
    Waiter waiter = ioEventHandle.newWaiter();
    session.flush(future);
    if (waiter.await(timeout)) {
        throw new TimeoutException("timeout");
    }
    return (RedisNode) waiter.getResponse();
}
Also used : Waiter(com.generallycloud.baseio.concurrent.Waiter) TimeoutException(com.generallycloud.baseio.TimeoutException)

Example 5 with Waiter

use of com.generallycloud.baseio.concurrent.Waiter in project baseio by generallycloud.

the class RedisIOEventHandle method accept.

@Override
public void accept(SocketSession session, Future future) throws Exception {
    RedisFuture f = (RedisFuture) future;
    Waiter waiter = this.waiter;
    if (waiter != null) {
        this.waiter = null;
        waiter.response(f);
    }
}
Also used : Waiter(com.generallycloud.baseio.concurrent.Waiter)

Aggregations

Waiter (com.generallycloud.baseio.concurrent.Waiter)6 TimeoutException (com.generallycloud.baseio.TimeoutException)2 HttpFuture (com.generallycloud.baseio.codec.http11.future.HttpFuture)2 JSONObject (com.alibaba.fastjson.JSONObject)1 ClosedChannelException (com.generallycloud.baseio.ClosedChannelException)1 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)1 SocketSession (com.generallycloud.baseio.component.SocketSession)1 OnFuture (com.generallycloud.baseio.container.OnFuture)1 Authority (com.generallycloud.baseio.container.authority.Authority)1 DatagramPacket (com.generallycloud.baseio.protocol.DatagramPacket)1 Future (com.generallycloud.baseio.protocol.Future)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1