ppf: Add SwarmWriter class.
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Mon, 22 Aug 2011 10:37:04 +0000 (13:37 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Mon, 22 Aug 2011 10:37:13 +0000 (13:37 +0300)
ppf/new/storage.py

index f771f00..cb47b5f 100644 (file)
@@ -579,3 +579,42 @@ class MySQLDatabaseAccess(DatabaseAccess):
 
     def add_verbose_message(self, msg):
         pass
+
+class SwarmWriter(object):
+    """
+    Wrapper class for swarm storage write actions. Multiple *Access
+    objects may be added to the clas resulting in multiple storage types.
+    For example, adding a swarm could result in
+       * adding a table entry in a MySQL database (MySQLDatabaseAccess)
+       * adding a table entry in an SQLite database (SQLiteDatabaseAccess)
+       * adding a new folder in a tree structure (TreeTextFileAccess)
+    """
+
+    def __init__(self):
+        handlers = []
+
+    def add_access_handle(self, handle):
+        handlers.append(handle)
+
+    def remove_access_handle(self, handle):
+        handlers.remove(handle)
+
+    def add_swarm(self, swarm):
+        for h in handlers:
+            h.add_swarm(swarm)
+
+    def add_client_session(self, session):
+        for h in handlers:
+            h.add_client_session(swarm)
+
+    def add_peer_status_message(self, msg):
+        for h in handlers:
+            h.add_peer_status_message(swarm)
+
+    def add_status_message(self, msg):
+        for h in handlers:
+            h.add_status_message(swarm)
+
+    def add_verbose_message(self, msg):
+        for h in handlers:
+            h.add_verbose_message(swarm)