Commits

Ginés Martínez Sánchez committed fd0b76f Draft

circle full closed? perhaps!!

Comments (0)

Files changed (3)

ginsfsm/examples/router/test_router.py

 def ac_message(self, event):
     print "ORDENNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN %s %s" % (
         self.counter,
-        event.__subscriptor_reference__,
+        event.__subscription_reference__,
     )
     list_globals()
     self.counter += 1
     if self.counter > 4:
         # delete subscription
-        pass
+        ret = self.gaplic.unsubscribe_event_from_external_gaplic(
+            'TOTO',         # gaplic_name
+            'sample2',      # gobj_name
+            'EV_MESSAGE',   # event_name
+            self,           # subscriber_gobj
+            __subscription_reference__=event.__subscription_reference__,
+        )
+        if not ret:
+            print "Eiiiiiiiiiiiiiiiiiiiiii something wrong!"
 
     # causes broadcast EV_MESSAGE again
     self.gaplic.send_event_to_external_gaplic(
 
 
 def ac_timeout(self, event):
+    print "Broadcasting EV_MESSAGE"
     self.broadcast_event('EV_MESSAGE')
 
 
                     )
                     oevent.event_name = sub.__rename_event_name__
 
-                if hasattr(sub, '__subscriptor_reference__'):
+                if hasattr(sub, '__subscription_reference__'):
                     oevent.kw.update(
                         {
-                            '__subscriptor_reference__':
-                            sub.__subscriptor_reference__,
+                            '__subscription_reference__':
+                            sub.__subscription_reference__,
                         }
                     )
                     oevent.event_name = sub.__rename_event_name__
               neither with delete_all_subscriptions().
               (Well, with force you can)
 
-            * `__subscriptor_reference__`:  ``str``
+            * `__subscription_reference__`:  ``str``
 
               If exists, it will be added as kw in the event broadcast.
               Can be used by the subscriptor for general purposes.

ginsfsm/router.py

         self.origin_gaplic = intra_event.origin_gaplic
         self.origin_gobj = intra_event.origin_gobj
         self.route_ref = route_ref
+        self.isubscription = None  # reference to internal subscription
 
 
 class IntraEvent(object):
 
                 subs_kw = {
                     '__rename_event_name__': 'EV_SUBSCRIPTION',
-                    '__subscriptor_reference__': external_subscriptor_ref,
+                    '__subscription_reference__': external_subscriptor_ref,
                 }
                 try:
-                    named_gobj.subscribe_event(
+                    isubscription = named_gobj.subscribe_event(
                         intra_event.event_name,
                         self,
                         **subs_kw
                         self.trace_intra_event(prefix, ack)
                     write(ack.toJSON())
                     return
+                esubscription = self.get_external_subscription(
+                    external_subscriptor_ref)
+                esubscription.isubscription = isubscription
 
                 # simple ack, no checkout, for the sender could remove the msg.
                 ack = intra_event.copy('__event_ack__')
                 write(ack.toJSON())
                 return
 
+            if intra_event.kw.get('__unsubscribe_event__', False):
+                # it's a external unsubscription
+                subscription_reference = intra_event.kw.get(
+                    '__subscription_reference__', None)
+
+                if subscription_reference:
+                    self.remove_external_subscription(subscription_reference)
+                else:
+                    # TODO: find and delete external subscription
+                    self.logging.error("ERROR no __subscription_reference__")
+
+                # simple ack, no checkout, for the sender could remove the msg.
+                ack = intra_event.copy('__event_ack__')
+                if trace_router:
+                    prefix = '%s ==> %s' % (
+                        registry.my_gaplic_name, this_route.route_ref)
+                    self.trace_intra_event(prefix, ack)
+                write(ack.toJSON())
+                return
+
             # simple ack, no checkout, for the sender could remove the msg.
             ack = intra_event.copy('__event_ack__')
             if trace_router:
 
 
 def ac_subscription(self, event):
-    subscriptor_reference = event.__subscriptor_reference__
-    subscription = self.external_subscriptions.get(subscriptor_reference, None)
+    subscription_reference = event.__subscription_reference__
+    subscription = self.external_subscriptions.get(subscription_reference, None)
     if subscription:
         self.mt_send_event_to_external_route(
             subscription.route_ref,
         self.external_subscriptions[k] = subscription
         return k
 
-    def remove_external_subscription(self, external_subscriptor_reference):
-        if external_subscriptor_reference in self.external_subscriptions:
-            subs = self.external_subscriptions[external_subscriptor_reference]
+    def remove_external_subscription(self, subscription_reference):
+        if subscription_reference in self.external_subscriptions:
+            subs = self.external_subscriptions[subscription_reference]
             if subs:
-                subs.destination_gobj.delete_subscription_by_object(
-                    subs.subscription)
-            del self.external_subscriptions[external_subscriptor_reference]
+                isubscription = subs.isubscription
+                named_gobj = self.gaplic.find_unique_gobj(
+                    subs.destination_gobj)
+                if named_gobj:
+                    named_gobj.delete_subscription_by_object(isubscription)
+            del self.external_subscriptions[subscription_reference]
+
+    def get_external_subscription(self, subscription_reference):
+        if subscription_reference in self.external_subscriptions:
+            subs = self.external_subscriptions[subscription_reference]
+            return subs
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.