ing
This commit is contained in:
parent
f22a5d5df4
commit
c9fbeb37d8
|
@ -15,6 +15,7 @@ func NewRPCRegistry() RPCRegistry {
|
|||
|
||||
type RPCRegistry interface {
|
||||
RPCInvoker
|
||||
GetService(name string) interface{}
|
||||
RegisterService(receiver interface{}, name string) error
|
||||
}
|
||||
|
||||
|
@ -43,6 +44,10 @@ func (rr *rpcRegistry) RegisterService(receiver interface{}, name string) error
|
|||
return rr.services.register(receiver, name)
|
||||
}
|
||||
|
||||
func (rr *rpcRegistry) GetService(name string) interface{} {
|
||||
return rr.services.getService(name)
|
||||
}
|
||||
|
||||
// HasMethod returns true if the given method is registered.
|
||||
//
|
||||
// The method uses a dotted notation as in "Service.Method".
|
||||
|
|
|
@ -77,10 +77,19 @@ func getValue(t reflect.Type) reflect.Value {
|
|||
|
||||
// serviceMap is a registry for services.
|
||||
type serviceMap struct {
|
||||
mutex sync.Mutex
|
||||
mutex sync.RWMutex
|
||||
services map[string]*service
|
||||
}
|
||||
|
||||
func (sm *serviceMap) getService(name string) interface{} {
|
||||
sm.mutex.RLock()
|
||||
defer sm.mutex.RUnlock()
|
||||
if sm.services == nil {
|
||||
return nil
|
||||
}
|
||||
return sm.services[name]
|
||||
}
|
||||
|
||||
// register adds a new service using reflection to extract its methods.
|
||||
func (sm *serviceMap) register(rcvr interface{}, name string) error {
|
||||
// Setup service.
|
||||
|
|
Loading…
Reference in New Issue
Block a user