• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / servicecomb-kie / 214

28 Dec 2019 08:06AM UTC coverage: 53.976% (+7.3%) from 46.679%
214

Pull #58

travis-ci

web-flow
SCB-1549 peer to peer event notification
Pull Request #58: SCB-1549 peer to peer event notification

174 of 307 new or added lines in 10 files covered. (56.68%)

5 existing lines in 4 files now uncovered.

733 of 1358 relevant lines covered (53.98%)

1.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.26
/server/pubsub/event_handler.go
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17

18
package pubsub
19

20
import (
21
        "github.com/go-mesh/openlogging"
22
        "github.com/hashicorp/serf/serf"
23
        "strings"
24
)
25

26
//EventHandler handler serf custom event
27
type EventHandler struct {
28
}
29

30
//HandleEvent send event to subscribers
31
func (h *EventHandler) HandleEvent(e serf.Event) {
2✔
32
        openlogging.Info("receive event:" + e.EventType().String())
2✔
33
        switch e.EventType().String() {
2✔
34
        case "user":
1✔
35
                if strings.Contains(e.String(), EventKVChange) {
2✔
36
                        ue := e.(serf.UserEvent)
1✔
37
                        ke, err := NewKVChangeEvent(ue.Payload)
1✔
38
                        if err != nil {
1✔
NEW
39
                                openlogging.Error("invalid json:" + string(ue.Payload))
×
NEW
40
                        }
×
41
                        openlogging.Debug("kv event:" + ke.Key)
1✔
42
                        topics.Range(func(key, value interface{}) bool { //range all topics
2✔
43
                                t, err := ParseTopicString(key.(string))
1✔
44
                                if err != nil {
1✔
NEW
45
                                        openlogging.Error("can not parse topic:" + key.(string))
×
NEW
46
                                        return true
×
NEW
47
                                }
×
48
                                if t.Match(ke) {
2✔
49
                                        observers := value.(map[string]*Observer)
1✔
50
                                        mutexObservers.Lock()
1✔
51
                                        defer mutexObservers.Unlock()
1✔
52
                                        for k, v := range observers {
1✔
53
                                                v.Event <- ke
54
                                                delete(observers, k)
55
                                        }
56
                                }
57
                                return true
1✔
58
                        })
59
                }
60

61
        }
62

63
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc