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

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

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

Request.getMessageObservers介绍

暂无

代码示例

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

  1. /**
  2. * Sets the response.
  3. *
  4. * @param response
  5. * the new response
  6. */
  7. public void setResponse(Response response) {
  8. synchronized (this) {
  9. this.response = response;
  10. notifyAll();
  11. }
  12. for (MessageObserver handler : getMessageObservers()) {
  13. handler.onResponse(response);
  14. }
  15. }

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

  1. /**
  2. * Sets the response.
  3. * <p>
  4. * Also notifies waiting threads and invokes this request's registered
  5. * @code MessageHandler}s <em>onResponse</em> method with the response.
  6. * </p>
  7. * @param response
  8. * the new response
  9. */
  10. public void setResponse(Response response) {
  11. synchronized (this) {
  12. this.response = response;
  13. notifyAll();
  14. }
  15. for (MessageObserver handler : getMessageObservers()) {
  16. handler.onResponse(response);
  17. }
  18. }

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

  1. @Test
  2. public void testAddListOfMessageObservers() {
  3. Request ping = new Request(null, Type.CON);
  4. List<MessageObserver> observers = new ArrayList<>();
  5. observers.add(new MessageObserverAdapter() {});
  6. observers.add(new MessageObserverAdapter() {});
  7. ping.addMessageObservers(observers);
  8. assertThat(ping.getMessageObservers().size(), is(2));
  9. }

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

  1. @Test
  2. public void testInitalEmptyMessageObservers() {
  3. Request ping = new Request(null, Type.CON);
  4. assertThat(ping.getMessageObservers().size(), is(0));
  5. }

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

  1. @Test
  2. public void testMultipleAddListOfMessageObservers() {
  3. Request ping = new Request(null, Type.CON);
  4. List<MessageObserver> observers = new ArrayList<>();
  5. observers.add(new MessageObserverAdapter() {});
  6. observers.add(new MessageObserverAdapter() {});
  7. ping.addMessageObservers(observers);
  8. observers.add(new MessageObserverAdapter() {});
  9. observers.add(new MessageObserverAdapter() {});
  10. ping.addMessageObservers(observers);
  11. assertThat(ping.getMessageObservers().size(), is(6));
  12. }

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

  1. @Test
  2. public void testAddEmptyListOfMessageObservers() {
  3. Request ping = new Request(null, Type.CON);
  4. List<MessageObserver> observers = Collections.emptyList();
  5. ping.addMessageObservers(observers);
  6. assertThat(ping.getMessageObservers().size(), is(0));
  7. }

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

  1. @Test
  2. public void testAddMessageObserver() {
  3. Request ping = new Request(null, Type.CON);
  4. ping.addMessageObserver(new MessageObserverAdapter() {});
  5. assertThat(ping.getMessageObservers().size(), is(1));
  6. }

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

  1. @Test
  2. public void testMultipleAddsToMessageObservers() {
  3. Request ping = new Request(null, Type.CON);
  4. List<MessageObserver> observers = new ArrayList<>();
  5. observers.add(new MessageObserverAdapter() {});
  6. observers.add(new MessageObserverAdapter() {});
  7. ping.addMessageObservers(observers);
  8. ping.addMessageObserver(new MessageObserverAdapter() {});
  9. ping.addMessageObserver(new MessageObserverAdapter() {});
  10. observers.add(new MessageObserverAdapter() {});
  11. observers.add(new MessageObserverAdapter() {});
  12. ping.addMessageObservers(observers);
  13. ping.addMessageObserver(new MessageObserverAdapter() {});
  14. assertThat(ping.getMessageObservers().size(), is(9));
  15. }
  16. }

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

  1. @Test
  2. public void testMultipleAddMessageObserver() {
  3. Request ping = new Request(null, Type.CON);
  4. ping.addMessageObserver(new MessageObserverAdapter() {});
  5. ping.addMessageObserver(new MessageObserverAdapter() {});
  6. ping.addMessageObserver(new MessageObserverAdapter() {});
  7. assertThat(ping.getMessageObservers().size(), is(3));
  8. }

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

  1. for (MessageObserver mo : request.getMessageObservers()) {
  2. request.removeMessageObserver(mo);
  3. refresh.addMessageObserver(mo);

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

  1. for (MessageObserver mo : request.getMessageObservers()) {
  2. request.removeMessageObserver(mo);
  3. refresh.addMessageObserver(mo);

代码示例来源: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. }

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

  1. private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) {
  2. int num = status.getCurrentNum();
  3. int szx = status.getCurrentSzx();
  4. Request block = new Request(request.getCode());
  5. // do not enforce CON, since NON could make sense over SMS or similar transports
  6. block.setType(request.getType());
  7. block.setDestination(request.getDestination());
  8. block.setDestinationPort(request.getDestinationPort());
  9. // copy options
  10. block.setOptions(new OptionSet(request.getOptions()));
  11. // copy message observers so that a failing blockwise request also notifies observers registered with
  12. // the original request
  13. block.addMessageObservers(request.getMessageObservers());
  14. int currentSize = 1 << (4 + szx);
  15. int from = num * currentSize;
  16. int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
  17. int length = to - from;
  18. byte[] blockPayload = new byte[length];
  19. System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
  20. block.setPayload(blockPayload);
  21. boolean m = (to < request.getPayloadSize());
  22. block.getOptions().setBlock1(szx, m, num);
  23. status.setComplete(!m);
  24. return block;
  25. }

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

  1. private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) {
  2. int num = status.getCurrentNum();
  3. int szx = status.getCurrentSzx();
  4. Request block = new Request(request.getCode());
  5. // do not enforce CON, since NON could make sense over SMS or similar transports
  6. block.setType(request.getType());
  7. block.setDestination(request.getDestination());
  8. block.setDestinationPort(request.getDestinationPort());
  9. // copy options
  10. block.setOptions(new OptionSet(request.getOptions()));
  11. // copy message observers so that a failing blockwise request also notifies observers registered with
  12. // the original request
  13. block.addMessageObservers(request.getMessageObservers());
  14. int currentSize = 1 << (4 + szx);
  15. int from = num * currentSize;
  16. int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
  17. int length = to - from;
  18. byte[] blockPayload = new byte[length];
  19. System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
  20. block.setPayload(blockPayload);
  21. boolean m = (to < request.getPayloadSize());
  22. block.getOptions().setBlock1(szx, m, num);
  23. status.setComplete(!m);
  24. return block;
  25. }

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

  1. block.addMessageObservers(request.getMessageObservers());

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

  1. block.addMessageObservers(request.getMessageObservers());

相关文章