/** This method register a FermatTyrusPacketProcessor object with this server */ public void registerFermatPacketProcessor(FermatTyrusPacketProcessor fermatPacketProcessor) { // Validate if a previous list created if (packetProcessorsRegister.containsKey(fermatPacketProcessor.getFermatPacketType())) { /* * Add to the existing list */ packetProcessorsRegister .get(fermatPacketProcessor.getFermatPacketType()) .add(fermatPacketProcessor); } else { /* * Create a new list and add the fermatPacketProcessor */ CopyOnWriteArrayList<FermatTyrusPacketProcessor> fermatPacketProcessorList = new CopyOnWriteArrayList<>(); fermatPacketProcessorList.add(fermatPacketProcessor); /* * Add to the packetProcessorsRegister */ packetProcessorsRegister.put( fermatPacketProcessor.getFermatPacketType(), fermatPacketProcessorList); } }
@OnMessage public void onMessage(String fermatPacketEncode) { System.out.println(" --------------------------------------------------------------------- "); System.out.println( " WsCommunicationsTyrusCloudClientChannel - Starting method onMessage(String)"); // System.out.println(" WsCommunicationsTyrusCloudClientChannel - encode fermatPacket " + // fermatPacketEncode); FermatPacket fermatPacketReceive = null; /* * If the client is no register */ if (!isRegister) { System.out.println( " WsCommunicationsTyrusCloudClientChannel - decoding fermatPacket with temp-identity "); /** Decode the message with the temporal identity */ fermatPacketReceive = FermatPacketDecoder.decode(fermatPacketEncode, temporalIdentity.getPrivateKey()); } else { System.out.println( " WsCommunicationsTyrusCloudClientChannel - decoding fermatPacket with client-identity "); /** Decode the message with the client identity */ fermatPacketReceive = FermatPacketDecoder.decode(fermatPacketEncode, clientIdentity.getPrivateKey()); /* * Validate the signature */ validateFermatPacketSignature(fermatPacketReceive); } // System.out.println(" WsCommunicationsTyrusCloudClientChannel - decode fermatPacket " + // fermatPacketReceive.toJson()); // verify is packet supported if (packetProcessorsRegister.containsKey(fermatPacketReceive.getFermatPacketType())) { /* * Call the processors for this packet */ for (FermatTyrusPacketProcessor fermatPacketProcessor : packetProcessorsRegister.get(fermatPacketReceive.getFermatPacketType())) { /* * Processor make his job */ fermatPacketProcessor.processingPackage(fermatPacketReceive); } } else { System.out.println( " WsCommunicationsTyrusCloudClientChannel - Packet type " + fermatPacketReceive.getFermatPacketType() + "is not supported"); } }