Coder Social home page Coder Social logo

Comments (4)

sbernard31 avatar sbernard31 commented on August 29, 2024 1

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 😅

from java-coap.

szysas avatar szysas commented on August 29, 2024

Thanks for feedback. I agree than modifying transport context is really needed.
Thanks for spotting outdated readme. It is actually based on theses tests: https://github.com/open-coap/java-coap/blob/master/coap-core/src/test/java/protocolTests/UsageTest.java. Do you know any idea/tools how to verify if readme examples are up to date?

from java-coap.

sbernard31 avatar sbernard31 commented on August 29, 2024

Do you know any idea/tools how to verify if readme examples are up to date?

I had some ideas but not sure they really works :

  • I was thinking about using checkstyle with regexp ? (but probably not work)
  • Using this github actions ? https://github.com/marketplace/actions/markdown-autodocs
  • Using another supported language than markdown (e.g. reStructuredText or asciidoctor) which have include directive but it seems that github doesn't support it ...
  • Using github code import but I understand you need to create permalink each time ... (and rendering is not so good)
    // define subscription manager for observable resources
    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", observersManager.then(req ->
    CoapResponse.ok("21C").toFuture()
    ))
    )
    .build();
    observersManager.init(server);
    server.start();

So nothing great 😬

from java-coap.

szysas avatar szysas commented on August 29, 2024

I had some ideas but not sure they really works

Thanks

from java-coap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.