org.eclipse.californium.core.coap.Request.setObserve()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(252)

本文整理了Java中org.eclipse.californium.core.coap.Request.setObserve方法的一些代码示例,展示了Request.setObserve的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.setObserve方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.Request
类名称:Request
方法名:setObserve

Request.setObserve介绍

[英]Sets CoAP's observe option. If the target resource of this request responds with a success code and also sets the observe option, it will send more responses in the future whenever the resource's state changes.
[中]设置CoAP的观察选项。如果此请求的目标资源使用成功代码进行响应,并且还设置了“观察”选项,则将来每当资源的状态发生变化时,它将发送更多响应。

代码示例

代码示例来源:origin: eclipse/californium

  1. public CO06(String serverURI) {
  2. super(CO06.class.getSimpleName());
  3. // create the request
  4. Request request = new Request(Code.GET, Type.CON);
  5. // set Observe option
  6. request.setObserve();
  7. // set the parameters and execute the request
  8. executeRequest(request, serverURI, RESOURCE_URI);
  9. }

代码示例来源:origin: eclipse/californium

  1. public CO04(String serverURI) {
  2. super(CO04.class.getSimpleName());
  3. // create the request
  4. Request request = new Request(Code.GET, Type.CON);
  5. // set Observe option
  6. request.setObserve();
  7. // set the parameters and execute the request
  8. executeRequest(request, serverURI, RESOURCE_URI);
  9. }

代码示例来源:origin: eclipse/californium

  1. public CO09(String serverURI) {
  2. super(CO09.class.getSimpleName());
  3. // create the request
  4. Request request = new Request(Code.GET, Type.CON);
  5. // request.setToken(TokenManager.getInstance().acquireToken(false));
  6. request.setObserve();
  7. // set the parameters and execute the request
  8. executeRequest(request, serverURI, RESOURCE_URI);
  9. }

代码示例来源:origin: eclipse/californium

  1. public CO02_05(String serverURI) {
  2. super(CO02_05.class.getSimpleName());
  3. // create the request
  4. Request request = new Request(Code.GET, Type.NON);
  5. // set Observe option
  6. request.setObserve();
  7. // set the parameters and execute the request
  8. executeRequest(request, serverURI, RESOURCE_URI);
  9. }

代码示例来源:origin: eclipse/californium

  1. public CO07(String serverURI) {
  2. super(CO07.class.getSimpleName());
  3. // create the request
  4. Request request = new Request(Code.GET, Type.CON);
  5. // request.setToken(TokenManager.getInstance().acquireToken());
  6. request.setObserve();
  7. // set the parameters and execute the request
  8. executeRequest(request, serverURI, RESOURCE_URI);
  9. }

代码示例来源:origin: eclipse/californium

  1. public CO08(String serverURI) {
  2. super(CO08.class.getSimpleName());
  3. // create the request
  4. Request request = new Request(Code.GET, Type.CON);
  5. // request.setToken(TokenManager.getInstance().acquireToken(false));
  6. request.setObserve();
  7. // set the parameters and execute the request
  8. executeRequest(request, serverURI, RESOURCE_URI);
  9. }

代码示例来源:origin: eclipse/californium

  1. public CO01_12(String serverURI) {
  2. super(CO01_12.class.getSimpleName());
  3. // create the request
  4. Request request = new Request(Code.GET, Type.CON);
  5. // set Observe option
  6. request.setObserve();
  7. // set the parameters and execute the request
  8. executeRequest(request, serverURI, RESOURCE_URI);
  9. }

代码示例来源:origin: eclipse/californium

  1. public CO10(String serverURI) {
  2. super(CO10.class.getSimpleName());
  3. // create the request
  4. Request request = new Request(Code.GET, Type.CON);
  5. // set Observe option
  6. request.setObserve();
  7. // set the parameters and execute the request
  8. executeRequest(request, serverURI, RESOURCE_URI);
  9. }

代码示例来源:origin: eclipse/californium

  1. /**
  2. * Sends an observe request and waits until it has been established
  3. * whereupon the specified handler is invoked when a notification arrives.
  4. *
  5. * @param handler the Response handler
  6. * @return the CoAP observe relation
  7. */
  8. public CoapObserveRelation observeAndWait(CoapHandler handler) {
  9. Request request = newGet().setURI(uri).setObserve();
  10. return observeAndWait(request, handler);
  11. }

代码示例来源:origin: org.eclipse.californium/californium-core

  1. /**
  2. * Sends an observe request and waits until it has been established
  3. * whereupon the specified handler is invoked when a notification arrives.
  4. *
  5. * @param handler the Response handler
  6. * @return the CoAP observe relation
  7. */
  8. public CoapObserveRelation observeAndWait(CoapHandler handler) {
  9. Request request = Request.newGet().setURI(uri).setObserve();
  10. return observeAndWait(request, handler);
  11. }

代码示例来源:origin: eclipse/californium

  1. /**
  2. * Sends an observe request and invokes the specified handler each time
  3. * a notification arrives.
  4. *
  5. * @param handler the Response handler
  6. * @return the CoAP observe relation
  7. */
  8. public CoapObserveRelation observe(CoapHandler handler) {
  9. Request request = newGet().setURI(uri).setObserve();
  10. return observe(request, handler);
  11. }

代码示例来源:origin: org.eclipse.californium/californium-core

  1. /**
  2. * Sends an observe request and invokes the specified handler each time
  3. * a notification arrives.
  4. *
  5. * @param handler the Response handler
  6. * @return the CoAP observe relation
  7. */
  8. public CoapObserveRelation observe(CoapHandler handler) {
  9. Request request = Request.newGet().setURI(uri).setObserve();
  10. return observe(request, handler);
  11. }

代码示例来源:origin: org.eclipse.leshan/leshan-server-cf

  1. @Override
  2. public void visit(ObserveRequest request) {
  3. coapRequest = Request.newGet();
  4. coapRequest.setObserve();
  5. setTarget(coapRequest, destination, request.getPath());
  6. }

代码示例来源:origin: eclipse/californium

  1. /**
  2. * Sends an observe request with the specified Accept option and invokes the
  3. * specified handler each time a notification arrives.
  4. *
  5. * @param handler the Response handler
  6. * @param accept the Accept option
  7. * @return the CoAP observe relation
  8. */
  9. public CoapObserveRelation observe(CoapHandler handler, int accept) {
  10. Request request = newGet().setURI(uri).setObserve();
  11. return observe(accept(request, accept), handler);
  12. }

代码示例来源:origin: org.eclipse.californium/californium-core

  1. /**
  2. * Sends an observe request with the specified Accept option and invokes the
  3. * specified handler each time a notification arrives.
  4. *
  5. * @param handler the Response handler
  6. * @param accept the Accept option
  7. * @return the CoAP observe relation
  8. */
  9. public CoapObserveRelation observe(CoapHandler handler, int accept) {
  10. Request request = Request.newGet().setURI(uri).setObserve();
  11. return observe(accept(request, accept), handler);
  12. }

代码示例来源:origin: eclipse/californium

  1. /**
  2. * Sends an observe request with the specified Accept option and waits until
  3. * it has been established whereupon the specified handler is invoked when a
  4. * notification arrives.
  5. *
  6. * @param handler the Response handler
  7. * @param accept the Accept option
  8. * @return the CoAP observe relation
  9. */
  10. public CoapObserveRelation observeAndWait(CoapHandler handler, int accept) {
  11. Request request = newGet().setURI(uri).setObserve();
  12. request.getOptions().setAccept(accept);
  13. return observeAndWait(request, handler);
  14. }

代码示例来源:origin: org.eclipse.californium/californium-core

  1. /**
  2. * Sends an observe request with the specified Accept option and waits until
  3. * it has been established whereupon the specified handler is invoked when a
  4. * notification arrives.
  5. *
  6. * @param handler the Response handler
  7. * @param accept the Accept option
  8. * @return the CoAP observe relation
  9. */
  10. public CoapObserveRelation observeAndWait(CoapHandler handler, int accept) {
  11. Request request = Request.newGet().setURI(uri).setObserve();
  12. request.getOptions().setAccept(accept);
  13. return observeAndWait(request, handler);
  14. }

代码示例来源:origin: eclipse/californium

  1. private static Exchange sendObserveRequest(final UdpMatcher matcher) {
  2. Request request = Request.newGet();
  3. request.setDestination(dest.getAddress());
  4. request.setDestinationPort(dest.getPort());
  5. request.setObserve();
  6. Exchange exchange = new Exchange(request, Origin.LOCAL);
  7. matcher.sendRequest(exchange, request);
  8. return exchange;
  9. }

代码示例来源:origin: eclipse/californium

  1. /**
  2. * Verifies that only GET requests can be marked for establishing an observe relation.
  3. */
  4. @Test
  5. public void setObserveFailsForNonGetRequest() {
  6. Code[] illegalCodes = new Code[]{ Code.DELETE, Code.POST, Code.PUT };
  7. for (Code code : illegalCodes) {
  8. try {
  9. Request req = new Request(code);
  10. req.setObserve();
  11. fail("should not be able to set observe option on " + code + " request");
  12. } catch (IllegalStateException e) {
  13. // as expected
  14. }
  15. }
  16. }

代码示例来源:origin: eclipse/leshan

  1. @Override
  2. public void visit(ObserveRequest request) {
  3. coapRequest = Request.newGet();
  4. if (request.getContentFormat() != null)
  5. coapRequest.getOptions().setAccept(request.getContentFormat().getCode());
  6. coapRequest.setObserve();
  7. setTarget(coapRequest, request.getPath());
  8. // add context info to the observe request
  9. coapRequest.setUserContext(ObserveUtil.createCoapObserveRequestContext(endpoint, registrationId, request));
  10. }

相关文章