HelloMessage handshakeMessage = fromJson(buffer.toString(), HelloMessageImpl.class);
if (!writeHandlerMap.containsKey(handshakeMessage.getUAID())) {
handshakeMessage = new HelloMessageImpl(UUIDUtil.newUAID());
}
final HelloResponse helloResponse = simplePushServer.handleHandshake(handshakeMessage);
sock.write(new Buffer(toJson(helloResponse)));
uaid = helloResponse.getUAID();
writeHandlerMap.put(uaid.toString(), sock.writeHandlerID());
lastAccessedMap.put(uaid.toString(), System.currentTimeMillis());
logger.info("UserAgent [" + uaid + "] handshake done");
break;
case REGISTER:
if (checkHandshakeCompleted(uaid)) {
final RegisterResponse response = simplePushServer.handleRegister(fromJson(buffer.toString(), RegisterMessageImpl.class), uaid);
sock.write(new Buffer(toJson(response)));
logger.info("UserAgent [" + uaid + "] Registered[" + response + "]");
}
break;
case UNREGISTER:
if (checkHandshakeCompleted(uaid)) {
final UnregisterMessage unregister = fromJson(buffer.toString(), UnregisterMessageImpl.class);
final UnregisterResponse response = simplePushServer.handleUnregister(unregister, uaid);
sock.write(new Buffer(toJson(response)));
logger.info("UserAgent [" + uaid + "] Unregistered[" + response.getChannelId() + "]");
}
break;
case ACK:
if (checkHandshakeCompleted(uaid)) {
final AckMessage ack = fromJson(buffer.toString(), AckMessageImpl.class);
simplePushServer.handleAcknowledgement(ack, uaid);
processUnacked(uaid);
}
break;
case PING:
sock.write(new Buffer(PingMessageImpl.JSON));
break;
default:
break;
}
updateAccessedTime(uaid);