distributed: Use more efficient context-allocation mechanism for Astron.
This commit is contained in:
parent
d782cd0f47
commit
0b482cd008
|
|
@ -32,7 +32,7 @@ class AstronDatabaseInterface:
|
|||
"""
|
||||
|
||||
# Save the callback:
|
||||
ctx = self.air.contextAllocator.allocate()
|
||||
ctx = self.air.getContext()
|
||||
self._callbacks[ctx] = callback
|
||||
|
||||
# Pack up/count valid fields.
|
||||
|
|
@ -72,7 +72,6 @@ class AstronDatabaseInterface:
|
|||
self._callbacks[ctx](doId)
|
||||
|
||||
del self._callbacks[ctx]
|
||||
self.air.contextAllocator.free(ctx)
|
||||
|
||||
def queryObject(self, databaseId, doId, callback):
|
||||
"""
|
||||
|
|
@ -84,7 +83,7 @@ class AstronDatabaseInterface:
|
|||
"""
|
||||
|
||||
# Save the callback:
|
||||
ctx = self.air.contextAllocator.allocate()
|
||||
ctx = self.air.getContext()
|
||||
self._callbacks[ctx] = callback
|
||||
|
||||
# Generate and send the datagram:
|
||||
|
|
@ -138,7 +137,6 @@ class AstronDatabaseInterface:
|
|||
|
||||
finally:
|
||||
del self._callbacks[ctx]
|
||||
self.air.contextAllocator.free(ctx)
|
||||
|
||||
def updateObject(self, databaseId, doId, dclass, newFields, oldFields=None, callback=None):
|
||||
"""
|
||||
|
|
@ -192,7 +190,7 @@ class AstronDatabaseInterface:
|
|||
# Generate and send the datagram:
|
||||
dg = PyDatagram()
|
||||
if oldFields is not None:
|
||||
ctx = self.air.contextAllocator.allocate()
|
||||
ctx = self.air.getContext()
|
||||
self._callbacks[ctx] = callback
|
||||
if fieldCount == 1:
|
||||
dg.addServerHeader(databaseId, self.air.ourChannel,
|
||||
|
|
@ -260,7 +258,6 @@ class AstronDatabaseInterface:
|
|||
|
||||
finally:
|
||||
del self._callbacks[ctx]
|
||||
self.air.contextAllocator.free(ctx)
|
||||
|
||||
def handleDatagram(self, msgType, di):
|
||||
if msgType == DBSERVER_CREATE_OBJECT_RESP:
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class AstronInternalRepository(ConnectionRepository):
|
|||
self.channelAllocator = UniqueIdAllocator(baseChannel, baseChannel+maxChannels-1)
|
||||
self._registeredChannels = set()
|
||||
|
||||
self.contextAllocator = UniqueIdAllocator(0, 100)
|
||||
self.__contextCounter = 0
|
||||
|
||||
self.dbInterface = AstronDatabaseInterface(self)
|
||||
|
||||
|
|
@ -61,6 +61,10 @@ class AstronInternalRepository(ConnectionRepository):
|
|||
|
||||
self.readDCFile(dcFileNames)
|
||||
|
||||
def getContext(self):
|
||||
self.__contextCounter = (self.__contextCounter + 1) & 0xFFFFFFFF
|
||||
return self.__contextCounter
|
||||
|
||||
def allocateChannel(self):
|
||||
"""
|
||||
Allocate an unused channel out of this AIR's configured channel space.
|
||||
|
|
|
|||
Loading…
Reference in New Issue