use of com.corundumstudio.socketio.AckCallback 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.AckCallback in project netty-socketio by mrniko.
the class AckManager method onAck.
@SuppressWarnings("unchecked")
public void onAck(SocketIOClient client, Packet packet) {
AckSchedulerKey key = new AckSchedulerKey(Type.ACK_TIMEOUT, client.getSessionId(), packet.getAckId());
scheduler.cancel(key);
AckCallback callback = removeCallback(client.getSessionId(), packet.getAckId());
if (callback == null) {
return;
}
if (callback instanceof MultiTypeAckCallback) {
callback.onSuccess(new MultiTypeArgs(packet.<List<Object>>getData()));
} else {
Object param = null;
List<Object> args = packet.getData();
if (!args.isEmpty()) {
param = args.get(0);
}
if (args.size() > 1) {
log.error("Wrong ack args amount. Should be only one argument, but current amount is: {}. Ack id: {}, sessionId: {}", args.size(), packet.getAckId(), client.getSessionId());
}
callback.onSuccess(param);
}
}
Aggregations