container_network/server/server.go
crusader f28ff9a303 ing
2018-04-20 00:46:38 +09:00

49 lines
1.3 KiB
Go

package server
import (
cdr "git.loafle.net/commons/di-go/registry"
logging "git.loafle.net/commons/logging-go"
crpj "git.loafle.net/commons/rpc-go/protocol/json"
crr "git.loafle.net/commons/rpc-go/registry"
cssn "git.loafle.net/commons/server-go/socket/net"
occa "git.loafle.net/overflow/commons-go/core/annotation"
"git.loafle.net/overflow/container-go"
"git.loafle.net/overflow/container_network/crawler"
"git.loafle.net/overflow/container_network/service"
"git.loafle.net/overflow/container_network/servlet"
)
func New(pidFilePath string) *cssn.Server {
rpcWriteChan := make(chan *container.RPCNotification, 256)
cdr.RegisterResource(container.CONTAINER_CRAWLERS, crawler.GetCrawlers())
cdr.RegisterResource(container.CONTAINER_RPC_WRITE_CHAN, rpcWriteChan)
services, err := cdr.GetInstancesByAnnotationType(occa.RPCServiceAnnotationType)
if nil != err {
logging.Logger().Panic(err)
}
rpcRegistry := crr.NewRPCRegistry()
rpcRegistry.RegisterServices(services...)
ns := &servlet.NetworkServlets{}
ns.RPCInvoker = rpcRegistry
ns.RPCWriteChan = rpcWriteChan
ns.RPCServerCodec = crpj.NewServerCodec()
sh := &ServerHandlers{}
sh.Name = "Container Network"
sh.PIDFilePath = pidFilePath
sh.Services = services
sh.OrderedServices = service.OrderedServices
sh.RegisterServlet(ns)
s := &cssn.Server{
ServerHandler: sh,
}
return s
}