Beispiel #1
0
 def start(self, stateID):
     if self.__isStarted:
         return
     self.__isStarted = True
     self.__requester = SimpleFortRequester(
         (FORT_ERROR.OK, FORT_ERROR.NOT_CREATED))
     self.__requester.init()
     self.__ctx = RequestCtx()
     self.__isAutoUnsubscribed = False
     self.__isEnabled = stateID in CLIENT_FORT_STATE.KEEP_ALIVE
     self.__setTimeout()
Beispiel #2
0
 def start(self, stateID):
     if self.__isStarted:
         return
     self.__isStarted = True
     self.__requester = SimpleFortRequester((FORT_ERROR.OK, FORT_ERROR.NOT_CREATED))
     self.__requester.init()
     self.__ctx = RequestCtx()
     self.__isAutoUnsubscribed = False
     self.__isEnabled = stateID in CLIENT_FORT_STATE.KEEP_ALIVE
     self.__setTimeout()
Beispiel #3
0
class FortSubscriptionKeeper(object):

    def __init__(self):
        super(FortSubscriptionKeeper, self).__init__()
        self.__isStarted = False
        self.__callbackID = None
        self.__requester = None
        self.__ctx = None
        self.__isAutoUnsubscribed = True
        self.__isEnabled = False
        self.onAutoUnsubscribed = Event.Event()
        return

    def isEnabled(self):
        return self.__isEnabled

    def isAutoUnsubscribed(self):
        return self.__isAutoUnsubscribed

    def start(self, stateID):
        if self.__isStarted:
            return
        self.__isStarted = True
        self.__requester = SimpleFortRequester((FORT_ERROR.OK, FORT_ERROR.NOT_CREATED))
        self.__requester.init()
        self.__ctx = RequestCtx()
        self.__isAutoUnsubscribed = False
        self.__isEnabled = stateID in CLIENT_FORT_STATE.KEEP_ALIVE
        self.__setTimeout()

    def stop(self):
        self.__isStarted = False
        self.__isAutoUnsubscribed = True
        self.__isEnabled = False
        if self.__ctx:
            self.__ctx.clear()
            self.__ctx = None
        if self.__requester:
            self.__requester.fini()
            self.__requester = None
        self.__clearTimeout()
        self.onAutoUnsubscribed.clear()
        return

    def update(self, stateID):
        isEnabled = stateID in CLIENT_FORT_STATE.KEEP_ALIVE
        if self.__isEnabled is isEnabled:
            return
        self.__isEnabled = isEnabled
        if self.__isEnabled and not self.__ctx.isProcessing():
            self.__setTimeout()

    def __setTimeout(self):
        if self.__callbackID is None:
            self.__callbackID = BigWorld.callback(FORT_AUTO_UNSUBSCRIBE_TIMEOUT, self.__timeout)
        return

    def __clearTimeout(self):
        if self.__callbackID is not None:
            BigWorld.cancelCallback(self.__callbackID)
            self.__callbackID = None
        return

    def __timeout(self):
        self.__callbackID = None
        if self.__isEnabled:
            self.__sendRequest()
        else:
            LOG_DEBUG('Client is unsubscribed automatically')
            self.onAutoUnsubscribed()
            self.__isAutoUnsubscribed = True
        return

    def __sendRequest(self):
        self.__requester.doRequestEx(self.__ctx, self.__callback, 'keepalive')

    def __callback(self, result):
        if result:
            self.__setTimeout()
Beispiel #4
0
class FortSubscriptionKeeper(object):
    def __init__(self):
        super(FortSubscriptionKeeper, self).__init__()
        self.__isStarted = False
        self.__callbackID = None
        self.__requester = None
        self.__ctx = None
        self.__isAutoUnsubscribed = True
        self.__isEnabled = False
        self.onAutoUnsubscribed = Event.Event()
        return

    def isEnabled(self):
        return self.__isEnabled

    def isAutoUnsubscribed(self):
        return self.__isAutoUnsubscribed

    def start(self, stateID):
        if self.__isStarted:
            return
        self.__isStarted = True
        self.__requester = SimpleFortRequester(
            (FORT_ERROR.OK, FORT_ERROR.NOT_CREATED))
        self.__requester.init()
        self.__ctx = RequestCtx()
        self.__isAutoUnsubscribed = False
        self.__isEnabled = stateID in CLIENT_FORT_STATE.KEEP_ALIVE
        self.__setTimeout()

    def stop(self):
        self.__isStarted = False
        self.__isAutoUnsubscribed = True
        self.__isEnabled = False
        if self.__ctx:
            self.__ctx.clear()
            self.__ctx = None
        if self.__requester:
            self.__requester.fini()
            self.__requester = None
        self.__clearTimeout()
        self.onAutoUnsubscribed.clear()
        return

    def update(self, stateID):
        isEnabled = stateID in CLIENT_FORT_STATE.KEEP_ALIVE
        if self.__isEnabled is isEnabled:
            return
        self.__isEnabled = isEnabled
        if self.__isEnabled and not self.__ctx.isProcessing():
            self.__setTimeout()

    def __setTimeout(self):
        if self.__callbackID is None:
            self.__callbackID = BigWorld.callback(
                FORT_AUTO_UNSUBSCRIBE_TIMEOUT, self.__timeout)
        return

    def __clearTimeout(self):
        if self.__callbackID is not None:
            BigWorld.cancelCallback(self.__callbackID)
            self.__callbackID = None
        return

    def __timeout(self):
        self.__callbackID = None
        if self.__isEnabled:
            self.__sendRequest()
        else:
            LOG_DEBUG('Client is unsubscribed automatically')
            self.onAutoUnsubscribed()
            self.__isAutoUnsubscribed = True
        return

    def __sendRequest(self):
        self.__requester.doRequestEx(self.__ctx, self.__callback, 'keepalive')

    def __callback(self, result):
        if result:
            self.__setTimeout()