Skip to content
Snippets Groups Projects
Commit 1c1f7575 authored by Herwin van Welbergen's avatar Herwin van Welbergen
Browse files
parents b41b881e 7d534472
No related branches found
No related tags found
No related merge requests found
...@@ -9,4 +9,7 @@ ...@@ -9,4 +9,7 @@
*/.classpath */.classpath
*.pyc *.pyc
**/.*.swp **/.*.swp
.*.sw[a-z]
*.un~
Session.vim
...@@ -137,14 +137,14 @@ class Payload(dict): ...@@ -137,14 +137,14 @@ class Payload(dict):
# exceptions and sending updates in the case where we just receive # exceptions and sending updates in the case where we just receive
# a whole new payload from the remote side and overwrite it locally. # a whole new payload from the remote side and overwrite it locally.
if (not omit_init_update_message) and (self.iu.buffer is not None): if (not omit_init_update_message) and (self.iu.buffer is not None):
self.iu._modify_payload(payload=self, is_delta=False, new_items=pl, keys_to_remove=[], writer_name=writer_name) self.iu._modify_payload(is_delta=False, new_items=pl, keys_to_remove=[], writer_name=writer_name)
for k, v in pl.items(): for k, v in pl.items():
dict.__setitem__(self, k, v) dict.__setitem__(self, k, v)
def __setitem__(self, k, v, writer_name=None): def __setitem__(self, k, v, writer_name=None):
self.iu._modify_payload(payload=self, is_delta=True, new_items={k:v}, keys_to_remove=[], writer_name=writer_name) self.iu._modify_payload(is_delta=True, new_items={k:v}, keys_to_remove=[], writer_name=writer_name)
result = dict.__setitem__(self, k, v) result = dict.__setitem__(self, k, v)
def __delitem__(self, k, writer_name=None): def __delitem__(self, k, writer_name=None):
self.iu._modify_payload(payload=self, is_delta=True, new_items={}, keys_to_remove=[k], writer_name=writer_name) self.iu._modify_payload(is_delta=True, new_items={}, keys_to_remove=[k], writer_name=writer_name)
result = dict.__delitem__(self, k) result = dict.__delitem__(self, k)
def _remotely_enforced_setitem(self, k, v): def _remotely_enforced_setitem(self, k, v):
"""Sets an item when requested remotely.""" """Sets an item when requested remotely."""
...@@ -210,23 +210,23 @@ class IUInterface(object): #{{{ ...@@ -210,23 +210,23 @@ class IUInterface(object): #{{{
'''Attempt to add links if the conditions are met '''Attempt to add links if the conditions are met
and send an update message. Then call the local setter.''' and send an update message. Then call the local setter.'''
if not hasattr(targets, '__iter__'): targets=[targets] if not hasattr(targets, '__iter__'): targets=[targets]
self._modify_links(links=self, is_delta=True, new_links={type:targets}, links_to_remove={}, writer_name=writer_name) self._modify_links(is_delta=True, new_links={type:targets}, links_to_remove={}, writer_name=writer_name)
self._add_and_remove_links( add={type:targets}, remove={} ) self._add_and_remove_links( add={type:targets}, remove={} )
def remove_links(self, type, targets, writer_name=None): def remove_links(self, type, targets, writer_name=None):
'''Attempt to remove links if the conditions are met '''Attempt to remove links if the conditions are met
and send an update message. Then call the local setter.''' and send an update message. Then call the local setter.'''
if not hasattr(targets, '__iter__'): targets=[targets] if not hasattr(targets, '__iter__'): targets=[targets]
self._modify_links(links=self, is_delta=True, new_links={}, links_to_remove={type:targets}, writer_name=writer_name) self._modify_links(is_delta=True, new_links={}, links_to_remove={type:targets}, writer_name=writer_name)
self._add_and_remove_links( add={}, remove={type:targets} ) self._add_and_remove_links( add={}, remove={type:targets} )
def modify_links(self, add, remove, writer_name=None): def modify_links(self, add, remove, writer_name=None):
'''Attempt to modify links if the conditions are met '''Attempt to modify links if the conditions are met
and send an update message. Then call the local setter.''' and send an update message. Then call the local setter.'''
self._modify_links(links=self, is_delta=True, new_links=add, links_to_remove=remove, writer_name=writer_name) self._modify_links(is_delta=True, new_links=add, links_to_remove=remove, writer_name=writer_name)
self._add_and_remove_links( add=add, remove=remove ) self._add_and_remove_links( add=add, remove=remove )
def set_links(self, links, writer_name=None): def set_links(self, links, writer_name=None):
'''Attempt to set (replace) links if the conditions are met '''Attempt to set (replace) links if the conditions are met
and send an update message. Then call the local setter.''' and send an update message. Then call the local setter.'''
self._modify_links(links=self, is_delta=False, new_links=links, links_to_remove={}, writer_name=writer_name) self._modify_links(is_delta=False, new_links=links, links_to_remove={}, writer_name=writer_name)
self._replace_links( links=links ) self._replace_links( links=links )
def get_links(self, type): def get_links(self, type):
return set(self._links[type]) return set(self._links[type])
...@@ -300,7 +300,7 @@ class IU(IUInterface):#{{{ ...@@ -300,7 +300,7 @@ class IU(IUInterface):#{{{
self.revision_lock = threading.RLock() self.revision_lock = threading.RLock()
self._payload = Payload(iu=self) self._payload = Payload(iu=self)
def _modify_links(self, links, is_delta=False, new_links={}, links_to_remove={}, writer_name=None): def _modify_links(self, is_delta=False, new_links={}, links_to_remove={}, writer_name=None):
if self.committed: if self.committed:
raise IUCommittedError(self) raise IUCommittedError(self)
with self.revision_lock: with self.revision_lock:
...@@ -316,7 +316,7 @@ class IU(IUInterface):#{{{ ...@@ -316,7 +316,7 @@ class IU(IUInterface):#{{{
links_to_remove=links_to_remove, links_to_remove=links_to_remove,
writer_name=self.owner_name if writer_name is None else writer_name) writer_name=self.owner_name if writer_name is None else writer_name)
def _modify_payload(self, payload, is_delta=True, new_items={}, keys_to_remove=[], writer_name=None): def _modify_payload(self, is_delta=True, new_items={}, keys_to_remove=[], writer_name=None):
"""Modify the payload: add or remove items from this payload locally and send update.""" """Modify the payload: add or remove items from this payload locally and send update."""
if self.committed: if self.committed:
raise IUCommittedError(self) raise IUCommittedError(self)
...@@ -412,7 +412,7 @@ class RemotePushIU(IUInterface):#{{{ ...@@ -412,7 +412,7 @@ class RemotePushIU(IUInterface):#{{{
self._payload = Payload(iu=self, new_payload=payload, omit_init_update_message=True) self._payload = Payload(iu=self, new_payload=payload, omit_init_update_message=True)
self._links = links self._links = links
def _modify_links(self, links, is_delta=False, new_links={}, links_to_remove={}, writer_name=None): def _modify_links(self, is_delta=False, new_links={}, links_to_remove={}, writer_name=None):
"""Modify the links: add or remove item from this payload remotely and send update.""" """Modify the links: add or remove item from this payload remotely and send update."""
if self.committed: if self.committed:
raise IUCommittedError(self) raise IUCommittedError(self)
...@@ -432,7 +432,7 @@ class RemotePushIU(IUInterface):#{{{ ...@@ -432,7 +432,7 @@ class RemotePushIU(IUInterface):#{{{
else: else:
self._revision = new_revision self._revision = new_revision
def _modify_payload(self, payload, is_delta=True, new_items={}, keys_to_remove=[], writer_name=None): def _modify_payload(self, is_delta=True, new_items={}, keys_to_remove=[], writer_name=None):
"""Modify the payload: add or remove item from this payload remotely and send update.""" """Modify the payload: add or remove item from this payload remotely and send update."""
if self.committed: if self.committed:
raise IUCommittedError(self) raise IUCommittedError(self)
......
...@@ -66,6 +66,7 @@ class Sender(object): ...@@ -66,6 +66,7 @@ class Sender(object):
def __init__(self, send_frequency): def __init__(self, send_frequency):
self.ob = ipaaca.OutputBuffer('PowerOut') self.ob = ipaaca.OutputBuffer('PowerOut')
self.iu = ipaaca.IU('spam') self.iu = ipaaca.IU('spam')
self.data_prefix='A'*1024;
self.iu.payload = {'data':'0'} self.iu.payload = {'data':'0'}
self.ob.add(self.iu) self.ob.add(self.iu)
self.counter = 0 self.counter = 0
...@@ -79,6 +80,17 @@ class Sender(object): ...@@ -79,6 +80,17 @@ class Sender(object):
time.sleep(self.delay) time.sleep(self.delay)
self.counter += 1 self.counter += 1
self.iu.payload['data'] = str(self.counter) self.iu.payload['data'] = str(self.counter)
#self.iu.payload = {
# 'data':self.data_prefix,
# 'data2':self.data_prefix,
# 'data3':self.data_prefix,
# 'data4':self.data_prefix,
# 'data5':self.data_prefix,
# 'data6':self.data_prefix,
# 'data7':self.data_prefix,
# 'data8':self.data_prefix,
# 'data9':self.data_prefix,
# }
if self.counter == 1000: if self.counter == 1000:
print "Sent 1k updates at", int(1000.0/(time.time()-last_time)),"Hz" print "Sent 1k updates at", int(1000.0/(time.time()-last_time)),"Hz"
last_time = time.time() last_time = time.time()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment