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

x33g5p2x  于2022-01-26 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(50)

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

OptionSet.hasBlock2介绍

[英]Checks if the Block2 option is present.
[中]检查Block2选项是否存在。

代码示例

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

@Override
  protected boolean checkResponse(Request request, Response response) {
    boolean success = response.getOptions().hasBlock2();
    
    if (!success) {
      System.out.println("FAIL: no Block2 option");
    } else {
      success &= hasNonEmptyPalyoad(response);
      success &= hasContentType(response);
    }
    return success;
  }
}

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

/**
 * Checks whether this response has either a <em>block1</em> or
 * <em>block2</em> option.
 * 
 * @return {@code true} if this response has a block option.
 */
public boolean hasBlockOption() {
  return getOptions().hasBlock1() || getOptions().hasBlock2();
}

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

private void earlyBlock2Negotiation(final Exchange exchange, final Request request) {
  // Call this method when a request has completely arrived (might have
  // been sent in one piece without blockwise).
  if (request.getOptions().hasBlock2()) {
    BlockOption block2 = request.getOptions().getBlock2();
    BlockwiseStatus status2 = new BlockwiseStatus(request.getOptions().getContentFormat(), block2.getNum(), block2.getSzx());
    LOGGER.fine("Request with early block negotiation "+block2+". Create and set new Block2 status: "+status2);
    exchange.setResponseBlockStatus(status2);
  }
}

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

} else if (!response.getOptions().hasBlock2()) {

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

idByToken = new KeyToken(request.getToken());
if (!(exchange.getFailedTransmissionCount()>0 || request.getOptions().hasBlock1() || request.getOptions().hasBlock2() || request.getOptions().hasObserve()) && exchangesByToken.get(idByToken) != null) {
  LOGGER.warning("Manual token overrides existing open request: "+idByToken);

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

private void registerWithToken(final Exchange exchange) {
  Request request = exchange.getCurrentRequest();
  KeyToken idByToken;
  if (request.getToken() == null) {
    idByToken = tokenProvider.getUnusedToken(request);
    request.setToken(idByToken.getToken());
  } else {
    idByToken = KeyToken.fromOutboundMessage(request);
    // ongoing requests may reuse token
    if (!(exchange.getFailedTransmissionCount() > 0 || request.getOptions().hasBlock1()
        || request.getOptions().hasBlock2() || request.getOptions().hasObserve())
        && tokenProvider.isTokenInUse(idByToken)) {
      LOGGER.log(Level.WARNING, "Manual token overrides existing open request: {0}", idByToken);
    }
  }
  exchangesByToken.put(idByToken, exchange);
}

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

if (hasBlock2())
  options.add(new Option(OptionNumberRegistry.BLOCK2, getBlock2().getValue()));
if (hasSize1())

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

if (hasBlock2())
  options.add(new Option(OptionNumberRegistry.BLOCK2, getBlock2().getValue()));
if (hasSize1())

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

if (response.getOptions().hasBlock2()) {
  Request request = exchange.getCurrentRequest();
  Exchange.KeyUri idByUri = new Exchange.KeyUri(request.getURI(), response.getDestination().getAddress(),

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

if (!request.getOptions().hasBlock1() && !request.getOptions().hasBlock2()) {

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

if (response.getOptions().hasBlock2()) {
  Request request = exchange.getCurrentRequest();
  KeyUri idByUri = new KeyUri(request.getURI(), response.getDestination().getAddress(), response.getDestinationPort());

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

if (request != null && (request.getOptions().hasBlock1() || (response != null && response.getOptions().hasBlock2())) ) {
  KeyUri uriKey = new KeyUri(request.getURI(), request.getSource().getAddress(), request.getSourcePort());
  LOGGER.fine("Remote ongoing completed, cleaning up "+uriKey);

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

@Override
  protected boolean checkResponse(Request request, Response response) {
    boolean success = response.getOptions().hasBlock2();

    if (!success) {
      System.out.println("FAIL: no Block2 option");
    } else {
      int maxNUM = response.getOptions().getBlock2().getNum();
      success &= checkType(Type.ACK, response.getType());
      success &= checkInt(EXPECTED_RESPONSE_CODE.value,
          response.getCode().value, "code");
      success &= checkOption(new BlockOption(EXPECTED_BLOCK_SIZE,
          false, maxNUM), response.getOptions().getBlock2(),
          "Block2");
      success &= hasNonEmptyPalyoad(response);
      success &= hasContentType(response);
    }
    return success;
  }
}

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

@Override
  protected boolean checkResponse(Request request, Response response) {
    boolean success = response.getOptions().hasBlock2();

    if (!success) {
      System.out.println("FAIL: no Block2 option");
    } else {
      int maxNUM = response.getOptions().getBlock2().getNum();
      success &= checkType(Type.ACK, response.getType());
      success &= checkInt(EXPECTED_RESPONSE_CODE.value,
          response.getCode().value, "code");
      success &= checkOption(new BlockOption(PlugtestChecker.PLUGTEST_BLOCK_SZX,
          false, maxNUM), response.getOptions().getBlock2(),
          "Block2");
      success &= hasNonEmptyPalyoad(response);
      success &= hasContentType(response);
    }
    return success;
  }
}

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

if (request != null && (request.getOptions().hasBlock1() || response.getOptions().hasBlock2())) {
  Exchange.KeyUri uriKey = new Exchange.KeyUri(request.getURI(), request.getSource().getAddress(),
      request.getSourcePort());

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

private BlockwiseStatus findResponseBlockStatus(final Exchange exchange, final Response response) {
  BlockwiseStatus status = exchange.getResponseBlockStatus();
  if (status == null) {
    if (exchange.isOfLocalOrigin()) {
      // we are receiving a large body in response to a request originating locally
      // we need to be prepared to buffer up to MAX_RESOURCE_BODY_SIZE bytes
      int bufferSize = maxResourceBodySize;
      if (response.getOptions().hasBlock2() && response.getOptions().hasSize2()) {
        // use size indication for allocating buffer
        bufferSize = response.getOptions().getSize2();
      }
      status = new BlockwiseStatus(bufferSize, response.getOptions().getContentFormat());
    } else {
      // we are sending out a large body in response to a request from a peer
      // we do not need to buffer and assemble anything
      status = new BlockwiseStatus(0, response.getOptions().getContentFormat());
    }
    status.setCurrentSzx(computeSZX(preferredBlockSize));
    status.setFirst(response);
    exchange.setResponseBlockStatus(status);
    LOGGER.log(Level.FINER, "There is no blockwise status yet. Create and set new Block2 status: {0}", status);
  } else {
    LOGGER.log(Level.FINER, "Current Block2 status: {0}", status);
  }
  // sets a timeout to complete exchange
  prepareBlockCleanup(exchange);
  return status;
}

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

} else if (exchange.getResponse() != null && request.getOptions().hasBlock2()) {

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

@Override
public void sendRequest(final Exchange exchange, final Request request) {
  if (request.getOptions().hasBlock2() && request.getOptions().getBlock2().getNum() > 0) {
    // This is the case if the user has explicitly added a block option
    // for random access.
    // Note: We do not regard it as random access when the block num is
    // 0. This is because the user might just want to do early block
    // size negotiation but actually wants to receive all blocks.
    LOGGER.fine("Request carries explicit defined block2 option: create random access blockwise status");
    BlockwiseStatus status = new BlockwiseStatus(request.getOptions().getContentFormat());
    BlockOption block2 = request.getOptions().getBlock2();
    status.setCurrentSzx(block2.getSzx());
    status.setCurrentNum(block2.getNum());
    status.setRandomAccess(true);
    exchange.setResponseBlockStatus(status);
    super.sendRequest(exchange, request);
  } else if (requiresBlockwise(request)) {
    // This must be a large POST or PUT request
    LOGGER.fine("Request payload "+request.getPayloadSize()+"/"+max_message_size+" requires Blockwise");
    BlockwiseStatus status = findRequestBlockStatus(exchange, request);
    Request block = getNextRequestBlock(request, status);
    exchange.setRequestBlockStatus(status);
    exchange.setCurrentRequest(block);
    super.sendRequest(exchange, block);
  } else {
    exchange.setCurrentRequest(request);
    super.sendRequest(exchange, request);
  }
}

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

public void check(Message message) {
  assertTrue("No Block2 option:", message.getOptions().hasBlock2());
  BlockOption block2 = message.getOptions().getBlock2();
  assertEquals("Wrong Block2 num:", num, block2.getNum());
  assertEquals("Wrong Block2 m:", m, block2.isM());
  assertEquals("Wrong Block2 size:", size, block2.getSize());
  print("Correct Block2 option: " + block2);
}

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

Assert.assertNotNull("Client received no response", response);
Assert.assertEquals(expectations[i], response.getPayloadString());
Assert.assertTrue(response.getOptions().hasBlock2());
Assert.assertEquals(num, response.getOptions().getBlock2().getNum());
Assert.assertEquals(szx, response.getOptions().getBlock2().getSzx());

相关文章

微信公众号

最新文章

更多