Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous mode for WebSocket server #172

Closed
dimaa6 opened this issue Jan 13, 2022 · 1 comment · Fixed by #215
Closed

Asynchronous mode for WebSocket server #172

dimaa6 opened this issue Jan 13, 2022 · 1 comment · Fixed by #215

Comments

@dimaa6
Copy link

dimaa6 commented Jan 13, 2022

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.

@TVolden
Copy link
Member

TVolden commented Feb 26, 2022

Hi @dimaa6,

Sorry for my slow reply, I got my hands full with my thesis.

I have faced this problem before, see: #86
I think the solution you propose, would solve this dilemma. Good job!

Sincerely,
Thomas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants