本文整理汇总了Java中org.eclipse.californium.core.server.resources.Resource类的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Resource类属于org.eclipse.californium.core.server.resources包,在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setName
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
public synchronized void setName(String name) {
if (name == null)
throw new NullPointerException();
String old = this.name;
// adjust parent if in tree
Resource parent = getParent();
if (parent!=null) {
synchronized (parent) {
parent.delete(this);
this.name = name;
parent.add(this);
}
} else {
this.name = name;
}
adjustChildrenPath();
for (ResourceObserver obs:observers)
obs.changedName(old);
}
示例2: deliverRequest
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
@Override
public void deliverRequest(final Exchange exchange) {
Request request = exchange.getRequest();
List<String> path = request.getOptions().getUriPath();
final Resource resource = findResource(path);
if (resource != null) {
checkForObserveOption(exchange, resource);
// Get the executor and let it process the request
Executor executor = resource.getExecutor();
if (executor != null) {
exchange.setCustomExecutor();
executor.execute(new Runnable() {
public void run() {
resource.handleRequest(exchange);
} });
} else {
resource.handleRequest(exchange);
}
} else {
LOGGER.info("Did not find resource " + path.toString() + " requested by " + request.getSource()+":"+request.getSourcePort());
exchange.sendResponse(new Response(ResponseCode.NOT_FOUND));
}
}
示例3: serializeTree
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
public static void serializeTree(Resource resource, List<String> queries, StringBuilder buffer) {
// add the current resource to the buffer
if (resource.isVisible()
&& LinkFormat.matches(resource, queries)) {
buffer.append(LinkFormat.serializeResource(resource));
}
// sort by resource name
List<Resource> childs = new ArrayList<Resource>(resource.getChildren());
Collections.sort(childs, new Comparator<Resource>() {
@Override
public int compare(Resource o1, Resource o2) {
return o1.getName().compareTo(o2.getName());
}
});
for (Resource child:childs) {
serializeTree(child, queries, buffer);
}
}
示例4: CoAPServer
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
public CoAPServer(int port, RESTHandler root)
{
server = new CoapServer(port) {
@Override
protected Resource createRoot()
{
return new CoAPRESTResource(root);
}
};
}
示例5: addRec
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
protected void addRec(String path, Resource resource, Resource parent) {
for (Resource r : parent.getChildren()) {
if (path.contains(path(r))) {
addRec(path, resource, r);
return;
}
}
parent.add(resource);
}
示例6: deleteRec
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
protected void deleteRec(String path, Resource parent) {
if (path(parent).equals(path)) {
parent.getParent().remove(parent);
return;
}
for (Resource r : parent.getChildren()) {
if (path.contains(path(r))) {
deleteRec(path, r);
return;
}
}
}
示例7: ObserveRelation
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
/**
* Constructs a new observe relation.
*
* @param endpoint the observing endpoint
* @param resource the observed resource
* @param exchange the exchange that tries to establish the observe relation
*/
public ObserveRelation(ObservingEndpoint endpoint, Resource resource, Exchange exchange) {
if (endpoint == null)
throw new NullPointerException();
if (resource == null)
throw new NullPointerException();
if (exchange == null)
throw new NullPointerException();
this.endpoint = endpoint;
this.resource = resource;
this.exchange = exchange;
this.established = false;
this.key = getSource().toString() + "#" + exchange.getRequest().getTokenString();
}
示例8: CoapResource
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
/**
* Constructs a new resource with the specified name and makes it visible to
* clients if the flag is true.
*
* @param name the name
* @param visible if the resource is visible
*/
public CoapResource(String name, boolean visible) {
this.name = name;
this.path = "";
this.visible = visible;
this.attributes = new ResourceAttributes();
this.children = new ConcurrentHashMap<String, Resource>();
this.observers = new CopyOnWriteArrayList<ResourceObserver>();
this.observeRelations = new ObserveRelationContainer();
this.notificationOrderer = new ObserveNotificationOrderer();
}
示例9: add
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
@Override
public synchronized void add(Resource child) {
if (child.getName() == null)
throw new NullPointerException("Child must have a name");
if (child.getParent() != null)
child.getParent().delete(child);
children.put(child.getName(), child);
child.setParent(this);
for (ResourceObserver obs:observers)
obs.addedChild(child);
}
示例10: delete
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
@Override
public synchronized boolean delete(Resource child) {
Resource deleted = delete(child.getName());
if (deleted == child) {
child.setParent(null);
child.setPath(null);
for (ResourceObserver obs : observers)
obs.removedChild(child);
return true;
}
return false;
}
示例11: findResource
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
/**
* Searches in the resource tree for the specified path. A parent resource
* may accept requests to subresources, e.g., to allow addresses with
* wildcards like <code>coap://example.com:5683/devices/*</code>
*
* @param list the path as list of resource names
* @return the resource or null if not found
*/
private Resource findResource(List<String> list) {
LinkedList<String> path = new LinkedList<String>(list);
Resource current = root;
while (!path.isEmpty() && current != null) {
String name = path.removeFirst();
current = current.getChild(name);
if(current != null && current.isAllChildFilter()) {
break;
}
}
return current;
}
示例12: serializeResource
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
public static StringBuilder serializeResource(Resource resource) {
StringBuilder buffer = new StringBuilder();
buffer.append("<")
.append(resource.getPath())
.append(resource.getName())
.append(">")
.append(LinkFormat.serializeAttributes(resource.getAttributes()))
.append(",");
return buffer;
}
示例13: add
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
/**
* Add a resource to the server.
* @param resources the resource(s)
* @return the server
*/
@Override
public CoapServer add(Resource... resources) {
for (Resource r:resources)
root.add(r);
return this;
}
示例14: doStart
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
super.doStart();
String path = endpoint.getUri().getPath();
if (path.startsWith("/")) {
path = path.substring(1);
}
Resource cr = endpoint.getCoapServer().getRoot();
while (!path.isEmpty()) {
int idx = path.indexOf('/');
String part1 = path;
if (idx != -1) {
part1 = path.substring(0, idx);
path = path.substring(idx + 1);
} else {
path = "";
}
Resource child = cr.getChild(part1);
if (child == null) {
child = new CamelCoapResource(part1, this);
cr.add(child);
cr = child;
} else if (path.isEmpty()) {
((CamelCoapResource)child).addConsumer(this);
} else {
cr = child;
}
}
}
示例15: discoverTree
import org.eclipse.californium.core.server.resources.Resource; //导入依赖的package包/类
/**
* Get all the resources hosted by this server. (Could be done by accessing
* /.well-known/core (COAP Bug))
*
* @return
*/
String discoverTree() {
StringBuilder buffer = new StringBuilder();
for (Resource child : server.getRoot().getChildren()) {
LinkFormat.serializeTree(child, null, buffer);
}
// remove last comma ',' of the buffer
if (buffer.length() > 1)
buffer.delete(buffer.length() - 1, buffer.length());
return buffer.toString();
}