Package ch.ethz.inf.vs.californium.coap

Examples of ch.ethz.inf.vs.californium.coap.Request


    KeyMID idByMID = new KeyMID(response.getMID(),
        response.getDestination().getAddress(), response.getDestinationPort());
    exchangesByMID.put(idByMID, exchange);
   
    if (response.getOptions().hasBlock2()) {
      Request request = exchange.getRequest();
      KeyUri idByUri = new KeyUri(request.getURI(),
          response.getDestination().getAddress(), response.getDestinationPort());
      if (exchange.getResponseBlockStatus()!=null && !response.getOptions().hasObserve()) {
        // Remember ongoing blockwise GET requests
        LOGGER.fine("Ongoing Block2 started, storing "+idByUri + "\nOngoing " + request + "\nOngoing " + response);
        ongoingExchanges.put(idByUri, exchange);
View Full Code Here


       * Uncomment logging code only for debugging purposes.
       */
     
      if (exchange.getOrigin() == Origin.LOCAL) {
        // this endpoint created the Exchange by issuing a request
        Request request = exchange.getRequest();
        KeyToken idByTok = new KeyToken(exchange.getCurrentRequest().getToken(), request.getDestination().getAddress(), request.getDestinationPort());
        KeyMID idByMID = new KeyMID(request.getMID(), request.getDestination().getAddress(), request.getDestinationPort());
       
//        LOGGER.fine("Exchange completed: Cleaning up "+idByTok);
        exchangesByToken.remove(idByTok);
        // in case an empty ACK was lost
        exchangesByMID.remove(idByMID);
     
      } else {
        // this endpoint created the Exchange to respond a request
        Request request = exchange.getCurrentRequest();
        if (request != null) {
          // TODO: We can optimize this and only do it, when the request really had blockwise transfer
          KeyUri uriKey = new KeyUri(request.getURI(),
              request.getSource().getAddress(), request.getSourcePort());
//          LOGGER.warning("++++++++++++++++++Remote ongoing completed, cleaning up "+uriKey);
          ongoingExchanges.remove(uriKey);
        }
        // TODO: What if the request is only a block?
        // TODO: This should only happen if the transfer was blockwise
View Full Code Here

    }
   
    @Override
    public void run() {
      if (!exchange.getRequest().isCanceled()) {
        Request refresh = Request.newGet();
        refresh.setOptions(exchange.getRequest().getOptions());
        // make sure Observe is set and zero
        refresh.setObserve();
        // use same Token
        refresh.setToken(exchange.getRequest().getToken());
        refresh.setDestination(exchange.getRequest().getDestination());
        refresh.setDestinationPort(exchange.getRequest().getDestinationPort());
        LOGGER.info("Re-registering for " + exchange.getRequest());
        sendRequest(exchange, refresh);
      } else {
        LOGGER.finer("Dropping re-registration for canceled " + exchange.getRequest());
      }
View Full Code Here

    if (requiresBlockwise(request)) {
      // This must be a large POST or PUT request
      LOGGER.fine("Request payload "+request.getPayloadSize()+"/"+maxMsgSize+" requires Blockwise");
      BlockwiseStatus status = findRequestBlockStatus(exchange, request);
     
      Request block = getNextRequestBlock(request, status);
     
      exchange.setRequestBlockStatus(status);
      exchange.setCurrentRequest(block);
      super.sendRequest(exchange, block);
     
View Full Code Here

         
          // Block2 early negotiation
          earlyBlock2Negotiation(exchange, request);
         
          // Assemble and deliver
          Request assembled = new Request(request.getCode()); // getAssembledRequest(status, request);
          assembleMessage(status, assembled, request);
//          assembled.setAcknowledged(true); // TODO: prevents accept from sending ACK. Maybe the resource uses separate...
          exchange.setRequest(assembled);
          super.receiveRequest(exchange, assembled);
        }
View Full Code Here

        int currentSize = 1 << (4 + status.getCurrentSzx());
        int nextNum = status.getCurrentNum() + currentSize / block1.getSize();
        LOGGER.finer("Send next block num = "+nextNum);
        status.setCurrentNum(nextNum);
        status.setCurrentSzx(block1.getSzx());
        Request nextBlock = getNextRequestBlock(exchange.getRequest(), status);
        if (nextBlock.getToken() == null)
          nextBlock.setToken(response.getToken()); // reuse same token
        exchange.setCurrentRequest(nextBlock);
        super.sendRequest(exchange, nextBlock);
        // do not deliver response
       
      } else if (!response.getOptions().hasBlock2()) {
        // All request block have been acknowledged and we receive a piggy-backed
        // response that needs no blockwise transfer. Thus, deliver it.
        super.receiveResponse(exchange, response);
      } else {
        LOGGER.fine("Response has Block2 option and is therefore sent blockwise");
      }
    }
   
    if (response.getOptions().hasBlock2()) {
      BlockOption block2 = response.getOptions().getBlock2();
      BlockwiseStatus status = findResponseBlockStatus(exchange, response);
     
      if (block2.getNum() == status.getCurrentNum()) {
        // We got the block we expected :-)
        status.addBlock(response.getPayload());
        if (response.getOptions().hasObserve())
          status.setObserve(response.getOptions().getObserve());
       
        if (block2.isM()) {
          LOGGER.finer("Request the next response block");
          // TODO: If this is a notification, do we have to use
          // another token now?

          Request request = exchange.getRequest();
          int num = block2.getNum() + 1;
          int szx = block2.getSzx();
          boolean m = false;
          Request block = new Request(request.getCode());
          block.setOptions(new OptionSet(request.getOptions()));
          block.setDestination(request.getDestination());
          block.setDestinationPort(request.getDestinationPort());
         
          block.setType(request.getType()); // NON could make sense over SMS or similar transports
          block.getOptions().setBlock2(szx, m, num);
          status.setCurrentNum(num);
         
          // to make it easier for Observe, we do not re-use the Token
//          if (!response.getOptions().hasObserve()) {
//            block.setToken(request.getToken());
//          }
         
          // make sure not to use Observe for block retrieval
          block.getOptions().removeObserve();
         
          exchange.setCurrentRequest(block);
          super.sendRequest(exchange, block);
         
        } else {
View Full Code Here

  }
 
  private Request getNextRequestBlock(Request request, BlockwiseStatus status) {
    int num = status.getCurrentNum();
    int szx = status.getCurrentSzx();
    Request block = new Request(request.getCode());
    block.setOptions(new OptionSet(request.getOptions()));
    block.setDestination(request.getDestination());
    block.setDestinationPort(request.getDestinationPort());
    block.setToken(request.getToken());
    block.setType(Type.CON);
   
    int currentSize = 1 << (4 + szx);
    int from = num * currentSize;
    int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
    int length = to - from;
    byte[] blockPayload = new byte[length];
    System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
    block.setPayload(blockPayload);
   
    boolean m = (to < request.getPayloadSize());
    block.getOptions().setBlock1(szx, m, num);
   
    status.setComplete(!m);
    return block;
  }
View Full Code Here

  }
 
  private static boolean ping(String address) {
    try {
      Request request = new Request(null);
      request.setType(Type.CON);
      request.setToken(new byte[0]);
      request.setURI(address);

            System.out.println("++++++ Sending Ping ++++++");
      request.send().waitForResponse(5000);
      return request.isRejected();

    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
View Full Code Here

  public CL02(String serverURI) {
    super(CL02.class.getSimpleName());

    // create the request
    Request request = new Request(Code.GET, Type.CON);
    // set query
    request.getOptions().addURIQuery(EXPECTED_RT);
    // set the parameters and execute the request
    executeRequest(request, serverURI, RESOURCE_URI);
  }
View Full Code Here

  public CC07(String serverURI) {
    super(CC07.class.getSimpleName());

    // create the request
    Request request = new Request(Code.PUT);
    request.setConfirmable(false);
    // add payload
    request.setPayload("TD_COAP_CORE_07", MediaTypeRegistry.TEXT_PLAIN);
    // set the parameters and execute the request
    executeRequest(request, serverURI, RESOURCE_URI);
  }
View Full Code Here

TOP

Related Classes of ch.ethz.inf.vs.californium.coap.Request

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.