class Named does the work.
# File queuemgr/queuemgr.rb, line 96
def initialize()
@log = Logging::init(APPNAME)
@log.info { "Initializing ..." }
@protocols = Hash.new
extend(MonitorMixin)
Thread.start {
Thread.pass
while sleep(TIMEOUT)
tnow = Time.now.to_i
synchronize {
@protocols.each {
|proto|
proto.delete_if {
|k,v|
tnow - v.last > TIMEOUT
@log.info { "GC: removed '#{k} ...'" }
}
}
}
Thread.pass
end
}
end
# File queuemgr/queuemgr.rb, line 120
def value(uri)
synchronize {
pair = uri.split("://")
proto = pair.first
path = pair.last
result = @protocols.key?(proto) ? [path] + @protocols[proto][path] : []
}
end
# File queuemgr/queuemgr.rb, line 129
def register(uri, val)
synchronize {
pair = uri.split("://")
proto = pair.first
path = pair.last
val = val.split("|")
@protocols[proto] = Hash.new if !@protocols.key?(proto)
@log.info { "Register '#{uri}'." } if @protocols[proto][path].nil?
@protocols[proto][path] = val + [ Time.now.to_i ]
}
end
# File queuemgr/queuemgr.rb, line 141
def unregister(uri)
synchronize {
pair = uri.split("://")
proto = pair.first
path = pair.last
if @protocols.key?(proto)
if !@protocols[proto][path].nil?
@protocols[proto].delete(path)
@log.info { "Unregister '#{uri}'." }
end
end
}
end
# File queuemgr/queuemgr.rb, line 155
def listall(proto)
synchronize {
list = []
if @protocols.key?(proto)
@protocols[proto].each_pair {
|key, val|
list << ([key] + val)
}
end
list
}
end
# File queuemgr/queuemgr.rb, line 168
def exit()
@log.info { "Exiting by request" }
Process.kill("HUP",$$)
end