add cluster.proxy and cluster.ncall

This commit is contained in:
Cloud Wu
2014-08-13 17:49:30 +08:00
parent cde423cb73
commit 978e010e67
11 changed files with 79 additions and 9 deletions

View File

@@ -36,7 +36,11 @@ function harbor.REGISTER(name, handle)
skynet.redirect(harbor_service, handle, "harbor", 0, "N " .. name)
end
function harbor.QUERYNAME(fd, name)
function harbor.QUERYNAME(name)
if name:byte() == 46 then -- "." , local name
skynet.ret(skynet.pack(skynet.localname(name)))
return
end
local result = globalname[name]
if result then
skynet.ret(skynet.pack(result))

View File

@@ -60,6 +60,16 @@ function command.req(source, node, addr, msg, sz)
skynet.ret(c:request(request, session))
end
local proxy = {}
function command.proxy(source, node, name)
local fullname = node .. "." .. name
if proxy[fullname] == nil then
proxy[fullname] = skynet.newservice("clusterproxy", node, name)
end
skynet.ret(skynet.pack(proxy[fullname]))
end
local request_fd = {}
function command.socket(source, subcmd, fd, msg)

View File

@@ -93,6 +93,7 @@ local function monitor_master(master_fd)
local fd = slaves[id_name]
slaves[id_name] = false
if fd then
monitor_clear(id_name)
socket.close(fd)
end
end
@@ -143,14 +144,14 @@ local function monitor_harbor(master_fd)
return function(session, source, command)
local t = string.sub(command, 1, 1)
local arg = string.sub(command, 3)
if t == "Q" then
if t == 'Q' then
-- query name
if globalname[arg] then
skynet.redirect(harbor_service, globalname[arg], "harbor", 0, "N " .. arg)
else
socket.write(master_fd, pack_package("Q", arg))
end
elseif t == "D" then
elseif t == 'D' then
-- harbor down
local id = tonumber(arg)
if slaves[id] then
@@ -194,6 +195,10 @@ function harbor.CONNECT(fd, id)
end
function harbor.QUERYNAME(fd, name)
if name:byte() == 46 then -- "." , local name
skynet.ret(skynet.pack(skynet.localname(name)))
return
end
local result = globalname[name]
if result then
skynet.ret(skynet.pack(result))