Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
6ba569af
Commit
6ba569af
authored
9 years ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
Task #8582: merged changes to PyMessaging back to trunk
parent
be9d1176
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
LCS/Messaging/python/messaging/Service.py
+49
-28
49 additions, 28 deletions
LCS/Messaging/python/messaging/Service.py
LCS/Messaging/python/messaging/messages.py
+2
-2
2 additions, 2 deletions
LCS/Messaging/python/messaging/messages.py
with
51 additions
and
30 deletions
LCS/Messaging/python/messaging/Service.py
+
49
−
28
View file @
6ba569af
...
@@ -50,7 +50,11 @@ class MessageHandlerInterface(object):
...
@@ -50,7 +50,11 @@ class MessageHandlerInterface(object):
handler.finalize_loop()
handler.finalize_loop()
"""
"""
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
**
kwargs
):
pass
# if you want your subclass to handle multiple services
# then you can specify for each service which method has to be called
# In case this map is empty, or the called service is not in this map,
# then the default handle_message is called
self
.
service2MethodMap
=
{}
def
prepare_loop
(
self
):
def
prepare_loop
(
self
):
"
Called before main processing loop is entered.
"
"
Called before main processing loop is entered.
"
...
@@ -73,7 +77,6 @@ class MessageHandlerInterface(object):
...
@@ -73,7 +77,6 @@ class MessageHandlerInterface(object):
"
Called after main processing loop is finished.
"
"
Called after main processing loop is finished.
"
pass
pass
# create service:
# create service:
class
Service
(
object
):
class
Service
(
object
):
...
@@ -296,15 +299,15 @@ class Service(object):
...
@@ -296,15 +299,15 @@ class Service(object):
try
:
try
:
# get the next message
# get the next message
msg
=
self
.
listener
.
receive
(
1
)
lofar_
msg
=
self
.
listener
.
receive
(
1
)
# retry if timed-out
# retry if timed-out
if
msg
is
None
:
if
lofar_
msg
is
None
:
continue
continue
# report if messages are not Service Messages
# report if messages are not Service Messages
if
isinstance
(
msg
,
RequestMessage
)
is
not
True
:
if
not
isinstance
(
lofar_
msg
,
RequestMessage
):
logger
.
error
(
"
Received wrong messagetype %s, RequestMessage expected.
"
%
(
str
(
type
(
msg
))))
logger
.
error
(
"
Received wrong messagetype %s, RequestMessage expected.
"
%
(
str
(
type
(
lofar_
msg
))))
self
.
listener
.
ack
(
msg
)
self
.
listener
.
ack
(
lofar_
msg
)
continue
continue
# Keep track of number of received messages
# Keep track of number of received messages
...
@@ -313,33 +316,51 @@ class Service(object):
...
@@ -313,33 +316,51 @@ class Service(object):
# Execute the service handler function and send reply back to client
# Execute the service handler function and send reply back to client
try
:
try
:
self
.
_debug
(
"
Running handler
"
)
self
.
_debug
(
"
Running handler
"
)
# determine which handler method has to be called
if
hasattr
(
service_handler
,
'
service2MethodMap
'
)
and
lofar_msg
.
subject
in
service_handler
.
service2MethodMap
:
# pass the handling of this message on to the specific method for this service
serviceHandlerMethod
=
service_handler
.
service2MethodMap
[
lofar_msg
.
subject
]
else
:
serviceHandlerMethod
=
service_handler
.
handle_message
if
self
.
parsefullmessage
is
True
:
if
self
.
parsefullmessage
is
True
:
replymessage
=
service
_h
andler
.
handle_message
(
msg
)
replymessage
=
service
H
andler
Method
(
lofar_
msg
)
else
:
else
:
# check for positional arguments and named arguments
# check for positional arguments and named arguments
if
msg
.
has_args
==
"
True
"
:
# depending on presence of args and kwargs,
rpcargs
=
msg
.
content
# the signature of the handler method should vary as well
if
msg
.
has_kwargs
==
"
True
"
:
if
lofar_msg
.
has_args
and
lofar_msg
.
has_kwargs
:
# both positional and named arguments
# both positional and named arguments
rpckwargs
=
rpcargs
[
-
1
]
# rpcargs and rpckwargs are packed in the content
del
rpcargs
[
-
1
]
rpcargs
=
lofar_msg
.
content
rpcargs
=
tuple
(
rpcargs
)
replymessage
=
service_handler
.
handle_message
(
*
rpcargs
,
**
rpckwargs
)
# rpckwargs is the last argument in the content
else
:
# rpcargs is the rest in front
# only positional arguments
rpckwargs
=
rpcargs
[
-
1
]
rpcargs
=
tuple
(
rpcargs
)
del
rpcargs
[
-
1
]
replymessage
=
service_handler
.
handle_message
(
*
rpcargs
)
rpcargs
=
tuple
(
rpcargs
)
replymessage
=
serviceHandlerMethod
(
*
rpcargs
,
**
rpckwargs
)
elif
lofar_msg
.
has_args
:
# only positional arguments
# msg.content should be a list
rpcargs
=
tuple
(
lofar_msg
.
content
)
replymessage
=
serviceHandlerMethod
(
*
rpcargs
)
elif
lofar_msg
.
has_kwargs
:
# only named arguments
# msg.content should be a dict
rpckwargs
=
lofar_msg
.
content
replymessage
=
serviceHandlerMethod
(
**
rpckwargs
)
elif
lofar_msg
.
content
:
rpccontent
=
lofar_msg
.
content
replymessage
=
serviceHandlerMethod
(
rpccontent
)
else
:
else
:
if
msg
.
has_kwargs
==
"
True
"
:
replymessage
=
serviceHandlerMethod
()
# only named arguments
replymessage
=
service_handler
.
handle_message
(
**
(
msg
.
content
))
else
:
replymessage
=
service_handler
.
handle_message
(
msg
.
content
)
self
.
_debug
(
"
finished handler
"
)
self
.
_debug
(
"
finished handler
"
)
self
.
_send_reply
(
replymessage
,
"
OK
"
,
msg
.
reply_to
)
self
.
_send_reply
(
replymessage
,
"
OK
"
,
lofar_
msg
.
reply_to
)
self
.
okcounter
[
thread_idx
]
+=
1
self
.
okcounter
[
thread_idx
]
+=
1
self
.
listener
.
ack
(
msg
)
self
.
listener
.
ack
(
lofar_
msg
)
try
:
try
:
service_handler
.
finalize_handling
(
True
)
service_handler
.
finalize_handling
(
True
)
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -365,7 +386,7 @@ class Service(object):
...
@@ -365,7 +386,7 @@ class Service(object):
logger
.
info
(
"
[Service:] Status: %s
"
,
str
(
status
))
logger
.
info
(
"
[Service:] Status: %s
"
,
str
(
status
))
logger
.
info
(
"
[Service:] ERRTXT: %s
"
,
str
(
errtxt
))
logger
.
info
(
"
[Service:] ERRTXT: %s
"
,
str
(
errtxt
))
logger
.
info
(
"
[Service:] BackTrace: %s
"
,
str
(
backtrace
))
logger
.
info
(
"
[Service:] BackTrace: %s
"
,
str
(
backtrace
))
self
.
_send_reply
(
None
,
status
,
msg
.
reply_to
,
errtxt
=
errtxt
,
backtrace
=
backtrace
)
self
.
_send_reply
(
None
,
status
,
lofar_
msg
.
reply_to
,
errtxt
=
errtxt
,
backtrace
=
backtrace
)
try
:
try
:
service_handler
.
finalize_handling
(
False
)
service_handler
.
finalize_handling
(
False
)
except
Exception
as
e
:
except
Exception
as
e
:
...
...
This diff is collapsed.
Click to expand it.
LCS/Messaging/python/messaging/messages.py
+
2
−
2
View file @
6ba569af
...
@@ -295,8 +295,8 @@ class RequestMessage(LofarMessage):
...
@@ -295,8 +295,8 @@ class RequestMessage(LofarMessage):
#reply_to = kwargs.pop("reply_to",None)
#reply_to = kwargs.pop("reply_to",None)
#if (reply_to!=None):
#if (reply_to!=None):
self
.
reply_to
=
reply_to
self
.
reply_to
=
reply_to
self
.
has_args
=
str
(
kwargs
.
pop
(
"
has_args
"
,
False
)
)
self
.
has_args
=
kwargs
.
pop
(
"
has_args
"
,
False
)
self
.
has_kwargs
=
str
(
kwargs
.
pop
(
"
has_kwargs
"
,
False
)
)
self
.
has_kwargs
=
kwargs
.
pop
(
"
has_kwargs
"
,
False
)
class
ReplyMessage
(
LofarMessage
):
class
ReplyMessage
(
LofarMessage
):
"""
"""
...
...
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