-
Notifications
You must be signed in to change notification settings - Fork 6
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
New CoapRequest / CoapResponse Builder API feedback #73
Comments
Not directly linked but I'm think that some part of the README was not updated with the new API : - // (optional) set custom observation relation store, for example one that will use external storage
+ // (optional) set custom observations store, for example one that will use external storage
- .observationRelationsStore(new HashMapObservationRelations())
+ .observationsStore(new HashMapObservationsStore()) -// define subscription manager for observable resources
+// define observers manager for observable resources
-InboundSubscriptionManager subscriptionManager = new InboundSubscriptionManager();
+ObserversManager observersManager = new ObserversManager();
server = CoapServer.builder()
// configure with plain text UDP transport, listening on port 5683
.transport(new DatagramSocketTransport(5683))
// define routing
// (note that each resource function is a `Service` type and can be decorated/transformed with `Filter`)
.route(RouterService.builder()
.get("/.well-known/core", req ->
CoapResponse.ok("</sensors/temperature>", MediaTypes.CT_APPLICATION_LINK__FORMAT).toFuture()
)
.post("/actuators/switch", req -> {
// ...
return coapResponse(Code.C204_CHANGED).toFuture();
})
// observable resource
- .get("/sensors/temperature", subscriptionManager.then(req ->
+ .get("/sensors/temperature", observersManager.then(req ->
- completedFuture(CoapResponse.ok("21C"))
+ CoapResponse.ok("21C").toFuture())
))
)
.build();
observersManager.init(server); I didn't test/execute the code, so probably deserve a double check 😅 |
Thanks for feedback. I agree than modifying transport context is really needed. |
I had some ideas but not sure they really works :
So nothing great 😬 |
Thanks |
I updated Leshan code to use the new java-coap API.
I think the API is largely better now 👍
Only issue I faced was when I wanted to modify a
CoapRequest
to add element inTransportContext
.I didn't find better way than :
A solution to avoid the verbose
coapRequest
creation could be #68 (comment) and so here this could look like :Maybe we could also add a method to modify transportContext in the builder ? something like :
Note that:
with*(...)
methods a first time. (if you think this is too soon)modify()
method probably also makes sense forCoapResponse
(If you are curious the whole migration change are available at : eclipse-leshan/leshan@c2f8232)
The text was updated successfully, but these errors were encountered: