Java-OCA-OCPP
Java-OCA-OCPP copied to clipboard
Asynchronous mode for WebSocket server
In larger scale deployment, it might be desirable to decouple communication from business logic, and use queueing/streaming to exchange messages between communication and business logic layers. Current model makes it possible, but with the cost of implementing asynchronous logic in implementation of *EventHandler interface.
I propose to add the asynchronous logic of handling requests sent to the server in the library itself. Let's consider example: interface ServerCoreEventHandler has method handleBootNotificationRequest, which returns BootNotificationConfirmation. Library code expects the method to return result synchronously. SimplePromiseFulfiller assumes confirmation is always returned, and completes promise passing it the confirmation. To allow asynchronous execution, handleBootNotificationRequest will return null, indicating that result is not available immediately. In such case, SimplePromiseFulfiller will not complete the promise. Internally, server will store the promise keyed by session id and message id. Once client library (client means not the client of OCPP server, but library which utilizes Java-OCA-OCPP) completes handling the request in whatever way suits its needs, it calls new method JSONServer.completeRequestAsync(UUID sessionIndex, String id, Confirmation confirmation). This method will find stored promise by (sessionIndex, id) key, complete it and remove from storage.
Please let me know if this enhancement is a good idea. Once you confirm, I will start implementing it.
Hi @dimaa6,
Sorry for my slow reply, I got my hands full with my thesis.
I have faced this problem before, see: https://github.com/ChargeTimeEU/Java-OCA-OCPP/issues/86 I think the solution you propose, would solve this dilemma. Good job!
Sincerely, Thomas