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 { type ClientHandler interface {
GetName() string csc.ClientHandler
GetConnector() csc.Connector
GetRPCCodec() protocol.ClientCodec GetRPCCodec() protocol.ClientCodec
GetRPCInvoker() registry.RPCInvoker GetRPCInvoker() registry.RPCInvoker
GetPendingRequestCount() int GetPendingRequestCount() int
GetRequestTimeout() time.Duration GetRequestTimeout() time.Duration
ClientCtx() ClientCtx
Init(clientCtx ClientCtx) error
OnStart(clientCtx ClientCtx) error
OnStop(clientCtx ClientCtx)
Destroy(clientCtx ClientCtx)
Validate() error
} }
type ClientHandlers struct { type ClientHandlers struct {
// Client name for sending in response headers. csc.ClientHandlers
//
// Default client name is used if left blank.
Name string `json:"name,omitempty"`
Connector csc.Connector `json:"-"`
RPCCodec protocol.ClientCodec `json:"-"` RPCCodec protocol.ClientCodec `json:"-"`
RPCInvoker registry.RPCInvoker `json:"-"` RPCInvoker registry.RPCInvoker `json:"-"`
PendingRequestCount int `json:"pendingRequests,omitempty"` PendingRequestCount int `json:"pendingRequests,omitempty"`
@ -43,33 +31,6 @@ type ClientHandlers struct {
validated atomic.Value 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 { func (ch *ClientHandlers) GetRPCCodec() protocol.ClientCodec {
return ch.RPCCodec return ch.RPCCodec
} }
@ -84,14 +45,15 @@ func (ch *ClientHandlers) GetRequestTimeout() time.Duration {
} }
func (ch *ClientHandlers) Validate() error { func (ch *ClientHandlers) Validate() error {
if err := ch.ClientHandlers.Validate(); nil != err {
return err
}
if nil != ch.validated.Load() { if nil != ch.validated.Load() {
return nil return nil
} }
ch.validated.Store(true) ch.validated.Store(true)
if "" == ch.Name {
ch.Name = "Client"
}
if 0 >= ch.PendingRequestCount { if 0 >= ch.PendingRequestCount {
ch.PendingRequestCount = rpc.DefaultPendingRequestCount ch.PendingRequestCount = rpc.DefaultPendingRequestCount
} }
@ -106,13 +68,5 @@ func (ch *ClientHandlers) Validate() error {
return fmt.Errorf("RPCCodec is not valid") 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 return nil
} }

View File

@ -7,8 +7,9 @@ import (
"sync" "sync"
"time" "time"
logging "git.loafle.net/commons/logging-go" "git.loafle.net/commons/logging-go"
"git.loafle.net/commons/rpc-go/protocol" "git.loafle.net/commons/rpc-go/protocol"
csc "git.loafle.net/commons/server-go/client"
) )
var uint64Type = reflect.TypeOf(uint64(0)) var uint64Type = reflect.TypeOf(uint64(0))
@ -16,7 +17,7 @@ var uint64Type = reflect.TypeOf(uint64(0))
type Client struct { type Client struct {
ClientHandler ClientHandler ClientHandler ClientHandler
ctx ClientCtx ctx csc.ClientCtx
stopChan chan struct{} stopChan chan struct{}
stopWg sync.WaitGroup stopWg sync.WaitGroup