Search in sources :

Example 1 with SchedulerKey

use of com.corundumstudio.socketio.scheduler.SchedulerKey in project netty-socketio by mrniko.

the class AckManager method onDisconnect.

@Override
public void onDisconnect(ClientHead client) {
    AckEntry e = ackEntries.remove(client.getSessionId());
    if (e == null) {
        return;
    }
    Set<Long> indexes = e.getAckIndexes();
    for (Long index : indexes) {
        AckCallback<?> callback = e.getAckCallback(index);
        if (callback != null) {
            callback.onTimeout();
        }
        SchedulerKey key = new AckSchedulerKey(Type.ACK_TIMEOUT, client.getSessionId(), index);
        scheduler.cancel(key);
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) SchedulerKey(com.corundumstudio.socketio.scheduler.SchedulerKey)

Example 2 with SchedulerKey

use of com.corundumstudio.socketio.scheduler.SchedulerKey in project netty-socketio by mrniko.

the class AckManager method scheduleTimeout.

private void scheduleTimeout(final long index, final UUID sessionId, AckCallback<?> callback) {
    if (callback.getTimeout() == -1) {
        return;
    }
    SchedulerKey key = new AckSchedulerKey(Type.ACK_TIMEOUT, sessionId, index);
    scheduler.scheduleCallback(key, new Runnable() {

        @Override
        public void run() {
            AckCallback<?> cb = removeCallback(sessionId, index);
            if (cb != null) {
                cb.onTimeout();
            }
        }
    }, callback.getTimeout(), TimeUnit.SECONDS);
}
Also used : AckCallback(com.corundumstudio.socketio.AckCallback) MultiTypeAckCallback(com.corundumstudio.socketio.MultiTypeAckCallback) SchedulerKey(com.corundumstudio.socketio.scheduler.SchedulerKey)

Example 3 with SchedulerKey

use of com.corundumstudio.socketio.scheduler.SchedulerKey in project netty-socketio by mrniko.

the class AuthorizeHandler method connect.

public void connect(UUID sessionId) {
    SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId);
    disconnectScheduler.cancel(key);
}
Also used : SchedulerKey(com.corundumstudio.socketio.scheduler.SchedulerKey)

Example 4 with SchedulerKey

use of com.corundumstudio.socketio.scheduler.SchedulerKey in project netty-socketio by mrniko.

the class ClientHead method cancelPingTimeout.

public void cancelPingTimeout() {
    SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId);
    disconnectScheduler.cancel(key);
}
Also used : SchedulerKey(com.corundumstudio.socketio.scheduler.SchedulerKey)

Example 5 with SchedulerKey

use of com.corundumstudio.socketio.scheduler.SchedulerKey in project netty-socketio by mrniko.

the class AuthorizeHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, ctx.channel());
    disconnectScheduler.cancel(key);
    if (msg instanceof FullHttpRequest) {
        FullHttpRequest req = (FullHttpRequest) msg;
        Channel channel = ctx.channel();
        QueryStringDecoder queryDecoder = new QueryStringDecoder(req.uri());
        if (!configuration.isAllowCustomRequests() && !queryDecoder.path().startsWith(connectPath)) {
            HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.BAD_REQUEST);
            channel.writeAndFlush(res).addListener(ChannelFutureListener.CLOSE);
            req.release();
            return;
        }
        List<String> sid = queryDecoder.parameters().get("sid");
        if (queryDecoder.path().equals(connectPath) && sid == null) {
            String origin = req.headers().get(HttpHeaderNames.ORIGIN);
            if (!authorize(ctx, channel, origin, queryDecoder.parameters(), req)) {
                req.release();
                return;
            }
        // forward message to polling or websocket handler to bind channel
        }
    }
    ctx.fireChannelRead(msg);
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) Channel(io.netty.channel.Channel) SchedulerKey(com.corundumstudio.socketio.scheduler.SchedulerKey) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse)

Aggregations

SchedulerKey (com.corundumstudio.socketio.scheduler.SchedulerKey)8 AckCallback (com.corundumstudio.socketio.AckCallback)1 MultiTypeAckCallback (com.corundumstudio.socketio.MultiTypeAckCallback)1 ClientHead (com.corundumstudio.socketio.handler.ClientHead)1 Channel (io.netty.channel.Channel)1 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 HttpResponse (io.netty.handler.codec.http.HttpResponse)1 QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1