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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations