Skip to content

Commit

Permalink
Factor Registrar out of Registry
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Nov 9, 2016
1 parent 9245832 commit 7207eae
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crossdock/server/yarpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Stop() {
}
}

func register(reg transport.Registry) {
func register(reg transport.Registrar) {
reg.Register(raw.Procedure("echo/raw", EchoRaw))
reg.Register(json.Procedure("echo", EchoJSON))

Expand Down
8 changes: 4 additions & 4 deletions dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
// Clients to send RPCs, and by Procedures to recieve them. This object is what
// enables an application to be transport-agnostic.
type Dispatcher interface {
transport.Registry
transport.Registrar
transport.ChannelProvider

// Inbounds returns a copy of the list of inbounds for this RPC object.
Expand Down Expand Up @@ -79,7 +79,7 @@ func NewDispatcher(cfg Config) Dispatcher {

return dispatcher{
Name: cfg.Name,
Registry: transport.NewMapRegistry(cfg.Name),
Registrar: transport.NewMapRegistry(cfg.Name),
inbounds: cfg.Inbounds,
Outbounds: cfg.Outbounds,
Filter: cfg.Filter,
Expand All @@ -92,7 +92,7 @@ func NewDispatcher(cfg Config) Dispatcher {
//
// It allows use of multiple Inbounds and Outbounds together.
type dispatcher struct {
transport.Registry
transport.Registrar

Name string
Outbounds transport.Outbounds
Expand Down Expand Up @@ -192,7 +192,7 @@ func (d dispatcher) Register(rs []transport.Registrant) {
r.Handler = transport.ApplyInterceptor(r.Handler, d.Interceptor)
rs[i] = r
}
d.Registry.Register(rs)
d.Registrar.Register(rs)
}

func (d dispatcher) Stop() error {
Expand Down
6 changes: 3 additions & 3 deletions encoding/json/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ var (
_interfaceEmptyType = reflect.TypeOf((*interface{})(nil)).Elem()
)

// Register calls the Registry's Register method.
// Register calls the Registrar's Register method.
//
// This function exists for backwards compatibility only. It will be removed
// in a future version.
//
// Deprecated: Use the Registry's Register method directly.
func Register(r transport.Registry, rs []transport.Registrant) {
// Deprecated: Use the Registrar's Register method directly.
func Register(r transport.Registrar, rs []transport.Registrant) {
r.Register(rs)
}

Expand Down
6 changes: 3 additions & 3 deletions encoding/raw/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import (
"go.uber.org/yarpc/transport"
)

// Register calls the Registry's Register method.
// Register calls the Registrar's Register method.
//
// This function exists for backwards compatibility only. It will be removed
// in a future version.
//
// Deprecated: Use the Registry's Register method directly.
func Register(r transport.Registry, rs []transport.Registrant) {
// Deprecated: Use the Registrar's Register method directly.
func Register(r transport.Registrar, rs []transport.Registrant) {
r.Register(rs)
}

Expand Down
6 changes: 3 additions & 3 deletions encoding/thrift/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ import (
"go.uber.org/thriftrw/wire"
)

// Register calls the Registry's Register method.
// Register calls the Registrar's Register method.
//
// This function exists for backwards compatibility only. It will be removed
// in a future version.
//
// Deprecated: Use the Registry's Register method directly.
func Register(r transport.Registry, rs []transport.Registrant) {
// Deprecated: Use the Registrar's Register method directly.
func Register(r transport.Registrar, rs []transport.Registrant) {
r.Register(rs)
}

Expand Down
11 changes: 8 additions & 3 deletions transport/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ type Registrant struct {
// Registry maintains and provides access to a collection of procedures and
// their handlers.
type Registry interface {
// Registers zero or more registrants with the registry.
Register([]Registrant)

// ServiceProcedures returns a list of services and their procedures that
// have been registered so far.
ServiceProcedures() []ServiceProcedure
Expand All @@ -69,6 +66,14 @@ type Registry interface {
GetHandler(service, procedure string) (Handler, error)
}

// Registrar provides access to a collection of procedures and their handlers.
type Registrar interface {
Registry

// Registers zero or more registrants with the registry.
Register([]Registrant)
}

// MapRegistry is a Registry that maintains a map of the registered
// procedures.
type MapRegistry struct {
Expand Down

0 comments on commit 7207eae

Please sign in to comment.