Skip to content

Commit

Permalink
Rename Basic* ==> Default*
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelliott committed Aug 7, 2014
1 parent 691eeac commit 06f8510
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
14 changes: 8 additions & 6 deletions wampv2/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ type Broker interface {
}

// A super simple broker that matches URIs to Subscribers.
type BasicBroker struct {
type DefaultBroker struct {
routes map[URI]map[ID]Subscriber
subscriptions map[ID]URI
}

func NewBasicBroker() *BasicBroker {
return &BasicBroker{
func NewDefaultBroker() *DefaultBroker {
return &DefaultBroker{
routes: make(map[URI]map[ID]Subscriber),
subscriptions: make(map[ID]URI),
}
}

func (br *BasicBroker) Publish(pub Publisher, msg *Publish) {
func (br *DefaultBroker) Publish(pub Publisher, msg *Publish) {
pubId := NewID()
evtTemplate := Event{
Publication: pubId,
Expand All @@ -75,7 +75,8 @@ func (br *BasicBroker) Publish(pub Publisher, msg *Publish) {
pub.SendPublished(&Published{Request: msg.Request, Publication: pubId})
}
}
func (br *BasicBroker) Subscribe(sub Subscriber, msg *Subscribe) {

func (br *DefaultBroker) Subscribe(sub Subscriber, msg *Subscribe) {
if _, ok := br.routes[msg.Topic]; !ok {
br.routes[msg.Topic] = make(map[ID]Subscriber)
}
Expand All @@ -86,7 +87,8 @@ func (br *BasicBroker) Subscribe(sub Subscriber, msg *Subscribe) {

sub.SendSubscribed(&Subscribed{Request: msg.Request, Subscription: id})
}
func (br *BasicBroker) Unsubscribe(sub Subscriber, msg *Unsubscribe) {

func (br *DefaultBroker) Unsubscribe(sub Subscriber, msg *Unsubscribe) {
topic, ok := br.subscriptions[msg.Subscription]
if !ok {
err := &Error{
Expand Down
9 changes: 5 additions & 4 deletions wampv2/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ type Realm interface {
Broker() Broker
}

type BasicRealm struct {
type DefaultRealm struct {
}

func NewBasicRealm() *BasicRealm {
return &BasicRealm{}
func NewDefaultRealm() *DefaultRealm {
return &DefaultRealm{}
}
func (realm *BasicRealm) Broker() Broker {

func (realm *DefaultRealm) Broker() Broker {
return nil
}
26 changes: 13 additions & 13 deletions wampv2/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ type Router interface {
RegisterRealm(URI, Realm) error
}

// BasicRouter is a very basic WAMP router.
type BasicRouter struct {
*BasicBroker
// DefaultRouter is a very basic WAMP router.
type DefaultRouter struct {
*DefaultBroker

realms map[URI]Realm
clients map[URI][]Session
closing bool
lastId int
}

func NewBasicRouter() *BasicRouter {
return &BasicRouter{
BasicBroker: NewBasicBroker(),
realms: make(map[URI]Realm),
clients: make(map[URI][]Session),
func NewDefaultRouter() *DefaultRouter {
return &DefaultRouter{
DefaultBroker: NewDefaultBroker(),
realms: make(map[URI]Realm),
clients: make(map[URI][]Session),
}
}

func (r *BasicRouter) Close() error {
func (r *DefaultRouter) Close() error {
r.closing = true
for _, clients := range r.clients {
for _, client := range clients {
Expand All @@ -56,22 +56,22 @@ func (r *BasicRouter) Close() error {
return nil
}

func (r *BasicRouter) RegisterRealm(uri URI, realm Realm) error {
func (r *DefaultRouter) RegisterRealm(uri URI, realm Realm) error {
if _, ok := r.realms[uri]; ok {
return realmExists(uri)
}
r.realms[uri] = realm
return nil
}

func (r *BasicRouter) broker(realm URI) Broker {
func (r *DefaultRouter) broker(realm URI) Broker {
if br := r.realms[realm].Broker(); br != nil {
return br
}
return r
}

func (r *BasicRouter) handleSession(sess Session, realm URI) {
func (r *DefaultRouter) handleSession(sess Session, realm URI) {
defer sess.Close()

c := sess.Receive()
Expand Down Expand Up @@ -136,7 +136,7 @@ func (r *BasicRouter) handleSession(sess Session, realm URI) {
}
}

func (r *BasicRouter) Accept(ep Endpoint) error {
func (r *DefaultRouter) Accept(ep Endpoint) error {
if r.closing {
ep.Send(&Abort{Reason: WAMP_ERROR_SYSTEM_SHUTDOWN})
ep.Close()
Expand Down
8 changes: 4 additions & 4 deletions wampv2/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func (ep *basicEndpoint) Close() error {
return nil
}

func basicConnect(t *testing.T, ep *basicEndpoint, server Endpoint) *BasicRouter {
r := NewBasicRouter()
r.RegisterRealm(test_realm, NewBasicRealm())
func basicConnect(t *testing.T, ep *basicEndpoint, server Endpoint) *DefaultRouter {
r := NewDefaultRouter()
r.RegisterRealm(test_realm, NewDefaultRealm())

ep.Send(&Hello{Realm: test_realm})
if err := r.Accept(server); err != nil {
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestHandshake(t *testing.T) {
}

func TestInvalidRealm(t *testing.T) {
r := NewBasicRouter()
r := NewDefaultRouter()
defer r.Close()

client, server := pipe()
Expand Down
4 changes: 2 additions & 2 deletions wampv2/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

func newWebsocketServer(t *testing.T) (int, Router, io.Closer) {
r := NewBasicRouter()
r.RegisterRealm(test_realm, NewBasicRealm())
r := NewDefaultRouter()
r.RegisterRealm(test_realm, NewDefaultRealm())
s := NewWebsocketServer(r)
s.RegisterProtocol(jsonWebsocketProtocol, websocket.TextMessage, new(JSONSerializer))
s.RegisterProtocol(msgpackWebsocketProtocol, websocket.BinaryMessage, new(MessagePackSerializer))
Expand Down

0 comments on commit 06f8510

Please sign in to comment.