mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
add cluster.proxy and cluster.ncall
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user