OPENBUS-3050 Novo método para definir tamanho máximo de caches LRU

Essa mudança afeta a openbus.core.Access.Interceptor que é usada pela
implementação do busservices. Mas também afeta Connection que herda de
openbus.core.Access.Interceptor.
parent 05caf37b
......@@ -217,17 +217,36 @@ local Interceptor = class()
-- login : information about the login used to access the bus
-- Optional field that may be provided to configure the interceptor:
-- prvkey: private key associated to the key registered to the login
-- legacy: ACS facet of OpenBus 1.5 to validate legacy invocations
-- prvkey : private key associated to the key registered to the login
-- legacy : ACS facet of OpenBus 1.5 to validate legacy invocations
-- maxcachesize: max size for LRUCache objects
function Interceptor:__init()
self.maxcachesize = self.maxcachesize or LRUCache.maxsize
self:resetCaches()
end
function Interceptor:maxCacheSize(newsize)
if not newsize then
return self.maxcachesize
else
self.maxcachesize = newsize
self.profile2login.maxsize = newsize
self.outgoingSessions.maxsize = newsize
self.incomingSessions.maxsize = newsize
end
end
local function newLRU(self, data)
local data = data or {}
data.maxsize = self.maxcachesize
return LRUCache(data)
end
function Interceptor:resetCaches()
self.profile2login = LRUCache() -- [iop_profile] = loginid
self.outgoingSessions = LRUCache()
self.incomingSessions = LRUCache{
self.profile2login = newLRU(self) -- [iop_profile] = loginid
self.outgoingSessions = newLRU(self)
self.incomingSessions = newLRU(self,{
retrieve = function(id)
return {
id = id,
......@@ -235,7 +254,7 @@ function Interceptor:resetCaches()
tickets = tickets(),
}
end,
}
})
end
function Interceptor:unmarshalSignedChain(chain, busid)
......
......@@ -45,6 +45,17 @@ local orb = openbus.initORB()
local OpenBusContext = orb.OpenBusContext
assert(OpenBusContext.orb == orb)
do log:TEST("Make changes on LRU max cache size")
local default = require("loop.collection.LRUCache").maxsize
local conn = OpenBusContext:createConnection(bushost, busport, connprops)
assert(conn:maxCacheSize() == default)
conn:maxCacheSize(1024)
assert(conn:maxCacheSize() == 1024)
-- TODO: exercise more calls than default initial value could perform
conn:maxCacheSize(default)
assert(conn:maxCacheSize() == default)
conn:logout()
end
do log:TEST("Two threads logging in")
local conn = OpenBusContext:createConnection(bushost, busport, connprops)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment