merge servicecache branch

This commit is contained in:
Cloud Wu
2014-04-29 14:39:54 +08:00
8 changed files with 235 additions and 46 deletions

View File

@@ -436,25 +436,19 @@ function skynet.newservice(name, ...)
end
function skynet.uniqueservice(global, ...)
local handle
if global == true then
handle = skynet.call("SERVICE", "lua", "LAUNCH", ...)
return assert(skynet.call(".service", "lua", "GLAUNCH", ...))
else
handle = skynet.call(".service", "lua", "LAUNCH", global, ...)
return assert(skynet.call(".service", "lua", "LAUNCH", global, ...))
end
assert(handle , "Unique service launch failed")
return handle
end
function skynet.queryservice(global, ...)
local handle
if global == true then
handle = skynet.call("SERVICE", "lua", "QUERY", ...)
return assert(skynet.call(".service", "lua", "GQUERY", ...))
else
handle = skynet.call(".service", "lua", "QUERY", global, ...)
return assert(skynet.call(".service", "lua", "QUERY", global, ...))
end
assert(handle , "Unique service query failed")
return handle
end
local function group_command(cmd, handle, address)

View File

@@ -72,16 +72,14 @@ end
local handle_cache = setmetatable( {} , { __mode = "kv" } )
function snax.newservice(name, ...)
function snax.rawnewservice(name, ...)
local t = snax.interface(name)
local handle = skynet.newservice("snaxd", name)
assert(handle_cache[handle] == nil)
if t.system.init then
skynet.call(handle, "snax", t.system.init, ...)
end
local ret = wrapper(handle, name, t)
handle_cache[handle] = ret
return ret
return handle
end
function snax.bind(handle, type)
@@ -96,6 +94,39 @@ function snax.bind(handle, type)
return ret
end
function snax.newservice(name, ...)
local handle = snax.rawnewservice(name, ...)
return snax.bind(handle, name)
end
local function service_name(global, name, ...)
if global == true then
return name
else
return global
end
end
function snax.uniqueservice(name, ...)
local handle = assert(skynet.call(".service", "lua", "LAUNCH", "snaxd", name, ...))
return snax.bind(handle, name)
end
function snax.globalservice(name, ...)
local handle = assert(skynet.call(".service", "lua", "GLAUNCH", "snaxd", name, ...))
return snax.bind(handle, name)
end
function snax.queryservice(name)
local handle = assert(skynet.call(".service", "lua", "QUERY", "snaxd", name))
return snax.bind(handle, name)
end
function snax.queryglobal(name)
local handle = assert(skynet.call(".service", "lua", "GQUERY", "snaxd", name))
return snax.bind(handle, name)
end
function snax.kill(obj, ...)
local t = snax.interface(obj.type)
skynet_call(obj.handle, "snax", t.system.exit, ...)