-
Notifications
You must be signed in to change notification settings - Fork 180
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 execution #215
Conversation
Asynchronous execution
Hi @dimaa6, First of all, thank you for your contribution. Sincerely, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine
} | ||
|
||
@Override | ||
public boolean completePendingPromise(String id, Confirmation confirmation) throws UnsupportedFeatureException, OccurenceConstraintException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method only returns true or throws an exception. Should probably just make it void. This would also conform to the CQS principle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may return false if it did not find pending promise:
Java-OCA-OCPP/ocpp-common/src/main/java/eu/chargetime/ocpp/Session.java
Lines 251 to 256 in b6c0b59
synchronized (pendingPromises) { | |
promiseAction = pendingPromises.get(id); | |
if (promiseAction == null) return false; | |
// remove promise from store | |
pendingPromises.remove(id); | |
} |
Hi @dimaa6, I have merged it into the main. Thank you for the contribution, it really means a lot to me. Sincerely, |
Hi @dimaa6 I believe that when the server sends a message, a uniqueId is assigned to the request. The server needs the uniqueId when it calls "asyncCompleteRequest". Where is "setOcppMessageId" called when the message is sent? |
You mean this line? |
Thank you for your response. I believe this is the process upon receipt. An ID is generated when a message is sent. |
Yes, ID is generated when the request is sent, you have identified the line correctly. But I still don't understand the question. Let me try to provide the information I have. Session still handles the received message, code on server and client side is the same. And setOcppMessageId is called on receiving side, not the sending side. Then client code which handles the message will have the ID and will be able to call asyncCompleteRequest. Does this answer your question? |
I am sorry that my question is not clear. |
You may create a pull request with new method which will remove promise by ID, similarly to asyncCompleteRequest but without actually completing it. |
I might be understanding wrong, but in the example bellow (from OCPP 1.6 example) it seems like returning null means unsupported feature, not "I'll handle response later". Is this an outdated example or am I misunderstanding?
|
This pull request resolves #172 . It introduces ability to skip executing request by server or client immediately, and allows to complete it at later time by invoking new methods of
IClient
andIServer
interfaces:Changes are not breaking, existing code will continue to work without any need for modification. Usage of new methods and asynchronous mode are fully optional. The following diagram provides an example of using the asynchronous mode:
It also resolves #86 by allowing client to call
asyncCompleteRequest
inhandleTriggerMessageRequest
before sending a message requested byTriggerMessageRequest
, and finally returnnull
fromhandleTriggerMessageRequest
.One serious change is that in order to know OCPP message ID of the request in its handler, it has been included into every class which implemented
Request
interface. I enhancedRequest
interface withgetOcppMessageId
andsetOcppMessageId
methods, and implemented them in abstract classRequestWithId
which implementsRequest
. Then every class which formerly implementedRequest
interface now extendsRequestWithId
. Now handler implementation can simple callgetOcppMessageId
on the instance ofRequest
it got. I have taken measures to not includeocppMessageId
into serialized message, by introducingExclude
annotation.