Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
Cloud
MAS
clonemap
Commits
29314085
Commit
29314085
authored
Jun 04, 2020
by
Stefan Dähling
Browse files
df close
parent
15bd3bce
Pipeline
#290170
passed with stages
in 1 minute and 9 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pkg/agency/agent.go
View file @
29314085
...
@@ -145,4 +145,5 @@ func (agent *Agent) Terminate() {
...
@@ -145,4 +145,5 @@ func (agent *Agent) Terminate() {
agent
.
ACL
.
close
()
agent
.
ACL
.
close
()
agent
.
Logger
.
close
()
agent
.
Logger
.
close
()
agent
.
MQTT
.
close
()
agent
.
MQTT
.
close
()
agent
.
DF
.
close
()
}
}
pkg/agency/df.go
View file @
29314085
...
@@ -200,3 +200,16 @@ func newDF(masID int, agentID int, nodeID int, logErr *log.Logger, logInf *log.L
...
@@ -200,3 +200,16 @@ func newDF(masID int, agentID int, nodeID int, logErr *log.Logger, logInf *log.L
df
.
registeredServices
=
make
(
map
[
string
]
schemas
.
Service
)
df
.
registeredServices
=
make
(
map
[
string
]
schemas
.
Service
)
return
return
}
}
// close closes the DF module
func
(
df
*
DF
)
close
()
{
for
d
:=
range
df
.
registeredServices
{
svc
:=
df
.
registeredServices
[
d
]
df
.
DeregisterService
(
svc
.
GUID
)
}
df
.
mutex
.
Lock
()
df
.
logInfo
.
Println
(
"Closing DF of agent "
,
df
.
agentID
)
df
.
active
=
false
df
.
mutex
.
Unlock
()
return
}
pkg/agency/mqtt.go
View file @
29314085
...
@@ -59,6 +59,7 @@ import (
...
@@ -59,6 +59,7 @@ import (
type
MQTT
struct
{
type
MQTT
struct
{
client
*
mqttClient
client
*
mqttClient
mutex
*
sync
.
Mutex
// mutex for message inbox map
mutex
*
sync
.
Mutex
// mutex for message inbox map
subTopic
map
[
string
]
interface
{}
// subscribed topics
msgInTopic
map
[
string
]
chan
schemas
.
MQTTMessage
// message inbox for messages with specified topic
msgInTopic
map
[
string
]
chan
schemas
.
MQTTMessage
// message inbox for messages with specified topic
msgIn
chan
schemas
.
MQTTMessage
// mqtt message inbox
msgIn
chan
schemas
.
MQTTMessage
// mqtt message inbox
agentID
int
agentID
int
...
@@ -80,6 +81,7 @@ func newMQTT(agentID int, cli *mqttClient, cmaplog *Logger, logErr *log.Logger,
...
@@ -80,6 +81,7 @@ func newMQTT(agentID int, cli *mqttClient, cmaplog *Logger, logErr *log.Logger,
logInfo
:
logInf
,
logInfo
:
logInf
,
active
:
true
,
active
:
true
,
}
}
mq
.
subTopic
=
make
(
map
[
string
]
interface
{})
mq
.
msgInTopic
=
make
(
map
[
string
]
chan
schemas
.
MQTTMessage
)
mq
.
msgInTopic
=
make
(
map
[
string
]
chan
schemas
.
MQTTMessage
)
mq
.
msgIn
=
make
(
chan
schemas
.
MQTTMessage
)
mq
.
msgIn
=
make
(
chan
schemas
.
MQTTMessage
)
return
return
...
@@ -87,8 +89,11 @@ func newMQTT(agentID int, cli *mqttClient, cmaplog *Logger, logErr *log.Logger,
...
@@ -87,8 +89,11 @@ func newMQTT(agentID int, cli *mqttClient, cmaplog *Logger, logErr *log.Logger,
// close closes the mqtt
// close closes the mqtt
func
(
mq
*
MQTT
)
close
()
{
func
(
mq
*
MQTT
)
close
()
{
for
t
:=
range
mq
.
subTopic
{
mq
.
Unsubscribe
(
t
)
}
mq
.
mutex
.
Lock
()
mq
.
mutex
.
Lock
()
mq
.
logInfo
.
Println
(
"Closing
Logger
of agent "
,
mq
.
agentID
)
mq
.
logInfo
.
Println
(
"Closing
MQTT
of agent "
,
mq
.
agentID
)
mq
.
active
=
false
mq
.
active
=
false
mq
.
mutex
.
Unlock
()
mq
.
mutex
.
Unlock
()
return
return
...
@@ -102,6 +107,13 @@ func (mq *MQTT) Subscribe(topic string, qos int) (err error) {
...
@@ -102,6 +107,13 @@ func (mq *MQTT) Subscribe(topic string, qos int) (err error) {
err
=
errors
.
New
(
"mqtt not active"
)
err
=
errors
.
New
(
"mqtt not active"
)
return
return
}
}
_
,
ok
:=
mq
.
subTopic
[
topic
]
mq
.
mutex
.
Unlock
()
if
ok
{
return
}
mq
.
mutex
.
Lock
()
mq
.
subTopic
[
topic
]
=
nil
mq
.
mutex
.
Unlock
()
mq
.
mutex
.
Unlock
()
err
=
mq
.
client
.
subscribe
(
mq
,
topic
,
qos
)
err
=
mq
.
client
.
subscribe
(
mq
,
topic
,
qos
)
return
return
...
@@ -115,6 +127,13 @@ func (mq *MQTT) Unsubscribe(topic string) (err error) {
...
@@ -115,6 +127,13 @@ func (mq *MQTT) Unsubscribe(topic string) (err error) {
err
=
errors
.
New
(
"mqtt not active"
)
err
=
errors
.
New
(
"mqtt not active"
)
return
return
}
}
_
,
ok
:=
mq
.
subTopic
[
topic
]
mq
.
mutex
.
Unlock
()
if
!
ok
{
return
}
mq
.
mutex
.
Lock
()
delete
(
mq
.
subTopic
,
topic
)
mq
.
mutex
.
Unlock
()
mq
.
mutex
.
Unlock
()
err
=
mq
.
client
.
unsubscribe
(
mq
,
topic
)
err
=
mq
.
client
.
unsubscribe
(
mq
,
topic
)
return
return
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment