Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
ipaaca
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
Social Cognitive Systems
ipaaca
Commits
df03ae53
Commit
df03ae53
authored
6 years ago
by
Ramin Yaghoubzadeh Torky
Browse files
Options
Downloads
Patches
Plain Diff
Python: gave MQTT backend time to publish final (atexit) retractions
parent
32699db3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ipaacalib/python/src/ipaaca/backend_mqtt.py
+17
-0
17 additions, 0 deletions
ipaacalib/python/src/ipaaca/backend_mqtt.py
with
17 additions
and
0 deletions
ipaacalib/python/src/ipaaca/backend_mqtt.py
+
17
−
0
View file @
df03ae53
...
...
@@ -108,6 +108,8 @@ else:
#self._mqtt_client.on_publish = self.mqtt_callback_on_publish
self
.
run_in_background
()
def
deactivate
(
self
):
pass
def
deactivate_internal
(
self
):
self
.
_mqtt_client
.
disconnect
()
self
.
_mqtt_client
=
None
def
run_in_background
(
self
):
...
...
@@ -130,6 +132,7 @@ else:
def
mqtt_callback_on_message
(
self
,
client
,
userdata
,
message
):
pass
def
publishData
(
self
,
data
):
print
(
'
Informer publishing
'
+
str
(
data
.
__class__
.
__name__
)
+
'
on
'
+
self
.
_scope
)
self
.
_mqtt_client
.
publish
(
self
.
_scope
,
ipaaca
.
converter
.
serialize
(
data
),
qos
=
2
)
class
BackgroundEventDispatcher
(
threading
.
Thread
):
...
...
@@ -166,6 +169,8 @@ else:
#self._mqtt_client.on_publish = self.mqtt_callback_on_publish
self
.
run_in_background
()
def
deactivate
(
self
):
pass
def
deactivate_internal
(
self
):
self
.
_mqtt_client
.
disconnect
()
self
.
_mqtt_client
=
None
def
run_in_background
(
self
):
...
...
@@ -191,6 +196,7 @@ else:
LOGGER
.
warning
(
'
MQTT disconnect for
'
+
str
(
self
.
_scope
)
+
'
with result code
'
+
str
(
rc
))
def
mqtt_callback_on_message
(
self
,
client
,
userdata
,
message
):
event
=
EventWrapper
(
ipaaca
.
converter
.
deserialize
(
message
.
payload
))
print
(
'
Received:
'
+
str
(
event
.
data
.
__class__
.
__name__
))
dispatcher
=
BackgroundEventDispatcher
(
event
,
self
.
_handlers
)
dispatcher
.
start
()
def
addHandler
(
self
,
handler
):
...
...
@@ -224,6 +230,8 @@ else:
#self._mqtt_client.on_publish = self.mqtt_callback_on_publish
self
.
run_in_background
()
def
deactivate
(
self
):
pass
def
deactivate_internal
(
self
):
self
.
_mqtt_client
.
disconnect
()
self
.
_mqtt_client
=
None
def
run_in_background
(
self
):
...
...
@@ -310,6 +318,8 @@ else:
#self._mqtt_client.on_publish = self.mqtt_callback_on_publish
self
.
run_in_background
()
def
deactivate
(
self
):
pass
def
deactivate_internal
(
self
):
self
.
_mqtt_client
.
disconnect
()
self
.
_mqtt_client
=
None
def
run_in_background
(
self
):
...
...
@@ -385,6 +395,7 @@ else:
# back-end initialization code
self
.
_config
=
ipaaca
.
config
.
get_global_config
()
self
.
_name
=
name
self
.
_participants
=
set
()
def
_get_name
(
self
):
return
self
.
_name
...
...
@@ -393,6 +404,8 @@ else:
def
teardown
(
self
):
LOGGER
.
info
(
'
MQTT teardown: waiting 1 sec for final deliveries
'
)
time
.
sleep
(
1
)
for
p
in
self
.
_participants
:
p
.
deactivate_internal
()
def
Scope
(
self
,
scope_str
):
'''
Scope adapter (glue replacing rsb.Scope)
'''
...
...
@@ -401,24 +414,28 @@ else:
def
createLocalServer
(
self
,
buffer_impl
,
scope
,
config
=
None
):
LOGGER
.
debug
(
'
Creating a LocalServer on
'
+
str
(
scope
))
s
=
LocalServer
(
buffer_impl
,
scope
,
self
.
_config
if
config
is
None
else
config
)
self
.
_participants
.
add
(
s
)
s
.
_live_event
.
wait
(
30.0
)
return
s
def
createRemoteServer
(
self
,
scope
,
config
=
None
):
LOGGER
.
debug
(
'
Creating a RemoteServer on
'
+
str
(
scope
))
s
=
RemoteServer
(
scope
,
self
.
_config
if
config
is
None
else
config
)
self
.
_participants
.
add
(
s
)
s
.
_live_event
.
wait
(
30.0
)
return
s
def
createInformer
(
self
,
scope
,
config
=
None
,
dataType
=
"
ignored in this backend
"
):
LOGGER
.
debug
(
'
Creating an Informer on
'
+
str
(
scope
))
s
=
Informer
(
scope
,
self
.
_config
if
config
is
None
else
config
)
self
.
_participants
.
add
(
s
)
s
.
_live_event
.
wait
(
30.0
)
return
s
def
createListener
(
self
,
scope
,
config
=
None
):
LOGGER
.
debug
(
'
Creating a Listener on
'
+
str
(
scope
))
s
=
Listener
(
scope
,
self
.
_config
if
config
is
None
else
config
)
self
.
_participants
.
add
(
s
)
s
.
_live_event
.
wait
(
30.0
)
return
s
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment