Browse Source

scope -> context

Josh Wilson 19 years ago
parent
commit
d5d97fb009
1 changed files with 55 additions and 54 deletions
  1. 55 54
      direct/src/distributed/DoInterestManager.py

+ 55 - 54
direct/src/distributed/DoInterestManager.py

@@ -19,11 +19,11 @@ from direct.showbase.PythonUtil import report
 class InterestState:
 class InterestState:
     StateActive = 'Active'
     StateActive = 'Active'
     StatePendingDel = 'PendingDel'
     StatePendingDel = 'PendingDel'
-    def __init__(self, desc, state, scope, event, parentId, zoneIdList,
+    def __init__(self, desc, state, context, event, parentId, zoneIdList,
                  eventCounter, auto=False):
                  eventCounter, auto=False):
         self.desc = desc
         self.desc = desc
         self.state = state
         self.state = state
-        self.scope = scope
+        self.context = context
         # We must be ready to keep track of multiple events. If somebody
         # We must be ready to keep track of multiple events. If somebody
         # requested an interest to be removed and we get a second request
         # requested an interest to be removed and we get a second request
         # for removal of the same interest before we get a response for the
         # for removal of the same interest before we get a response for the
@@ -52,8 +52,8 @@ class InterestState:
     def isPendingDelete(self):
     def isPendingDelete(self):
         return self.state == InterestState.StatePendingDel
         return self.state == InterestState.StatePendingDel
     def __repr__(self):
     def __repr__(self):
-        return 'InterestState(desc=%s, state=%s, scope=%s, event=%s, parentId=%s, zoneIdList=%s)' % (
-            self.desc, self.state, self.scope, self.events, self.parentId, self.zoneIdList)
+        return 'InterestState(desc=%s, state=%s, context=%s, event=%s, parentId=%s, zoneIdList=%s)' % (
+            self.desc, self.state, self.context, self.events, self.parentId, self.zoneIdList)
 
 
 class InterestHandle:
 class InterestHandle:
     """This class helps to ensure that valid handles get passed in to DoInterestManager funcs"""
     """This class helps to ensure that valid handles get passed in to DoInterestManager funcs"""
@@ -68,8 +68,8 @@ class InterestHandle:
     def __repr__(self):
     def __repr__(self):
         return '%s(%s)' % (self.__class__.__name__, self._id)
         return '%s(%s)' % (self.__class__.__name__, self._id)
 
 
-# scope value for interest changes that have no complete event
-NO_SCOPE = 0
+# context value for interest changes that have no complete event
+NO_CONTEXT = 0
 
 
 class DoInterestManager(DirectObject.DirectObject):
 class DoInterestManager(DirectObject.DirectObject):
     """
     """
@@ -89,9 +89,9 @@ class DoInterestManager(DirectObject.DirectObject):
     # high bit is reserved for server interests
     # high bit is reserved for server interests
     _HandleMask = 0x7FFF
     _HandleMask = 0x7FFF
 
 
-    # 'scope' refers to a single request to change an interest set
-    _ScopeIdSerialNum = 100
-    _ScopeIdMask = 0x3FFFFFFF # avoid making Python create a long
+    # 'context' refers to a single request to change an interest set
+    _ContextIdSerialNum = 100
+    _ContextIdMask = 0x3FFFFFFF # avoid making Python create a long
 
 
     _interests = {}
     _interests = {}
     if __debug__:
     if __debug__:
@@ -108,8 +108,8 @@ class DoInterestManager(DirectObject.DirectObject):
         self._removeInterestEvent = uniqueName('DoInterestManager-Remove')
         self._removeInterestEvent = uniqueName('DoInterestManager-Remove')
         self._noNewInterests = False
         self._noNewInterests = False
         self._completeDelayedCallback = None
         self._completeDelayedCallback = None
-        # keep track of request scopes that have not completed
-        self._outstandingScopes = set()
+        # keep track of request contexts that have not completed
+        self._outstandingContexts = set()
         self._completeEventCount = ScratchPad(num=0)
         self._completeEventCount = ScratchPad(num=0)
         self._allInterestsCompleteCallbacks = []
         self._allInterestsCompleteCallbacks = []
 
 
@@ -137,7 +137,7 @@ class DoInterestManager(DirectObject.DirectObject):
 
 
     def resetInterestStateForConnectionLoss(self):
     def resetInterestStateForConnectionLoss(self):
         DoInterestManager._interests.clear()
         DoInterestManager._interests.clear()
-        self._outstandingScopes = set()
+        self._outstandingContexts = set()
         self._completeEventCount = ScratchPad(num=0)
         self._completeEventCount = ScratchPad(num=0)
         if __debug__:
         if __debug__:
             self._addDebugInterestHistory("RESET", "", 0, 0, 0, [])
             self._addDebugInterestHistory("RESET", "", 0, 0, 0, [])
@@ -175,20 +175,20 @@ class DoInterestManager(DirectObject.DirectObject):
                         '' % (parentId, parent.__class__.__name__))
                         '' % (parentId, parent.__class__.__name__))
 
 
         if auto:
         if auto:
-            scopeId = 0
+            contextId = 0
             event = None
             event = None
         else:
         else:
-            scopeId = self._getNextScopeId()
-            self._outstandingScopes.add(scopeId)
+            contextId = self._getNextContextId()
+            self._outstandingContexts.add(contextId)
             if event is None:
             if event is None:
                 event = self._getAnonymousEvent('addInterest')
                 event = self._getAnonymousEvent('addInterest')
         DoInterestManager._interests[handle] = InterestState(
         DoInterestManager._interests[handle] = InterestState(
-            description, InterestState.StateActive, scopeId, event, parentId, zoneIdList, self._completeEventCount)
+            description, InterestState.StateActive, contextId, event, parentId, zoneIdList, self._completeEventCount)
         if self.__verbose():
         if self.__verbose():
             print 'CR::INTEREST.addInterest(handle=%s, parentId=%s, zoneIdList=%s, description=%s, event=%s, auto=%s)' % (
             print 'CR::INTEREST.addInterest(handle=%s, parentId=%s, zoneIdList=%s, description=%s, event=%s, auto=%s)' % (
                 handle, parentId, zoneIdList, description, event, auto)
                 handle, parentId, zoneIdList, description, event, auto)
         if not auto:
         if not auto:
-            self._sendAddInterest(handle, scopeId, parentId, zoneIdList, description)
+            self._sendAddInterest(handle, contextId, parentId, zoneIdList, description)
         if event:
         if event:
             messenger.send(self._getAddInterestEvent(), [event])
             messenger.send(self._getAddInterestEvent(), [event])
         assert self.printInterestsIfDebug()
         assert self.printInterestsIfDebug()
@@ -230,11 +230,11 @@ class DoInterestManager(DirectObject.DirectObject):
                 if auto:
                 if auto:
                     self._considerRemoveInterest(handle)
                     self._considerRemoveInterest(handle)
                 else:
                 else:
-                    scopeId = self._getNextScopeId()
-                    intState.scope = scopeId
+                    contextId = self._getNextContextId()
+                    intState.context = contextId
                     if event is not None:
                     if event is not None:
                         intState.addEvent(event)
                         intState.addEvent(event)
-                    self._sendRemoveInterest(handle, scopeId)
+                    self._sendRemoveInterest(handle, contextId)
                     if event is None:
                     if event is None:
                         self._considerRemoveInterest(handle)
                         self._considerRemoveInterest(handle)
                 if self.__verbose():
                 if self.__verbose():
@@ -274,18 +274,19 @@ class DoInterestManager(DirectObject.DirectObject):
                 description = DoInterestManager._interests[handle].desc
                 description = DoInterestManager._interests[handle].desc
 
 
             # are we overriding an existing change?
             # are we overriding an existing change?
-            if DoInterestManager._interests[handle].scope != NO_SCOPE:
+            if DoInterestManager._interests[handle].context != NO_CONTEXT:
                 DoInterestManager._interests[handle].clearEvents()
                 DoInterestManager._interests[handle].clearEvents()
 
 
-            scopeId = self._getNextScopeId()
-            DoInterestManager._interests[handle].scope = scopeId
+            contextId = self._getNextContextId()
+            DoInterestManager._interests[handle].context = contextId
+            DoInterestManager._interests[handle].parentId = parentId            
             DoInterestManager._interests[handle].zoneIdList = zoneIdList
             DoInterestManager._interests[handle].zoneIdList = zoneIdList
             DoInterestManager._interests[handle].addEvent(event)
             DoInterestManager._interests[handle].addEvent(event)
 
 
             if self.__verbose():
             if self.__verbose():
                 print 'CR::INTEREST.alterInterest(handle=%s, parentId=%s, zoneIdList=%s, description=%s, event=%s)' % (
                 print 'CR::INTEREST.alterInterest(handle=%s, parentId=%s, zoneIdList=%s, description=%s, event=%s)' % (
                     handle, parentId, zoneIdList, description, event)
                     handle, parentId, zoneIdList, description, event)
-            self._sendAddInterest(handle, scopeId, parentId, zoneIdList, description, action='modify')
+            self._sendAddInterest(handle, contextId, parentId, zoneIdList, description, action='modify')
             exists = True
             exists = True
             assert self.printInterestsIfDebug()
             assert self.printInterestsIfDebug()
         else:
         else:
@@ -332,15 +333,15 @@ class DoInterestManager(DirectObject.DirectObject):
                 'interest %s already in use' % handle)
                 'interest %s already in use' % handle)
         DoInterestManager._HandleSerialNum = handle
         DoInterestManager._HandleSerialNum = handle
         return DoInterestManager._HandleSerialNum
         return DoInterestManager._HandleSerialNum
-    def _getNextScopeId(self):
-        scopeId = DoInterestManager._ScopeIdSerialNum
+    def _getNextContextId(self):
+        contextId = DoInterestManager._ContextIdSerialNum
         while True:
         while True:
-            scopeId = (scopeId + 1) & DoInterestManager._ScopeIdMask
-            # skip over the 'no scope' id
-            if scopeId != NO_SCOPE:
+            contextId = (contextId + 1) & DoInterestManager._ContextIdMask
+            # skip over the 'no context' id
+            if contextId != NO_CONTEXT:
                 break
                 break
-        DoInterestManager._ScopeIdSerialNum = scopeId
-        return DoInterestManager._ScopeIdSerialNum
+        DoInterestManager._ContextIdSerialNum = contextId
+        return DoInterestManager._ContextIdSerialNum
 
 
     def _considerRemoveInterest(self, handle):
     def _considerRemoveInterest(self, handle):
         """
         """
@@ -351,7 +352,7 @@ class DoInterestManager(DirectObject.DirectObject):
         if DoInterestManager._interests.has_key(handle):
         if DoInterestManager._interests.has_key(handle):
             if DoInterestManager._interests[handle].isPendingDelete():
             if DoInterestManager._interests[handle].isPendingDelete():
                 # make sure there is no pending event for this interest
                 # make sure there is no pending event for this interest
-                if DoInterestManager._interests[handle].scope == NO_SCOPE:
+                if DoInterestManager._interests[handle].context == NO_CONTEXT:
                     assert len(DoInterestManager._interests[handle].events) == 0
                     assert len(DoInterestManager._interests[handle].events) == 0
                     del DoInterestManager._interests[handle]
                     del DoInterestManager._interests[handle]
 
 
@@ -362,11 +363,11 @@ class DoInterestManager(DirectObject.DirectObject):
             return 1 # for assert
             return 1 # for assert
 
 
         def _addDebugInterestHistory(self, action, description, handle,
         def _addDebugInterestHistory(self, action, description, handle,
-                                     scopeId, parentId, zoneIdList):
+                                     contextId, parentId, zoneIdList):
             if description is None:
             if description is None:
                 description = ''
                 description = ''
             DoInterestManager._debug_interestHistory.append(
             DoInterestManager._debug_interestHistory.append(
-                (action, description, handle, scopeId, parentId, zoneIdList))
+                (action, description, handle, contextId, parentId, zoneIdList))
             DoInterestManager._debug_maxDescriptionLen = max(
             DoInterestManager._debug_maxDescriptionLen = max(
                 DoInterestManager._debug_maxDescriptionLen, len(description))
                 DoInterestManager._debug_maxDescriptionLen, len(description))
 
 
@@ -374,18 +375,18 @@ class DoInterestManager(DirectObject.DirectObject):
             print "***************** Interest History *************"
             print "***************** Interest History *************"
             format = '%9s %' + str(DoInterestManager._debug_maxDescriptionLen) + 's %6s %6s %9s %s'
             format = '%9s %' + str(DoInterestManager._debug_maxDescriptionLen) + 's %6s %6s %9s %s'
             print format % (
             print format % (
-                "Action", "Description", "Handle", "Scope", "ParentId",
+                "Action", "Description", "Handle", "Context", "ParentId",
                 "ZoneIdList")
                 "ZoneIdList")
             for i in DoInterestManager._debug_interestHistory:
             for i in DoInterestManager._debug_interestHistory:
                 print format % tuple(i)
                 print format % tuple(i)
-            print "Note: interests with a Scope of 0 do not get" \
+            print "Note: interests with a Context of 0 do not get" \
                 " done/finished notices."
                 " done/finished notices."
             
             
         def printInterestSets(self):
         def printInterestSets(self):
             print "******************* Interest Sets **************"
             print "******************* Interest Sets **************"
             format = '%6s %' + str(DoInterestManager._debug_maxDescriptionLen) + 's %10s %5s %9s %9s %10s'
             format = '%6s %' + str(DoInterestManager._debug_maxDescriptionLen) + 's %10s %5s %9s %9s %10s'
             print format % (
             print format % (
-                "Handle", "Description", "State", "Scope",
+                "Handle", "Description", "State", "Context",
                 "ParentId", "ZoneIdList", "Event")
                 "ParentId", "ZoneIdList", "Event")
             for id, state in DoInterestManager._interests.items():
             for id, state in DoInterestManager._interests.items():
                 if len(state.events) == 0:
                 if len(state.events) == 0:
@@ -394,7 +395,7 @@ class DoInterestManager(DirectObject.DirectObject):
                     event = state.events[0]
                     event = state.events[0]
                 else:
                 else:
                     event = state.events
                     event = state.events
-                print format % (id, state.desc, state.state, state.scope,
+                print format % (id, state.desc, state.state, state.context,
                                 state.parentId, state.zoneIdList, event)
                                 state.parentId, state.zoneIdList, event)
             print "************************************************"
             print "************************************************"
 
 
@@ -402,7 +403,7 @@ class DoInterestManager(DirectObject.DirectObject):
             self.printInterestHistory()
             self.printInterestHistory()
             self.printInterestSets()
             self.printInterestSets()
             
             
-    def _sendAddInterest(self, handle, scopeId, parentId, zoneIdList, description,
+    def _sendAddInterest(self, handle, contextId, parentId, zoneIdList, description,
                          action=None):
                          action=None):
         """
         """
         Part of the new otp-server code.
         Part of the new otp-server code.
@@ -419,7 +420,7 @@ class DoInterestManager(DirectObject.DirectObject):
             if action is None:
             if action is None:
                 action = 'add'
                 action = 'add'
             self._addDebugInterestHistory(
             self._addDebugInterestHistory(
-                action, description, handle, scopeId, parentId, zoneIdList)
+                action, description, handle, contextId, parentId, zoneIdList)
         if parentId == 0:
         if parentId == 0:
             DoInterestManager.notify.error(
             DoInterestManager.notify.error(
                 'trying to set interest to invalid parent: %s' % parentId)
                 'trying to set interest to invalid parent: %s' % parentId)
@@ -427,7 +428,7 @@ class DoInterestManager(DirectObject.DirectObject):
         # Add message type
         # Add message type
         datagram.addUint16(CLIENT_ADD_INTEREST)
         datagram.addUint16(CLIENT_ADD_INTEREST)
         datagram.addUint16(handle)
         datagram.addUint16(handle)
-        datagram.addUint32(scopeId)
+        datagram.addUint32(contextId)
         datagram.addUint32(parentId)
         datagram.addUint32(parentId)
         if isinstance(zoneIdList, types.ListType):
         if isinstance(zoneIdList, types.ListType):
             vzl = list(zoneIdList)
             vzl = list(zoneIdList)
@@ -439,7 +440,7 @@ class DoInterestManager(DirectObject.DirectObject):
            datagram.addUint32(zoneIdList)
            datagram.addUint32(zoneIdList)
         self.send(datagram)
         self.send(datagram)
 
 
-    def _sendRemoveInterest(self, handle, scopeId):
+    def _sendRemoveInterest(self, handle, contextId):
         """
         """
         handle is a client-side created number that refers to
         handle is a client-side created number that refers to
                 a set of interests.  The same handle number doesn't
                 a set of interests.  The same handle number doesn't
@@ -452,13 +453,13 @@ class DoInterestManager(DirectObject.DirectObject):
         # Add message type
         # Add message type
         datagram.addUint16(CLIENT_REMOVE_INTEREST)
         datagram.addUint16(CLIENT_REMOVE_INTEREST)
         datagram.addUint16(handle)
         datagram.addUint16(handle)
-        if scopeId != 0:
-            datagram.addUint32(scopeId)
+        if contextId != 0:
+            datagram.addUint32(contextId)
         self.send(datagram)
         self.send(datagram)
         if __debug__:
         if __debug__:
             state = DoInterestManager._interests[handle]
             state = DoInterestManager._interests[handle]
             self._addDebugInterestHistory(
             self._addDebugInterestHistory(
-                "remove", state.desc, handle, scopeId,
+                "remove", state.desc, handle, contextId,
                 state.parentId, state.zoneIdList)
                 state.parentId, state.zoneIdList)
 
 
     def cleanupWaitAllInterestsClosed(self):
     def cleanupWaitAllInterestsClosed(self):
@@ -472,16 +473,16 @@ class DoInterestManager(DirectObject.DirectObject):
         """
         """
         assert DoInterestManager.notify.debugCall()
         assert DoInterestManager.notify.debugCall()
         handle = di.getUint16()
         handle = di.getUint16()
-        scopeId = di.getUint32()
+        contextId = di.getUint32()
         if self.__verbose():
         if self.__verbose():
             print 'CR::INTEREST.interestDone(handle=%s)' % handle
             print 'CR::INTEREST.interestDone(handle=%s)' % handle
         DoInterestManager.notify.debug(
         DoInterestManager.notify.debug(
-            "handleInterestDoneMessage--> Received handle %s, scope %s" % (
-            handle, scopeId))
+            "handleInterestDoneMessage--> Received handle %s, context %s" % (
+            handle, contextId))
         eventsToSend = []
         eventsToSend = []
-        # if the scope matches, send out the event
-        if scopeId == DoInterestManager._interests[handle].scope:
-            DoInterestManager._interests[handle].scope = NO_SCOPE
+        # if the context matches, send out the event
+        if contextId == DoInterestManager._interests[handle].context:
+            DoInterestManager._interests[handle].context = NO_CONTEXT
             # the event handlers may call back into the interest manager. Send out
             # the event handlers may call back into the interest manager. Send out
             # the events after we're once again in a stable state.
             # the events after we're once again in a stable state.
             #DoInterestManager._interests[handle].sendEvents()
             #DoInterestManager._interests[handle].sendEvents()
@@ -489,12 +490,12 @@ class DoInterestManager(DirectObject.DirectObject):
             DoInterestManager._interests[handle].clearEvents()
             DoInterestManager._interests[handle].clearEvents()
         else:
         else:
             DoInterestManager.notify.warning(
             DoInterestManager.notify.warning(
-                "handleInterestDoneMessage--> handle: %s: Expecting scope %s, got %s" % (
-                handle, DoInterestManager._interests[handle].scope, scopeId))
+                "handleInterestDoneMessage--> handle: %s: Expecting context %s, got %s" % (
+                handle, DoInterestManager._interests[handle].context, contextId))
         if __debug__:
         if __debug__:
             state = DoInterestManager._interests[handle]
             state = DoInterestManager._interests[handle]
             self._addDebugInterestHistory(
             self._addDebugInterestHistory(
-                "finished", state.desc, handle, scopeId, state.parentId,
+                "finished", state.desc, handle, contextId, state.parentId,
                 state.zoneIdList)
                 state.zoneIdList)
         self._considerRemoveInterest(handle)
         self._considerRemoveInterest(handle)
         for event in eventsToSend:
         for event in eventsToSend: