// Extract the packet, hand it to UC client
byte[] buffer = Utils.byteBufferToByteArray(((ChannelBuffer) e.getMessage()).toByteBuffer());
// Parse received packet
ResUcdRecieve returnPacket = (ResUcdRecieve) protocol.parseRecievePacket(buffer);
ResUcdQuery queryPacket = null;
// Process returned packet in comparison with sent query packet
if(!(sendingPacket instanceof UrpQuery)) throw new RuntimeException("The sending packet is not of type UrpQuery.");
else {
// Cast based on command type of the query packet
UrpQuery uq = (UrpQuery) sendingPacket;
switch(uq.getCommandId()) {
case RES_UCD:
queryPacket = (ResUcdQuery) sendingPacket;
break;
default:
break;
}
}
Object rawData = null;
try {
rawData = protocol.processRecieve(returnPacket, queryPacket);
} catch (Exception ex) {
client.resolveFailed();
}
// If the rawData is null after processRecieve() just ignore the packet
if(rawData == null) {
return;
} else { // If it is not null hands the whole packet to client
ResUcdRecieve finalPacket = (ResUcdRecieve) rawData;
client.processReturnData(finalPacket);
// Check if this is cascade requested packet that need to be forwarded back
if(protocol.forwardPacketMap.containsKey(queryPacket.getQueryUcode())) {
assert(protocol.forwardPacketMap.remove(queryPacket.getQueryUcode()) + 1 == finalPacket.getSerialNumber());
protocol.returnCascadePacket(finalPacket);
}
}