Преглед изворни кода

[revise] 길호님 수정하다 만 버전

master
kidjung пре 4 година
родитељ
комит
af5cab5cf8

+ 1
- 0
src/broker/modules/AppConfig.go Прегледај датотеку

15
 		&inject.Object{Value: NewMStable()},
15
 		&inject.Object{Value: NewMStable()},
16
 		&inject.Object{Value: app.application},
16
 		&inject.Object{Value: app.application},
17
 		&inject.Object{Value: NewSecurity()})
17
 		&inject.Object{Value: NewSecurity()})
18
+
18
 	if err != nil {
19
 	if err != nil {
19
 		println(err)
20
 		println(err)
20
 		return nil
21
 		return nil

+ 16
- 14
src/broker/modules/init.go Прегледај датотеку

4
 	"encoding/json"
4
 	"encoding/json"
5
 	"errors"
5
 	"errors"
6
 	"fmt"
6
 	"fmt"
7
-	_ "github.com/fatih/color"
7
+	"github.com/fatih/color"
8
 	"log"
8
 	"log"
9
 	"net"
9
 	"net"
10
 	"net/rpc"
10
 	"net/rpc"
14
 
14
 
15
 type Moscato struct {
15
 type Moscato struct {
16
 	queue               MsgQueue
16
 	queue               MsgQueue
17
-	SendQueue			chan myType
17
+	SendQueue           chan myType
18
 	MicroServiceManager NodeManager `inject:""`
18
 	MicroServiceManager NodeManager `inject:""`
19
 	MatchingManager     match_manager
19
 	MatchingManager     match_manager
20
-	Subscriptionmanager	sub_manager
20
+	SubscriptionManager sub_manager
21
 	SecureManager       SecurityManager `inject:""`
21
 	SecureManager       SecurityManager `inject:""`
22
 }
22
 }
23
 
23
 
24
-type myType struct{
25
-	subList	[]string
26
-	pubMsg	MsgUnit
27
-	err		error
24
+type myType struct {
25
+	subList []string
26
+	pubMsg  MsgUnit
27
+	err     error
28
 }
28
 }
29
 
29
 
30
 type Reply struct {
30
 type Reply struct {
83
 
83
 
84
 			}
84
 			}
85
 		}()
85
 		}()
86
-		reply.CompleteLog = "received"
86
+		reply.CompleteLog = "SM received"
87
 	case RM:
87
 	case RM:
88
 		var msg RegisterMsg
88
 		var msg RegisterMsg
89
 		err := json.Unmarshal(args.JsonMsg, &msg)
89
 		err := json.Unmarshal(args.JsonMsg, &msg)
135
 
135
 
136
 	case PM: //Publish msg
136
 	case PM: //Publish msg
137
 		log.Println("PM received")
137
 		log.Println("PM received")
138
+		fmt.Println("PM: ", msg)
138
 		moscato.queue.push(msg.(PublishMsg))
139
 		moscato.queue.push(msg.(PublishMsg))
139
 
140
 
140
 	case SM: //Subscription msg
141
 	case SM: //Subscription msg
141
-		moscato.Subscriptionmanager.addSubscription(msg.(*SubscriptionMsg))
142
+		fmt.Println("SM: ", msg)
143
+		moscato.SubscriptionManager.addSubscription(msg)
142
 
144
 
143
 	case RM: //Register msg
145
 	case RM: //Register msg
144
 		log.Println("RM received")
146
 		log.Println("RM received")
206
 	receiver := Receiver{moscato: moscato}
208
 	receiver := Receiver{moscato: moscato}
207
 	err := moscato.queue.queue_init()
209
 	err := moscato.queue.queue_init()
208
 	moscato.SendQueue = make(chan myType)
210
 	moscato.SendQueue = make(chan myType)
209
-	moscato.Subscriptionmanager.Initialize()
211
+	moscato.SubscriptionManager.Initialize()
210
 
212
 
211
 	if err != nil {
213
 	if err != nil {
212
 		fmt.Println(err)
214
 		fmt.Println(err)
213
 		return
215
 		return
214
 	}
216
 	}
215
 
217
 
216
-
217
 	//go routine -> matching 동작
218
 	//go routine -> matching 동작
218
 	go moscato.Matching()
219
 	go moscato.Matching()
219
-	go moscato.CheckQueue()
220
+
221
+	//go moscato.CheckQueue()
220
 
222
 
221
 	//rpc 등록 -> Receive 함수
223
 	//rpc 등록 -> Receive 함수
222
 	err = rpc.Register(receiver)
224
 	err = rpc.Register(receiver)
226
 	}
228
 	}
227
 
229
 
228
 	go Listen()
230
 	go Listen()
229
-	//color.Blue("initializing complete.")
231
+	color.Blue("initializing complete.")
230
 	fmt.Scanln()
232
 	fmt.Scanln()
231
 }
233
 }
232
 
234
 
252
 		conn, _ := l2.Accept()
254
 		conn, _ := l2.Accept()
253
 		go rpc.ServeConn(conn)
255
 		go rpc.ServeConn(conn)
254
 	}*/
256
 	}*/
255
-}
257
+}

+ 1
- 1
src/broker/modules/list.go Прегледај датотеку

102
 	return empty
102
 	return empty
103
 }
103
 }
104
 
104
 
105
-// To insert sub# into the operator list of the Value node
105
+// To insert sub# into the Operator list of the Value node
106
 func (n *valueNode) insertSub(op string, sub int, issingle bool) {
106
 func (n *valueNode) insertSub(op string, sub int, issingle bool) {
107
 	if issingle == true {
107
 	if issingle == true {
108
 		switch op {
108
 		switch op {

+ 17
- 7
src/broker/modules/matching.go Прегледај датотеку

3
 import (
3
 import (
4
 	"errors"
4
 	"errors"
5
 	_ "errors"
5
 	_ "errors"
6
+	"fmt"
6
 	"github.com/juliangruber/go-intersect"
7
 	"github.com/juliangruber/go-intersect"
7
 	"reflect"
8
 	"reflect"
8
 )
9
 )
12
 }
13
 }
13
 
14
 
14
 // Matching -> Return (list of IP addresses of matched subs, Pub Msg, error)
15
 // Matching -> Return (list of IP addresses of matched subs, Pub Msg, error)
15
-func (moscato * Moscato) Matching() {
16
+func (moscato *Moscato) Matching() {
16
 	msg := moscato.queue.pop(true)
17
 	msg := moscato.queue.pop(true)
17
-	topic := msg.(*PublishMsg).Topic
18
-	value := msg.(*PublishMsg).Value
19
-	sub_mng := moscato.Subscriptionmanager
20
-	// list
18
+	topic := msg.(PublishMsg).Topic
19
+	value := msg.(PublishMsg).Value
20
+	sub_mng := moscato.SubscriptionManager
21
+
22
+	fmt.Println("matchßing st")
23
+
24
+	fmt.Println("value = ", value)
25
+
26
+	// listß
21
 	ret := make([]string, 0)
27
 	ret := make([]string, 0)
22
 
28
 
23
 	// list for matched range subscriptions
29
 	// list for matched range subscriptions
24
 	big := make([]int, 0)
30
 	big := make([]int, 0)
25
 	small := make([]int, 0)
31
 	small := make([]int, 0)
26
 
32
 
27
-	// 1. Find (topicNode[topic] == msg.topic) Node
33
+	// 1. Find (topicNode[Topic] == msg.Topic) Node
28
 	topicPtr := sub_mng.list
34
 	topicPtr := sub_mng.list
29
 	pos := topicPtr.getTopicNodePos(topic)
35
 	pos := topicPtr.getTopicNodePos(topic)
30
 
36
 
151
 			ret = append(ret, ip)
157
 			ret = append(ret, ip)
152
 		}
158
 		}
153
 
159
 
160
+		fmt.Println("Big =", big)
161
+		fmt.Println("small =", small)
162
+
163
+		fmt.Println("matching: ", ret)
154
 		moscato.MatchingManager.match_count++
164
 		moscato.MatchingManager.match_count++
155
 		moscato.SendQueue <- myType{ret, msg, nil}
165
 		moscato.SendQueue <- myType{ret, msg, nil}
156
 	}
166
 	}
157
-}
167
+}

+ 4
- 4
src/broker/modules/message.go Прегледај датотеку

56
 //구독 정보를 담은 메세지
56
 //구독 정보를 담은 메세지
57
 type SubscriptionMsg struct {
57
 type SubscriptionMsg struct {
58
 	Message
58
 	Message
59
-	topic    []int64  //대주제
60
-	value    []int64  //피연산자
61
-	operator []string //연산자
62
-	isAlpha  bool     //value가 숫자인지 문자열인지
59
+	Topic    []int64  //대주제
60
+	Value    []int64  //피연산자
61
+	Operator []string //연산자
62
+	IsAlpha  bool     //value가 숫자인지 문자열인지
63
 }
63
 }
64
 
64
 
65
 //Microservice 등록 메세지
65
 //Microservice 등록 메세지

+ 20
- 17
src/broker/modules/subscription.go Прегледај датотеку

2
 
2
 
3
 import (
3
 import (
4
 	"errors"
4
 	"errors"
5
+	"fmt"
5
 )
6
 )
6
 
7
 
7
 type sub_manager struct {
8
 type sub_manager struct {
33
 //	### To Insert sub#
34
 //	### To Insert sub#
34
 func (manager *sub_manager) addSubscription(msg MsgUnit) error {
35
 func (manager *sub_manager) addSubscription(msg MsgUnit) error {
35
 
36
 
36
-	topic := msg.(*SubscriptionMsg).topic
37
-	value := msg.(*SubscriptionMsg).value
38
-	operator := msg.(*SubscriptionMsg).operator
37
+	topic := msg.(SubscriptionMsg).Topic
38
+	value := msg.(SubscriptionMsg).Value
39
+	operator := msg.(SubscriptionMsg).Operator
39
 	subnumber := 0
40
 	subnumber := 0
40
-
41
 	// * 1. Mapping incoming IP address to sub #
41
 	// * 1. Mapping incoming IP address to sub #
42
 
42
 
43
+	fmt.Println("add sub st")
44
+	fmt.Println("sub val", value)
45
+
43
 	if len(manager.emptylist) == 0 {
46
 	if len(manager.emptylist) == 0 {
44
 		subnumber = manager.count_sub
47
 		subnumber = manager.count_sub
45
-		manager.ip2sub[msg.(*SubscriptionMsg).From] = append(manager.ip2sub[msg.(*SubscriptionMsg).From], manager.count_sub)
46
-		manager.sub2ip[subnumber] = msg.(*SubscriptionMsg).From
48
+		manager.ip2sub[msg.(SubscriptionMsg).From] = append(manager.ip2sub[msg.(SubscriptionMsg).From], manager.count_sub)
49
+		manager.sub2ip[subnumber] = msg.(SubscriptionMsg).From
47
 		manager.count_sub++
50
 		manager.count_sub++
48
 	} else {
51
 	} else {
49
 		subnumber := manager.emptylist[len(manager.emptylist)-1]
52
 		subnumber := manager.emptylist[len(manager.emptylist)-1]
50
 		manager.emptylist = manager.emptylist[:len(manager.emptylist)-1]
53
 		manager.emptylist = manager.emptylist[:len(manager.emptylist)-1]
51
-		manager.ip2sub[msg.(*SubscriptionMsg).From] = append(manager.ip2sub[msg.(*SubscriptionMsg).From], subnumber)
52
-		manager.sub2ip[subnumber] = msg.(*SubscriptionMsg).From
54
+		manager.ip2sub[msg.(SubscriptionMsg).From] = append(manager.ip2sub[msg.(SubscriptionMsg).From], subnumber)
55
+		manager.sub2ip[subnumber] = msg.(SubscriptionMsg).From
53
 	}
56
 	}
54
 
57
 
55
 	nameptr := manager.list.head
58
 	nameptr := manager.list.head
71
 		nameptr = manager.list.tail
74
 		nameptr = manager.list.tail
72
 	}
75
 	}
73
 
76
 
74
-	// Add value to list[name]
77
+	// Add Value to list[name]
75
 	if len(operator) == 1 { // if single expression
78
 	if len(operator) == 1 { // if single expression
76
 		valptr := nameptr.list.getValueNodePos(value)
79
 		valptr := nameptr.list.getValueNodePos(value)
77
 		if valptr == nil {
80
 		if valptr == nil {
86
 
89
 
87
 		// For compound expressions bounded by '&&' and '||'
90
 		// For compound expressions bounded by '&&' and '||'
88
 		// (ex) { (234 < x) && (x <= 1293) } , { (234 < x) || ( x < 1293) }
91
 		// (ex) { (234 < x) && (x <= 1293) } , { (234 < x) || ( x < 1293) }
89
-		logical_operator := operator[1]
92
+		logical_operator := operator[2]
90
 
93
 
91
-		// Find ValueNode = (namelist[name].list.val == value)
94
+		// Find ValueNode = (namelist[name].list.val == Value)
92
 		valptr1 := nameptr.list.getValueNodePos([]int64{value[0]})
95
 		valptr1 := nameptr.list.getValueNodePos([]int64{value[0]})
93
-		valptr2 := nameptr.list.getValueNodePos([]int64{value[1]})
96
+		valptr2 := nameptr.list.getValueNodePos([]int64{value[2]})
94
 
97
 
95
 		if valptr1 == nil {
98
 		if valptr1 == nil {
96
 			nameptr.list.addValueNode([]int64{value[0]})
99
 			nameptr.list.addValueNode([]int64{value[0]})
97
 			valptr1 = nameptr.list.tail
100
 			valptr1 = nameptr.list.tail
98
 		}
101
 		}
99
 		if valptr2 == nil {
102
 		if valptr2 == nil {
100
-			nameptr.list.addValueNode([]int64{value[1]})
103
+			nameptr.list.addValueNode([]int64{value[2]})
101
 			valptr2 = nameptr.list.tail
104
 			valptr2 = nameptr.list.tail
102
 		}
105
 		}
103
 
106
 
105
 		manager.sub2node[subnumber] = append(manager.sub2node[subnumber], valptr2)
108
 		manager.sub2node[subnumber] = append(manager.sub2node[subnumber], valptr2)
106
 
109
 
107
 		if logical_operator == "&&" {
110
 		if logical_operator == "&&" {
108
-			// If they are enclosed in '&&' -> Insert value to range_operator_list
111
+			// If they are enclosed in '&&' -> Insert Value to range_operator_list
109
 			manager.israngesub[subnumber] = true
112
 			manager.israngesub[subnumber] = true
110
 			valptr1.insertSub(operator[0], subnumber, false)
113
 			valptr1.insertSub(operator[0], subnumber, false)
111
-			valptr2.insertSub(operator[2], subnumber, false)
114
+			valptr2.insertSub(operator[4], subnumber, false)
112
 
115
 
113
 		} else {
116
 		} else {
114
-			// if they are enclosed in '||' -> Insert value to single_operator_list
117
+			// if they are enclosed in '||' -> Insert Value to single_operator_list
115
 			valptr1.insertSub(operator[0], subnumber, true)
118
 			valptr1.insertSub(operator[0], subnumber, true)
116
-			valptr2.insertSub(operator[2], subnumber, true)
119
+			valptr2.insertSub(operator[4], subnumber, true)
117
 		}
120
 		}
118
 
121
 
119
 		return nil // addSubscription ok
122
 		return nil // addSubscription ok

Loading…
Откажи
Сачувај