public interface Resource
Root | |-- foo | `-- bar | `-- balFor resource bal it holds that
bal.getName() equals "bal" bal.getPath() equals "/foo/bar/" bal.getURI() equals "/foo/bar/bal"
A resource is able to respond to CoAP requests. The requests are contained in
an instance of type Exchange
that contains additional information
about the current exchange. The request will always be a complete request and
not only a block as defined in the CoAP draft (
http://tools.ietf.org/html/draft-ietf-core-block-12)
When a request arrives at the server, the ServerMessageDeliverer
searches in the resource tree for the destination resource. It travels down
the resource tree by looking for one element of the destination URI after
another and by calling the method getChild(String)
on each element.
It is allowed to override this method and to return an arbitrary resource.
This allows for instance to serve URIs with wildcards or delegate requests to
any sub-URI to the same resource.
A resource can have its own Executor
. If a resource has such an
executor, all requests will be handled by it. Otherwise, the request will
be executed on the executor of the parent or transitively the first ancestor
that defines its own executor. If no resource up to the root defines its own
executor, the currently executing thread will handle the request. A class
that implements this interface can export further methods to allow the
execution of code on the resource's executor. See CoapResource
for an
example.
Modifier and Type | Interface and Description |
---|---|
static class |
Resource.ResourceTreeBuilder |
Modifier and Type | Method and Description |
---|---|
void |
add(Resource child)
Adds the specified resource as child.
|
void |
addObserver(ResourceObserver observer)
Adds the specified ResourceObserver.
|
void |
addObserveRelation(ObserveRelation relation)
Adds the specified CoAP observe relation.
|
ResourceAttributes |
getAttributes()
Gets the attributes of this resource.
|
Resource |
getChild(java.lang.String name)
Gets the child with the specified name.
|
java.util.Collection<Resource> |
getChildren()
Gets all child resources.
|
java.util.List<Endpoint> |
getEndpoints()
Gets the endpoints this resource is bound to.
|
java.util.concurrent.ExecutorService |
getExecutor()
Gets the executor of this resource.
|
java.lang.String |
getName()
Gets the name of the resource.
|
Resource |
getParent()
Gets the parent of this resource.
|
java.lang.String |
getPath()
Gets the path to the resource which is equal to the URI of its parent
plus a slash.
|
java.lang.String |
getURI()
Gets the URI of the resource.
|
void |
handleRequest(Exchange exchange)
Handles the request from the specified exchange.
|
boolean |
isCachable()
Checks if is the URI of the resource can be cached.
|
boolean |
isObservable()
Checks if this resource is observable by remote CoAP clients.
|
boolean |
isVisible()
Checks if the resource is visible to remote CoAP clients.
|
boolean |
remove(Resource child)
Removes the the specified child.
|
void |
removeObserver(ResourceObserver observer)
Removes the the specified observer.
|
void |
removeObserveRelation(ObserveRelation relation)
Removes the specified CoAP observe relation.
|
void |
setName(java.lang.String name)
Sets the name of the resource.
|
void |
setParent(Resource parent)
Sets the parent of this resource.
|
void |
setPath(java.lang.String path)
Sets the path of the resource.
|
void handleRequest(Exchange exchange)
exchange
- the exchange with the requestjava.lang.String getName()
void setName(java.lang.String name)
name
- the new namejava.lang.String getPath()
void setPath(java.lang.String path)
path
- the new pathjava.lang.String getURI()
boolean isVisible()
boolean isCachable()
boolean isObservable()
ResourceAttributes getAttributes()
void add(Resource child)
child
- the childboolean remove(Resource child)
child
- the childjava.util.Collection<Resource> getChildren()
Resource getChild(java.lang.String name)
name
- the nameResource getParent()
void setParent(Resource parent)
parent
- the new parentvoid addObserver(ResourceObserver observer)
addObserveRelation(ObserveRelation)
. ResourceObserver simply is
the observer pattern used in Java to observe a certain object.observer
- the observervoid removeObserver(ResourceObserver observer)
observer
- the observervoid addObserveRelation(ObserveRelation relation)
relation
- the relationvoid removeObserveRelation(ObserveRelation relation)
relation
- the relationjava.util.concurrent.ExecutorService getExecutor()
java.util.List<Endpoint> getEndpoints()