add service manager

This commit is contained in:
云风
2012-09-07 11:04:46 +08:00
parent 87b8b664aa
commit 4c1cbaaf3e
6 changed files with 49 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
local skynet = require "skynet"
local SERVICE = "GROUPMGR"
local SERVICE
local group = {}
@@ -27,4 +27,9 @@ function group.release(id)
skynet.send(SERVICE, "lua" , "CLEAR", skynet.self(), id)
end
skynet.init(function()
SERVICE = skynet.call("SERVICE", "lua", "group_mgr")
skynet.call(".service","lua","group_agent")
end, "group")
return group

View File

@@ -3,6 +3,8 @@ local string = string
local table = table
local unpack = unpack
local redis_manager
local redis = {}
local command = {}
@@ -30,9 +32,13 @@ local meta = {
}
function redis.connect(dbname)
local handle = skynet.call(".redis-manager", "lua", dbname)
local handle = skynet.call(redis_manager, "lua", dbname)
assert(handle ~= nil)
return setmetatable({ __handle = handle } , meta)
end
skynet.init(function()
redis_manager = skynet.call(".service", "lua", "redis-mgr")
end, "redis")
return redis

View File

@@ -402,9 +402,34 @@ do
}
end
local init_func = {}
function skynet.init(f, name)
assert(type(f) == "function")
if init_func == nil then
f()
else
if name == nil then
table.insert(init_func, f)
else
assert(init_func[name] == nil)
init_func[name] = f
end
end
end
local function init_all()
local funcs = init_func
init_func = nil
for k,v in pairs(funcs) do
v()
end
end
function skynet.start(f)
c.callback(dispatch_message)
skynet.timeout(0, function()
init_all()
f()
skynet.send(".launcher","lua", nil)
end)