Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cf-dev] A californium Resource which manages all children request

Hi,

I would like to know what is the best way to implement a CoapResource which handles all the request under its path.

I mean I create a CoapResource at /myResource and I want to handle all the request on /myResource/**/*.

Currently, in Leshan we do something like that :

@Override
public Resource getChild(String name) {
     return this;
}

But, I'm not sure this is the best way to do that...

The second point is that I would like to notify observer(at Coap Observer meaning) just for some given URI, for now we do that :

private ObserveRelationContainer observeRelations = new ObserveRelationContainer();

    @Override
    public void addObserveRelation(ObserveRelation relation) {
        super.addObserveRelation(relation);
        observeRelations.add(relation);
    }

    @Override
    public void removeObserveRelation(ObserveRelation relation) {
        super.removeObserveRelation(relation);
        observeRelations.remove(relation);
    }

    protected void notifyObserverRelationsForResource(String URI) {
        for (ObserveRelation relation : observeRelations) {
if (relation.getExchange().getRequest().getOptions().getUriPathString().equals(URI)) {
                relation.notifyObservers();
            }
        }
    }
But, this is clearly a crappy hack. (we could image that cf provide a way to do that. Instead of passing and URI we could imagine we pass a ExchangeFilter or a RelationFilter)

The full code is available here : https://github.com/jvermillard/leshan/blob/newclientapi/leshan-client/src/main/java/org/eclipse/leshan/client/californium/impl/ObjectResource.java

Thx

Simon.


Back to the top