diff --git a/client/client-context.go b/client/client-context.go deleted file mode 100644 index 3cb37db..0000000 --- a/client/client-context.go +++ /dev/null @@ -1,19 +0,0 @@ -package client - -import ( - cuc "git.loafle.net/commons/util-go/context" -) - -type ClientCtx interface { - cuc.Context -} - -func NewClientCtx(parent cuc.Context) ClientCtx { - return &clientCtx{ - Context: cuc.NewContext(parent), - } -} - -type clientCtx struct { - cuc.Context -} diff --git a/client/client-handler.go b/client/client-handler.go index 750d96a..ed33bd3 100644 --- a/client/client-handler.go +++ b/client/client-handler.go @@ -12,29 +12,17 @@ import ( ) type ClientHandler interface { - GetName() string - GetConnector() csc.Connector + csc.ClientHandler + GetRPCCodec() protocol.ClientCodec GetRPCInvoker() registry.RPCInvoker GetPendingRequestCount() int GetRequestTimeout() time.Duration - - ClientCtx() ClientCtx - - Init(clientCtx ClientCtx) error - OnStart(clientCtx ClientCtx) error - OnStop(clientCtx ClientCtx) - Destroy(clientCtx ClientCtx) - - Validate() error } type ClientHandlers struct { - // Client name for sending in response headers. - // - // Default client name is used if left blank. - Name string `json:"name,omitempty"` - Connector csc.Connector `json:"-"` + csc.ClientHandlers + RPCCodec protocol.ClientCodec `json:"-"` RPCInvoker registry.RPCInvoker `json:"-"` PendingRequestCount int `json:"pendingRequests,omitempty"` @@ -43,33 +31,6 @@ type ClientHandlers struct { validated atomic.Value } -func (ch *ClientHandlers) ClientCtx() ClientCtx { - return NewClientCtx(nil) -} - -func (ch *ClientHandlers) Init(clientCtx ClientCtx) error { - return nil -} - -func (ch *ClientHandlers) OnStart(clientCtx ClientCtx) error { - return nil -} - -func (ch *ClientHandlers) OnStop(clientCtx ClientCtx) { - -} - -func (ch *ClientHandlers) Destroy(clientCtx ClientCtx) { - -} - -func (ch *ClientHandlers) GetName() string { - return ch.Name -} - -func (ch *ClientHandlers) GetConnector() csc.Connector { - return ch.Connector -} func (ch *ClientHandlers) GetRPCCodec() protocol.ClientCodec { return ch.RPCCodec } @@ -84,14 +45,15 @@ func (ch *ClientHandlers) GetRequestTimeout() time.Duration { } func (ch *ClientHandlers) Validate() error { + if err := ch.ClientHandlers.Validate(); nil != err { + return err + } + if nil != ch.validated.Load() { return nil } ch.validated.Store(true) - if "" == ch.Name { - ch.Name = "Client" - } if 0 >= ch.PendingRequestCount { ch.PendingRequestCount = rpc.DefaultPendingRequestCount } @@ -106,13 +68,5 @@ func (ch *ClientHandlers) Validate() error { return fmt.Errorf("RPCCodec is not valid") } - if nil == ch.Connector { - return fmt.Errorf("Connector is not valid") - } - - if err := ch.Connector.Validate(); nil != err { - return err - } - return nil } diff --git a/client/client.go b/client/client.go index a1429bc..fae49d3 100644 --- a/client/client.go +++ b/client/client.go @@ -7,8 +7,9 @@ import ( "sync" "time" - logging "git.loafle.net/commons/logging-go" + "git.loafle.net/commons/logging-go" "git.loafle.net/commons/rpc-go/protocol" + csc "git.loafle.net/commons/server-go/client" ) var uint64Type = reflect.TypeOf(uint64(0)) @@ -16,7 +17,7 @@ var uint64Type = reflect.TypeOf(uint64(0)) type Client struct { ClientHandler ClientHandler - ctx ClientCtx + ctx csc.ClientCtx stopChan chan struct{} stopWg sync.WaitGroup