Skip to content

Commit

Permalink
Version 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
MrYsLab authored and MrYsLab committed Jan 4, 2018
1 parent de21433 commit cd6f0f6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
20 changes: 19 additions & 1 deletion python_banyan/backplane/backplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ def __init__(self, subscriber_port='43125', publisher_port='43124', backplane_na
"""
This is the initializer for the Python Banyan BackPlane class. The class must be instantiated
before starting any other Python Banyan components
:param subscriber_port: subscriber IP port number
:param publisher_port: publisher IP port number
:param backplane_name: name to appear on the console for this backplane
:param loop_time: event loop idle timer
"""

Expand Down Expand Up @@ -124,7 +128,21 @@ def bp():
"""
Instantiate the backplane and run it.
Attach a signal handler for the process to listen for user pressing Control C
:return:
usage: backplane [-h] [-n BACKPLANE_NAME] [-p PUBLISHER_PORT] [-s SUBSCRIBER_PORT] [-t LOOP_TIME]
optional arguments:
-h, --help show this help message and exit
-n BACKPLANE_NAME Name of this backplane
-p PUBLISHER_PORT Publisher IP port
-s SUBSCRIBER_PORT Subscriber IP port
-t LOOP_TIME Event Loop Timer in seconds
"""

parser = argparse.ArgumentParser()
Expand Down
22 changes: 15 additions & 7 deletions python_banyan/banyan_base/banyan_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class BanyanBase(object):
"""

def __init__(self, back_plane_ip_address=None, subscriber_port='43125',
publisher_port='43124', process_name='None', loop_time=.1, numpy=False):
publisher_port='43124', process_name='None', loop_time=.1, numpy=False,
external_message_processor=None):
"""
The __init__ method sets up all the ZeroMQ "plumbing"
Expand All @@ -74,6 +75,8 @@ def __init__(self, back_plane_ip_address=None, subscriber_port='43125',
:param loop_time: Receive loop sleep time.
:param numpy: Set true if you wish to include numpy matrices in your messages.
:param external_message_processor: external method to process messages
"""

# call to super allows this class to be used in multiple inheritance scenarios when needed
Expand All @@ -83,6 +86,7 @@ def __init__(self, back_plane_ip_address=None, subscriber_port='43125',

self.back_plane_ip_address = None
self.numpy = numpy
self.external_message_processor = external_message_processor

# if using numpy apply the msgpack_numpy monkey patch
if numpy:
Expand All @@ -96,9 +100,12 @@ def __init__(self, back_plane_ip_address=None, subscriber_port='43125',
for pid in psutil.pids():
p = psutil.Process(pid)
p_command = p.cmdline()
if any('backplane' in s for s in p_command):
self.backplane_exists = True
else:
try:
if any('backplane' in s for s in p_command):
self.backplane_exists = True
else:
continue
except UnicodeDecodeError:
continue

if not self.backplane_exists:
Expand All @@ -114,8 +121,6 @@ def __init__(self, back_plane_ip_address=None, subscriber_port='43125',

self.loop_time = loop_time

print()

print('\n************************************************************')
print(process_name + ' using Back Plane IP address: ' + self.back_plane_ip_address)
print('Subscriber Port = ' + self.subscriber_port)
Expand Down Expand Up @@ -205,7 +210,10 @@ def incoming_message_processing(self, topic, payload):
:param payload: Message Data.
"""
print('this method should be overwritten in the child class', topic, payload)
if self.external_message_processor:
self.external_message_processor(topic, payload)
else:
print('this method should be overwritten in the child class', topic, payload)

def clean_up(self):
"""
Expand Down
5 changes: 5 additions & 0 deletions python_banyan/utils/monitor/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ def __init__(self, back_plane_ip_address=None,
numpy=False):
"""
This is constructor for the Monitor class
:param back_plane_ip_address: IP address of the currently running backplane
:param subscriber_port: subscriber port number - matches that of backplane
:param publisher_port: publisher port number - matches that of backplane
:param process_name: default name is "Monitor". Change using this paramenter
"""

# initialize the base class
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='python-banyan',
version='2.2',
version='2.3',
packages=[
'python_banyan',
'python_banyan.banyan_base',
Expand All @@ -16,7 +16,7 @@
'u-msgpack-python',
'msgpack-python',
'numpy>=1.9',
'msgpack-numpy',
'msgpack-numpy==0.4.1',
'psutil'
],

Expand Down

0 comments on commit cd6f0f6

Please sign in to comment.