コード例 #1
0
        def _create_own_remote_cse_remotely():
            endpoints = self.api.get_onem2m_endpoints()

            from openmtc.util import datetime_the_future

            # init RemoteCSE object
            cse = RemoteCSE(resourceName=self.cse_id[1:],
                            labels=self.labels,
                            cseType=self.cse_type,
                            pointOfAccess=endpoints,
                            CSEBase=self.cse_base,
                            CSE_ID=self.cse_id,
                            requestReachability=bool(len(endpoints)),
                            expirationTime=datetime_the_future(
                                self.get_offset))
            if remote_cse.get('own_poa'):
                cse.pointOfAccess = remote_cse.get('own_poa')

            request = OneM2MRequest(OneM2MOperation.create,
                                    remote_cse_uri,
                                    self.originator,
                                    ty=RemoteCSE,
                                    pc=cse)

            return self.api.send_onem2m_request(request)
コード例 #2
0
    def __updateExpTime(self, instance, future=None, fields=[]):
        """ Updates a resource instance's expirationTime to future.

            @note: Starts a new Timer.
            @param instance: resource instance to update
            @param future: new expirationTime value (optional)
        """
        self.logger.debug("__updateExpTime: %s" % instance)
        if self.__shutdown:
            return

        interval = self.__interval
        offset = self.__offset
        if not future:
            future = datetime_the_future(interval + offset)
        fields.append("expirationTime")
        instance.expirationTime = future
        self.send_update(instance, fields)
        # NOTE: expirationTime might have been changed by SCL at this point.
        # update could/should return the updated instance in this case,
        #   but does it?
        # => additional GET to confirm expirationTime ?

        # t = Timer(interval, self.__updateExpTime,
        #           kwargs = { "instance": instance, "fields": fields})
        # t.start()
        t = self.api.set_timer(interval,
                               lambda: self.__updateExpTime(instance,
                                                            fields=fields))
        del self.__timers[instance.path]
        self.__timers[instance.path] = t
コード例 #3
0
    def __updateExpTime(self, instance, future=None, fields=[], restore=None,
                        send_update=None):
        """ Updates a resource instance's expirationTime to future.

            @note: Starts a new Timer.
            @param instance: resource instance to update
            @param future: new expirationTime value (optional)
            @param fields: additional fields mandatory during update
            @param restore: function that will restore the instance, if it has
                            expired accidentally. Has to restart the refresher.
        """
        self.logger.debug("__updateExpTime: %s" % instance )
        if self.__shutdown:
            return

        interval = self.interval
        offset = self.offset
        future = datetime_the_future(interval + offset)

        instance.expirationTime = future

        if send_update:
            send_update(instance)
        else:
            return

        # NOTE: expirationTime might have been changed by SCL at this point.
        # update could/should return the updated instance in this case,
        #   but does it?
        # => additional GET to confirm expirationTime ?
        kwargs = {"instance": instance, "fields": fields, "restore": restore,
                  "send_update": send_update}
        t = Timer(interval, self.__updateExpTime, kwargs=kwargs)
        t.start()
        self.timers[instance.path] = t
コード例 #4
0
    def __updateExpTime(self, instance, future=None, fields=[], restore=None):
        """ Updates a resource instance's expirationTime to future.

            @note: Starts a new Timer.
            @param instance: resource instance to update
            @param future: new expirationTime value (optional)
            @param fields: additional fields mandatory during update
            @param restore: function that will restore the instance, if it has expired accidentally. Has to restart the refresher.
        """
        self.logger.debug("__updateExpTime: %s" % (instance))
        if self.__shutdown:
            return

        interval = self.__interval
        offset = self.__offset
        if not future:
            future = datetime_the_future(interval + offset)
        fields.append("expirationTime")
        instance.expirationTime = future
        try:
            self.mapper.update(instance, fields)
        except SCLNotFound as e:
            self.logger.warn("ExpirationTime update failed: %s", e)
            # subscription disappeared?
            # missed the expirationTime?
            # mb sync issue?; mb congestion?
            if restore:
                restore(instance)
                return
            else:
                raise
        # NOTE: expirationTime might have been changed by SCL at this point.
        # update could/should return the updated instance in this case, but does it?
        # => additional GET to confirm expirationTime ?
        kwargs = {"instance": instance, "fields": fields, "restore": restore}
        t = Timer(interval, self.__updateExpTime, kwargs=kwargs)
        t.start()
        self.__timers[instance.path] = t
コード例 #5
0
 def get_expiration_time(self):
     if self.default_lifetime is None:
         return None
     return datetime_the_future(self.default_lifetime)