ing
This commit is contained in:
57
client/client-handler.go
Normal file
57
client/client-handler.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
crc "git.loafle.net/commons/rpc-go/client"
|
||||
occ "git.loafle.net/overflow/container-go/client"
|
||||
)
|
||||
|
||||
type ClientHandler interface {
|
||||
occ.ClientHandler
|
||||
}
|
||||
|
||||
type ClientHandlers struct {
|
||||
occ.ClientHandlers
|
||||
|
||||
validated atomic.Value
|
||||
}
|
||||
|
||||
func (ch *ClientHandlers) Init(clientCtx crc.ClientCtx) error {
|
||||
if err := ch.ClientHandlers.Init(clientCtx); nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ch *ClientHandlers) OnStart(clientCtx crc.ClientCtx) error {
|
||||
if err := ch.ClientHandlers.OnStart(clientCtx); nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ch *ClientHandlers) OnStop(clientCtx crc.ClientCtx) {
|
||||
|
||||
ch.ClientHandlers.OnStop(clientCtx)
|
||||
}
|
||||
|
||||
func (ch *ClientHandlers) Destroy(clientCtx crc.ClientCtx) {
|
||||
|
||||
ch.ClientHandlers.Destroy(clientCtx)
|
||||
}
|
||||
|
||||
func (ch *ClientHandlers) Validate() error {
|
||||
if nil != ch.validated.Load() {
|
||||
return nil
|
||||
}
|
||||
ch.validated.Store(true)
|
||||
|
||||
if err := ch.ClientHandlers.Validate(); nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
50
client/client.go
Normal file
50
client/client.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
cdr "git.loafle.net/commons/di-go/registry"
|
||||
"git.loafle.net/commons/logging-go"
|
||||
crc "git.loafle.net/commons/rpc-go/client"
|
||||
crpj "git.loafle.net/commons/rpc-go/protocol/json"
|
||||
crr "git.loafle.net/commons/rpc-go/registry"
|
||||
occp "git.loafle.net/overflow/commons-go/config/probe"
|
||||
occa "git.loafle.net/overflow/commons-go/core/annotation"
|
||||
"git.loafle.net/overflow/container-go"
|
||||
occ "git.loafle.net/overflow/container-go/client"
|
||||
"git.loafle.net/overflow/container_network/crawler"
|
||||
"git.loafle.net/overflow/container_network/service"
|
||||
)
|
||||
|
||||
func New(portNumber int) *crc.Client {
|
||||
rpcClientCodec := crpj.NewClientCodec()
|
||||
|
||||
connector, err := occ.NewConnector(occp.ContainerDiscovery, portNumber)
|
||||
if nil != err {
|
||||
logging.Logger().Panic(err)
|
||||
}
|
||||
|
||||
ch := &ClientHandlers{}
|
||||
ch.Name = occp.ContainerNetwork.String()
|
||||
ch.Connector = connector
|
||||
ch.RPCCodec = rpcClientCodec
|
||||
|
||||
c := &crc.Client{
|
||||
ClientHandler: ch,
|
||||
}
|
||||
|
||||
cdr.RegisterResource(container.CONTAINER_CRAWLERS, crawler.GetCrawlers())
|
||||
cdr.RegisterResource(container.CONTAINER_RPC_CLIENT, c)
|
||||
|
||||
services, err := cdr.GetInstancesByAnnotationType(occa.RPCServiceAnnotationType)
|
||||
if nil != err {
|
||||
logging.Logger().Panic(err)
|
||||
}
|
||||
|
||||
rpcRegistry := crr.NewRPCRegistry()
|
||||
rpcRegistry.RegisterServices(services...)
|
||||
|
||||
ch.RPCInvoker = rpcRegistry
|
||||
ch.Services = services
|
||||
ch.OrderedServices = service.OrderedServices
|
||||
|
||||
return c
|
||||
}
|
||||
Reference in New Issue
Block a user