Examples of ObserveRelation


Examples of ch.ethz.inf.vs.californium.observe.ObserveRelation

     * relation, then the ServerMessageDeliverer must have created such a relation
     * and added to the exchange. Otherwise, there is no such relation.
     * Remember that different paths might lead to this resource.
     */
   
    ObserveRelation relation = exchange.getRelation();
    if (relation == null) return; // because request did not try to establish a relation
   
    if (CoAP.ResponseCode.isSuccess(response.getCode())) {
      response.getOptions().setObserve(notificationOrderer.getCurrent());
     
      if (!relation.isEstablished()) {
        LOGGER.info("Successfully established observe relation between "+relation.getSource()+" and resource "+getURI());
        relation.setEstablished(true);
        addObserveRelation(relation);
      } else if (observeType != null) {
        // The resource can control the message type of the notification
        response.setType(observeType);
      }
View Full Code Here

Examples of ch.ethz.inf.vs.californium.observe.ObserveRelation

    super.sendRequest(exchange, request);
  }
 
  @Override
  public void sendResponse(final Exchange exchange, final Response response) {
    final ObserveRelation relation = exchange.getRelation();
    if (relation != null && relation.isEstablished()) {
     
      if (exchange.getRequest().isAcknowledged() || exchange.getRequest().getType()==Type.NON) {
        // Transmit errors as CON
        if (!ResponseCode.isSuccess(response.getCode())) {
          LOGGER.fine("Response has error code "+response.getCode()+" and must be sent as CON");
          response.setType(Type.CON);
          relation.cancel();
        } else {
          // Make sure that every now and than a CON is mixed within
          if (relation.check()) {
            LOGGER.fine("The observe relation requires the notification to be sent as CON");
            response.setType(Type.CON);
          // By default use NON, but do not override resource decision
          } else if (response.getType()==null) {
            response.setType(Type.NON);
          }
        }
      }
     
      // This is a notification
      response.setLast(false);
     
      /*
       * Only one Confirmable message is allowed to be in transit. A CON
       * is in transit as long as it has not been acknowledged, rejected,
       * or timed out. All further notifications are postponed here. If a
       * former CON is acknowledged or timeouts, it starts the youngest
       * notification (In case of a timeout, it keeps the retransmission
       * counter). When a fresh/younger notification arrives but must be
       * postponed we forget any former notification.
       */
      if (response.getType() == Type.CON) {
        prepareSelfReplacement(exchange, response);
      }
     
      // The decision whether to postpone this notification or not and the
      // decision which notification is the youngest to send next must be
      // synchronized
      synchronized (exchange) {
        Response current = relation.getCurrentControlNotification();
        if (current != null && isInTransit(current)) {
          LOGGER.fine("A former notification is still in transit. Postpone " + response);
          relation.setNextControlNotification(response);
          return;
        } else {
          relation.setCurrentControlNotification(response);
          relation.setNextControlNotification(null);
        }
      }

    } // else no observe was requested or the resource does not allow it
    super.sendResponse(exchange, response);
View Full Code Here

Examples of ch.ethz.inf.vs.californium.observe.ObserveRelation

  public void receiveEmptyMessage(Exchange exchange, EmptyMessage message) {
    // NOTE: We could also move this into the MessageObserverAdapter from
    // sendResponse into the method rejected().
    if (message.getType() == Type.RST && exchange.getOrigin() == Origin.REMOTE) {
      // The response has been rejected
      ObserveRelation relation = exchange.getRelation();
      if (relation != null) {
        relation.cancel();
      } // else there was no observe relation ship and this layer ignores the rst
    }
    super.receiveEmptyMessage(exchange, message);
  }
View Full Code Here

Examples of ch.ethz.inf.vs.californium.observe.ObserveRelation

     
      if (request.getOptions().getObserve()==0) {
        // Requests wants to observe and resource allows it :-)
        LOGGER.info("Initiate an observe relation between " + request.getSource() + ":" + request.getSourcePort() + " and resource " + resource.getURI());
        ObservingEndpoint remote = observeManager.findObservingEndpoint(source);
        ObserveRelation relation = new ObserveRelation(remote, resource, exchange);
        remote.addObserveRelation(relation);
        exchange.setRelation(relation);
        // all that's left is to add the relation to the resource which
        // the resource must do itself if the response is successful
      } else if (request.getOptions().getObserve()==1) {
        ObserveRelation relation = observeManager.getRelation(source, request.getToken());
        if (relation!=null) relation.cancel();
      }
    }
  }
View Full Code Here

Examples of ch.ethz.inf.vs.californium.observe.ObserveRelation

    }
   
    @Override
    public void onAcknowledgement() {
      synchronized (exchange) {
        ObserveRelation relation = exchange.getRelation();
        Response next = relation.getNextControlNotification();
        relation.setCurrentControlNotification(next); // next may be null
        relation.setNextControlNotification(null);
        if (next != null) {
          LOGGER.fine("Notification has been acknowledged, send the next one");
          ObserveLayer.super.sendResponse(exchange, next); // TODO: make this as new task?
        }
      }
View Full Code Here

Examples of ch.ethz.inf.vs.californium.observe.ObserveRelation

    }
   
    @Override
    public void onRetransmission() {
      synchronized (exchange) {
        final ObserveRelation relation = exchange.getRelation();
        final Response next = relation.getNextControlNotification();
        if (next != null) {
          LOGGER.fine("The notification has timed out and there is a younger notification. Send the younger one");
          relation.setNextControlNotification(null);
          // Send the next notification
          response.cancel();
          Type nt = next.getType();
          if (nt != Type.CON); {
            LOGGER.finer("The next notification's type was "+nt+". Since it replaces a CON control notification, it becomes a CON as well");
            prepareSelfReplacement(exchange, next);
            next.setType(Type.CON); // Force the next to be a Confirmable as well
          }
          relation.setCurrentControlNotification(next);
          // Create a new task for sending next response so that we can leave the sync-block
          executor.execute(new Runnable() {
            public void run() {
              ObserveLayer.super.sendResponse(exchange, next);
            }
View Full Code Here

Examples of ch.ethz.inf.vs.californium.observe.ObserveRelation

      }
    }
   
    @Override
    public void onTimeout() {
      ObserveRelation relation = exchange.getRelation();
      LOGGER.info("Notification timed out. Cancel all relations with source "+relation.getSource());
      relation.cancelAll();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.