Package ch.ethz.inf.vs.californium.network

Examples of ch.ethz.inf.vs.californium.network.Exchange


   * before, this method returns the corresponding exchange. If this
   * KeyMID has not yet arrived, this methos returns null, indicating that
   * the message with the KeyMID is not a duplicate.
   */
  public Exchange findPrevious(KeyMID key, Exchange exchange) {
    Exchange previous = incommingMessages.putIfAbsent(key, exchange);
    return previous;
  }
View Full Code Here


      long oldestAllowed = System.currentTimeMillis() - lifecycle;
     
      // Notice that the guarantees from the ConcurrentHashMap guarantee
      // the correctness for this iteration.
      for (Map.Entry<?,Exchange> entry:incommingMessages.entrySet()) {
        Exchange exchange = entry.getValue();
        if (exchange.getTimestamp() < oldestAllowed) {
         
          // TODO: Only remove if no observe option!!! Should we take ts of last message?
          // Use exchange.isCompleted()
         
          LOGGER.finer("Mark-And-Sweep removes "+entry.getKey());
View Full Code Here

  }
 
  private class StackTopAdapter extends AbstractLayer {
   
    public void sendRequest(Request request) {
      Exchange exchange = new Exchange(request, Origin.LOCAL);
      sendRequest(exchange, request); // layer method
    }
View Full Code Here

  @Override
  public Exchange findPrevious(KeyMID key, Exchange exchange) {
    int f = first;
    int s = second;
    Exchange prev = maps[f].putIfAbsent(key, exchange);
    if (prev != null || f==s)
      return prev;
    prev = maps[s].putIfAbsent(key, exchange);
    return prev;
  }
View Full Code Here

  @Override
  public Exchange find(KeyMID key) {
    int f = first;
    int s = second;
    Exchange prev = maps[f].get(key);
    if (prev != null || f==s)
      return prev;
    prev = maps[s].get(key);
    return prev;
  }
View Full Code Here

  public void handleRequest(final Request request) {
//    if (Bench_Help.DO_LOG)
      LOGGER.info("ProxyEndpoint handles request "+request);
   
    Exchange exchange = new Exchange(request, Origin.REMOTE) {
      @Override public void sendResponse(Response response) {
        // Redirect the response to the HttpStack instead of a normal
        // CoAP endpoint.
        // TODO: When we change endpoint to be an interface, we can
        // redirect the responses a little more elegantly.
        try {
          request.setResponse(response);
          responseProduced(request, response);
          httpStack.doSendResponse(request, response);
        } catch (Exception e) {
          LOGGER.log(Level.WARNING, "Exception while responding to Http request", e);
        }
      }
    };
    exchange.setRequest(request);
   
    Response response = null;
    // ignore the request if it is reset or acknowledge
    // check if the proxy-uri is defined
    if (request.getType() != Type.RST && request.getType() != Type.ACK
        && request.getOptions().hasProxyURI()) {
      // get the response from the cache
      response = cacheResource.getResponse(request);
//      if (Bench_Help.DO_LOG)
        LOGGER.info("Cache returned "+response);

      // update statistics
      statsResource.updateStatistics(request, response != null);
    }

    // check if the response is present in the cache
    if (response != null) {
      // link the retrieved response with the request to set the
      // parameters request-specific (i.e., token, id, etc)
      exchange.sendResponse(response);
      return;
    } else {

      // edit the request to be correctly forwarded if the proxy-uri is
      // set
      if (request.getOptions().hasProxyURI()) {
        try {
          manageProxyUriRequest(request);
//          if (Bench_Help.DO_LOG)
            LOGGER.info("after manageProxyUriRequest: "+request);

        } catch (URISyntaxException e) {
          LOGGER.warning(String.format("Proxy-uri malformed: %s", request.getOptions().getProxyURI()));

          exchange.sendResponse(new Response(ResponseCode.BAD_OPTION));
        }
      }

      // handle the request as usual
      proxyCoapResolver.forwardRequest(exchange);
View Full Code Here

TOP

Related Classes of ch.ethz.inf.vs.californium.network.Exchange

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.