Skip to content

Commit

Permalink
registry: log subscribe/unsubscribe messages only when the action act…
Browse files Browse the repository at this point in the history
…ually takes place
  • Loading branch information
mmatczuk committed Nov 25, 2017
1 parent c2c50bf commit 1700712
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ var voidRegistryItem = &RegistryItem{}

// Subscribe allows to connect client with a given identifier.
func (r *registry) Subscribe(identifier id.ID) {
r.logger.Log(
"level", 1,
"action", "subscribe",
"identifier", identifier,
)

r.mu.Lock()
defer r.mu.Unlock()

if _, ok := r.items[identifier]; ok {
return
}

r.logger.Log(
"level", 1,
"action", "subscribe",
"identifier", identifier,
)

r.items[identifier] = voidRegistryItem
}

Expand All @@ -93,12 +93,6 @@ func (r *registry) Subscriber(hostPort string) (id.ID, *Auth, bool) {

// Unsubscribe removes client from registry and returns it's RegistryItem.
func (r *registry) Unsubscribe(identifier id.ID) *RegistryItem {
r.logger.Log(
"level", 1,
"action", "unsubscribe",
"identifier", identifier,
)

r.mu.Lock()
defer r.mu.Unlock()

Expand All @@ -107,6 +101,12 @@ func (r *registry) Unsubscribe(identifier id.ID) *RegistryItem {
return nil
}

r.logger.Log(
"level", 1,
"action", "unsubscribe",
"identifier", identifier,
)

if i.Hosts != nil {
for _, h := range i.Hosts {
delete(r.hosts, h.Host)
Expand Down

0 comments on commit 1700712

Please sign in to comment.