Kaynağa Gözat

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

master
kidjung 4 yıl önce
ebeveyn
işleme
af5cab5cf8

+ 1
- 0
src/broker/modules/AppConfig.go Dosyayı Görüntüle

@@ -15,6 +15,7 @@ func (app *AppConfig) config() *Moscato {
15 15
 		&inject.Object{Value: NewMStable()},
16 16
 		&inject.Object{Value: app.application},
17 17
 		&inject.Object{Value: NewSecurity()})
18
+
18 19
 	if err != nil {
19 20
 		println(err)
20 21
 		return nil

+ 16
- 14
src/broker/modules/init.go Dosyayı Görüntüle

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

+ 1
- 1
src/broker/modules/list.go Dosyayı Görüntüle

@@ -102,7 +102,7 @@ func (n *valueNode) isEmpty() bool {
102 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 106
 func (n *valueNode) insertSub(op string, sub int, issingle bool) {
107 107
 	if issingle == true {
108 108
 		switch op {

+ 17
- 7
src/broker/modules/matching.go Dosyayı Görüntüle

@@ -3,6 +3,7 @@ package modules
3 3
 import (
4 4
 	"errors"
5 5
 	_ "errors"
6
+	"fmt"
6 7
 	"github.com/juliangruber/go-intersect"
7 8
 	"reflect"
8 9
 )
@@ -12,19 +13,24 @@ type match_manager struct {
12 13
 }
13 14
 
14 15
 // Matching -> Return (list of IP addresses of matched subs, Pub Msg, error)
15
-func (moscato * Moscato) Matching() {
16
+func (moscato *Moscato) Matching() {
16 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 27
 	ret := make([]string, 0)
22 28
 
23 29
 	// list for matched range subscriptions
24 30
 	big := make([]int, 0)
25 31
 	small := make([]int, 0)
26 32
 
27
-	// 1. Find (topicNode[topic] == msg.topic) Node
33
+	// 1. Find (topicNode[Topic] == msg.Topic) Node
28 34
 	topicPtr := sub_mng.list
29 35
 	pos := topicPtr.getTopicNodePos(topic)
30 36
 
@@ -151,7 +157,11 @@ func (moscato * Moscato) Matching() {
151 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 164
 		moscato.MatchingManager.match_count++
155 165
 		moscato.SendQueue <- myType{ret, msg, nil}
156 166
 	}
157
-}
167
+}

+ 4
- 4
src/broker/modules/message.go Dosyayı Görüntüle

@@ -56,10 +56,10 @@ type PublishMsg struct {
56 56
 //구독 정보를 담은 메세지
57 57
 type SubscriptionMsg struct {
58 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 65
 //Microservice 등록 메세지

+ 20
- 17
src/broker/modules/subscription.go Dosyayı Görüntüle

@@ -2,6 +2,7 @@ package modules
2 2
 
3 3
 import (
4 4
 	"errors"
5
+	"fmt"
5 6
 )
6 7
 
7 8
 type sub_manager struct {
@@ -33,23 +34,25 @@ func newSubmng() *sub_manager {
33 34
 //	### To Insert sub#
34 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 40
 	subnumber := 0
40
-
41 41
 	// * 1. Mapping incoming IP address to sub #
42 42
 
43
+	fmt.Println("add sub st")
44
+	fmt.Println("sub val", value)
45
+
43 46
 	if len(manager.emptylist) == 0 {
44 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 50
 		manager.count_sub++
48 51
 	} else {
49 52
 		subnumber := manager.emptylist[len(manager.emptylist)-1]
50 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 58
 	nameptr := manager.list.head
@@ -71,7 +74,7 @@ func (manager *sub_manager) addSubscription(msg MsgUnit) error {
71 74
 		nameptr = manager.list.tail
72 75
 	}
73 76
 
74
-	// Add value to list[name]
77
+	// Add Value to list[name]
75 78
 	if len(operator) == 1 { // if single expression
76 79
 		valptr := nameptr.list.getValueNodePos(value)
77 80
 		if valptr == nil {
@@ -86,18 +89,18 @@ func (manager *sub_manager) addSubscription(msg MsgUnit) error {
86 89
 
87 90
 		// For compound expressions bounded by '&&' and '||'
88 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 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 98
 		if valptr1 == nil {
96 99
 			nameptr.list.addValueNode([]int64{value[0]})
97 100
 			valptr1 = nameptr.list.tail
98 101
 		}
99 102
 		if valptr2 == nil {
100
-			nameptr.list.addValueNode([]int64{value[1]})
103
+			nameptr.list.addValueNode([]int64{value[2]})
101 104
 			valptr2 = nameptr.list.tail
102 105
 		}
103 106
 
@@ -105,15 +108,15 @@ func (manager *sub_manager) addSubscription(msg MsgUnit) error {
105 108
 		manager.sub2node[subnumber] = append(manager.sub2node[subnumber], valptr2)
106 109
 
107 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 112
 			manager.israngesub[subnumber] = true
110 113
 			valptr1.insertSub(operator[0], subnumber, false)
111
-			valptr2.insertSub(operator[2], subnumber, false)
114
+			valptr2.insertSub(operator[4], subnumber, false)
112 115
 
113 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 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 122
 		return nil // addSubscription ok

Loading…
İptal
Kaydet