This commit is contained in:
crusader 2018-05-11 13:20:24 +09:00
parent 65cfd8f1ab
commit fba0aa26f6
3 changed files with 11 additions and 75 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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