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.

(cherry picked from commit 6c08d438)
parent aa374b70
......@@ -219,16 +219,35 @@ 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
-- prvkey : private key associated to the key registered to the login
-- 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,
......@@ -236,7 +255,7 @@ function Interceptor:resetCaches()
tickets = tickets(),
}
end,
}
})
end
function Interceptor:unmarshalSignedChain(chain, idltype)
......
......@@ -51,6 +51,17 @@ local OpenBusContext = orb.OpenBusContext
assert(OpenBusContext.orb == orb)
local busref = orb:newproxy(busref, nil, "::scs::core::IComponent")
do log:TEST("Make changes on LRU max cache size")
local default = require("loop.collection.LRUCache").maxsize
local conn = OpenBusContext:connectByReference(busref, 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:connectByReference(busref, 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