service_mgr support list, add a debug command to debug_console

This commit is contained in:
Cloud Wu
2014-04-19 20:45:40 +08:00
parent ddd0b13013
commit 8840c0fe3e
5 changed files with 98 additions and 20 deletions

View File

@@ -7,3 +7,4 @@ address = "127.0.0.1:2527"
master = "127.0.0.1:2013" master = "127.0.0.1:2013"
start = "main_log" start = "main_log"
luaservice ="./service/?.lua;./test/?.lua;./examples/?.lua" luaservice ="./service/?.lua;./test/?.lua;./examples/?.lua"
snax = "./examples/?.lua;./test/?.lua"

View File

@@ -8,7 +8,7 @@ skynet.start(function()
skynet.monitor "simplemonitor" skynet.monitor "simplemonitor"
local lualog = skynet.newservice("lualog") local lualog = skynet.newservice("lualog")
local console = skynet.newservice("console") local console = skynet.newservice("console")
-- skynet.newservice("debug_console",8000) skynet.newservice("debug_console",8000)
skynet.newservice("simpledb") skynet.newservice("simpledb")
local watchdog = skynet.newservice("watchdog") local watchdog = skynet.newservice("watchdog")
skynet.call(watchdog, "lua", "start", { skynet.call(watchdog, "lua", "start", {

View File

@@ -110,6 +110,7 @@ function COMMAND.help()
gc = "gc : force every lua service do garbage collect", gc = "gc : force every lua service do garbage collect",
start = "lanuch a new lua service", start = "lanuch a new lua service",
clearcache = "clear lua code cache", clearcache = "clear lua code cache",
service = "List unique service",
} }
end end
@@ -126,4 +127,6 @@ function COMMAND.start(...)
end end
end end
function COMMAND.service()
return skynet.call("SERVICE", "lua", "LIST")
end

View File

@@ -58,36 +58,107 @@ local function waitfor(name , func, ...)
return s return s
end end
function cmd.LAUNCH(service_name, subname, ...) local function read_name(service_name)
if service_name == "snaxd" then if string.byte(service_name) == 64 then -- '@'
return waitfor("snax."..subname, snax.rawnewservice, subname, ...) return string.sub(service_name , 2)
else else
return waitfor(service_name, skynet.newservice, service_name, subname, ...) return service_name
end
end
function cmd.LAUNCH(service_name, subname, ...)
local realname = read_name(service_name)
if realname == "snaxd" then
return waitfor(service_name.."."..subname, snax.rawnewservice, subname, ...)
else
return waitfor(service_name, skynet.newservice, realname, subname, ...)
end end
end end
function cmd.QUERY(service_name, subname) function cmd.QUERY(service_name, subname)
if service_name == "snaxd" then local realname = read_name(service_name)
return waitfor("snax."..subname)
if realname == "snaxd" then
return waitfor(service_name.."."..subname)
else else
return waitfor(service_name) return waitfor(service_name)
end end
end end
function cmd.GLAUNCH(...) local function list_service()
if GLOBAL then local result = {}
return cmd.LAUNCH(...) for k,v in pairs(service) do
else if type(v) == "string" then
return waitfor(service_name, skynet.call, "SERVICE", "lua", "LAUNCH", ...) v = "Error: " .. v
elseif type(v) == "table" then
v = "Querying"
else
v = skynet.address(v)
end
result[k] = v
end
return result
end
local function register_global()
function cmd.GLAUNCH(name, ...)
local global_name = "@" .. name
return cmd.LAUNCH(global_name, ...)
end
function cmd.GQUERY(name, ...)
local global_name = "@" .. name
return cmd.QUERY(global_name, ...)
end
local mgr = {}
function cmd.REPORT(m)
mgr[m] = true
skynet.watch(m)
end
local function add_list(all, m)
local harbor = "@" .. skynet.harbor(m)
local result = skynet.call(m, "lua", "LIST")
for k,v in pairs(result) do
all[k .. harbor] = v
end
end
function cmd.LIST()
local result = {}
for k in pairs(mgr) do
pcall(add_list, result, k)
end
local l = list_service()
for k, v in pairs(l) do
result[k] = v
end
return result
end end
end end
function cmd.GQUERY(...) local function register_local()
if GLOBAL then function cmd.GLAUNCH(name, ...)
return cmd.QUERY(...) local global_name = "@" .. name
else return waitfor(global_name, skynet.call, "SERVICE", "lua", "LAUNCH", global_name, ...)
return waitfor(service_name, skynet.call, "SERVICE", "lua", "QUERY", ...)
end end
function cmd.GQUERY(name, ...)
local global_name = "@" .. name
return waitfor(global_name, skynet.call, "SERVICE", "lua", "QUERY", global_name, ...)
end
function cmd.LIST()
return list_service()
end
skynet.call("SERVICE", "lua", "REPORT", skynet.self())
end end
skynet.start(function() skynet.start(function()
@@ -110,5 +181,8 @@ skynet.start(function()
if skynet.getenv "standalone" then if skynet.getenv "standalone" then
GLOBAL = true GLOBAL = true
skynet.register("SERVICE") skynet.register("SERVICE")
register_global()
else
register_local()
end end
end) end)

View File

@@ -2,7 +2,7 @@ local skynet = require "skynet"
local snax = require "snax" local snax = require "snax"
skynet.start(function() skynet.start(function()
local ps = snax.newservice ("pingserver", "hello world") local ps = snax.uniqueservice ("pingserver", "hello world")
print(ps.req.ping("foobar")) print(ps.req.ping("foobar"))
print(ps.pub.hello()) print(ps.pub.hello())
print(pcall(ps.req.error)) print(pcall(ps.req.error))
@@ -24,6 +24,6 @@ end
]])) ]]))
print(ps.pub.hello()) print(ps.pub.hello())
print(snax.kill(ps,"exit")) -- print(snax.kill(ps,"exit"))
skynet.exit() skynet.exit()
end) end)