if already subscribed, this will *resubscribe* with the new subscription (remove the old one, and replace with this one)
(subRouteId string, sub SubscriptionRequest)
| 73 | |
| 74 | // if already subscribed, this will *resubscribe* with the new subscription (remove the old one, and replace with this one) |
| 75 | func (b *BrokerType) Subscribe(subRouteId string, sub SubscriptionRequest) { |
| 76 | // log.Printf("[wps] sub %s %s\n", subRouteId, sub.Event) |
| 77 | if sub.Event == "" { |
| 78 | return |
| 79 | } |
| 80 | b.Lock.Lock() |
| 81 | defer b.Lock.Unlock() |
| 82 | b.unsubscribe_nolock(subRouteId, sub.Event) |
| 83 | bs := b.SubMap[sub.Event] |
| 84 | if bs == nil { |
| 85 | bs = &BrokerSubscription{ |
| 86 | AllSubs: []string{}, |
| 87 | ScopeSubs: make(map[string][]string), |
| 88 | StarSubs: make(map[string][]string), |
| 89 | } |
| 90 | b.SubMap[sub.Event] = bs |
| 91 | } |
| 92 | if sub.AllScopes { |
| 93 | bs.AllSubs = utilfn.AddElemToSliceUniq(bs.AllSubs, subRouteId) |
| 94 | return |
| 95 | } |
| 96 | for _, scope := range sub.Scopes { |
| 97 | starMatch := scopeHasStarMatch(scope) |
| 98 | if starMatch { |
| 99 | addStrToScopeMap(bs.StarSubs, scope, subRouteId) |
| 100 | } else { |
| 101 | addStrToScopeMap(bs.ScopeSubs, scope, subRouteId) |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | func (bs *BrokerSubscription) IsEmpty() bool { |
| 107 | return len(bs.AllSubs) == 0 && len(bs.ScopeSubs) == 0 && len(bs.StarSubs) == 0 |
no test coverage detected