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

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

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

Request.setObserveCancel介绍

[英]Sets CoAP's observe option to the value of 1 to proactively cancel.
[中]将CoAP的“观察”选项设置为1,以便主动取消。

代码示例

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

  1. /**
  2. * Verifies that only GET requests can be marked for canceling an observe relation.
  3. */
  4. @Test
  5. public void setObserveCancelFailsForNonGetRequest() {
  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.setObserveCancel();
  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/californium

  1. deregister.setURI(uri);
  2. deregister.setToken(request.getToken());
  3. deregister.setObserveCancel();
  4. request = deregister;
  5. request.send();

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

  1. /**
  2. * Send request with option "cancel observe" (GET with Observe=1).
  3. */
  4. private void sendCancelObserve() {
  5. Request request = this.request;
  6. Request cancel = Request.newGet();
  7. cancel.setDestination(request.getDestination());
  8. cancel.setDestinationPort(request.getDestinationPort());
  9. // use same Token
  10. cancel.setToken(request.getToken());
  11. // copy options, but set Observe to cancel
  12. cancel.setOptions(request.getOptions());
  13. cancel.setObserveCancel();
  14. // dispatch final response to the same message observers
  15. for (MessageObserver mo : request.getMessageObservers()) {
  16. cancel.addMessageObserver(mo);
  17. }
  18. endpoint.sendRequest(cancel);
  19. }

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

  1. /**
  2. * Send request with option "cancel observe" (GET with Observe=1).
  3. */
  4. private void sendCancelObserve() {
  5. Request request = this.request;
  6. Request cancel = Request.newGet();
  7. cancel.setDestination(request.getDestination());
  8. cancel.setDestinationPort(request.getDestinationPort());
  9. // use same Token
  10. cancel.setToken(request.getToken());
  11. // copy options, but set Observe to cancel
  12. cancel.setOptions(request.getOptions());
  13. cancel.setObserveCancel();
  14. // dispatch final response to the same message observers
  15. for (MessageObserver mo: request.getMessageObservers()) {
  16. cancel.addMessageObserver(mo);
  17. }
  18. endpoint.sendRequest(cancel);
  19. }

相关文章