Commits

Ginés Martínez Sánchez committed 780fc13 Draft

developing examples inter_event

Comments (0)

Files changed (5)

ginsfsm/examples/inter_event/ap1_banco/banco/main.py

         'application': 'wsgi-application',
         'GWsgiServer.host': '0.0.0.0',
         'GWsgiServer.port': 8001,
-        'GSock.trace_dump': True,
-        'GObj.trace_mach': True,
+        'GSock.trace_dump': False,
+        'GObj.trace_mach': False,
         'GObj.trace_creation': False,
-        'GObj.trace_traverse': True,
+        'GObj.trace_traverse': False,
         'GObj.trace_subscription': False,
 
         'GObj.logger': logging,
Add a comment to this file

ginsfsm/examples/inter_event/schema.svg

Old
Old image
New
New image
    height="888.02795"
    id="svg2985"
    version="1.1"
-   inkscape:version="0.48.3.1 r9886"
+   inkscape:version="0.48.4 r9939"
    sodipodi:docname="schema.svg">
   <defs
      id="defs2987">
      inkscape:pageopacity="0.0"
      inkscape:pageshadow="2"
      inkscape:zoom="0.8830081"
-     inkscape:cx="-208.7149"
+     inkscape:cx="-240.51795"
      inkscape:cy="270.8469"
      inkscape:current-layer="layer1"
      inkscape:document-units="px"
      showgrid="false"
-     inkscape:window-width="1366"
-     inkscape:window-height="692"
+     inkscape:window-width="1280"
+     inkscape:window-height="948"
      inkscape:window-x="0"
      inkscape:window-y="24"
      inkscape:window-maximized="1"
        d="m 23.98009,607.16336 c 0,58.39204 0,58.39204 0,58.39204"
        id="path4484-8-3"
        inkscape:connector-curvature="0" />
-    <text
-       xml:space="preserve"
-       style="font-size:14px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
-       x="-74.534973"
-       y="119.08725"
-       id="text5383"
-       sodipodi:linespacing="125%"><tspan
-         sodipodi:role="line"
-         id="tspan5385"
-         x="-74.534973"
-         y="119.08725">Presentation flow at <tspan
-   style="font-weight:bold;-inkscape-font-specification:Sans Bold"
-   id="tspan5408">start up</tspan></tspan></text>
     <g
        id="g5461-4"
        transform="translate(72.948789,3.215763)">
     <text
        xml:space="preserve"
        style="font-size:11px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
-       x="-638.22913"
-       y="458.01477"
+       x="-326.7937"
+       y="68.43737"
        id="text4950"
        sodipodi:linespacing="125%"><tspan
          sodipodi:role="line"
          id="tspan4952"
-         x="-638.22913"
-         y="458.01477">Al establecer la ruta estática en el envio de la identity_card van también los</tspan><tspan
+         x="-326.7937"
+         y="68.43737">Al establecer la ruta estática en el envio de la identity_card van también los</tspan><tspan
          sodipodi:role="line"
-         x="-638.22913"
-         y="471.76477"
+         x="-326.7937"
+         y="82.18737"
          id="tspan4954">roles de back-way, que son todos los roles de las conexiones dinámicas.</tspan><tspan
          sodipodi:role="line"
-         x="-638.22913"
-         y="485.51477"
+         x="-326.7937"
+         y="95.93737"
          id="tspan4956" /><tspan
          sodipodi:role="line"
-         x="-638.22913"
-         y="499.26477"
+         x="-326.7937"
+         y="109.68737"
          id="tspan4958">Cuando uno recibe una identity_card de una conexión dinámica, </tspan><tspan
          sodipodi:role="line"
-         x="-638.22913"
-         y="513.01477"
+         x="-326.7937"
+         y="123.43737"
          id="tspan4960">si obtiene nuevos roles, debe reenviar su identity card (back ways modificados)</tspan><tspan
          sodipodi:role="line"
-         x="-638.22913"
-         y="526.76477"
+         x="-326.7937"
+         y="137.18736"
          id="tspan4966">a todas sus conexiones estáticas.</tspan><tspan
          sodipodi:role="line"
-         x="-638.22913"
-         y="540.51477"
+         x="-326.7937"
+         y="150.93736"
          id="tspan4972">Si el nuevo rol recibido es el propio, se abstendrá de reenviar, </tspan><tspan
          sodipodi:role="line"
-         x="-638.22913"
-         y="554.26477"
+         x="-326.7937"
+         y="164.68736"
          id="tspan4974">para no entrar en bucles.</tspan></text>
   </g>
 </svg>

ginsfsm/gaplic.py

         named_gobj = self._unique_named_gobjs.get(gobj_name, None)
         return named_gobj
 
-    def send_event_to_external_role(
-            self, role, gobj_name, event_name, subscriber_gobj, **kw):
+    def send_event_to_external_gaplic(
+            self, gaplic_name, role, gobj_name, event_name, subscriber_gobj, **kw):
         """ Send an event to an external gaplic.
 
         :param role: name of external role.
               response of external executed action.
               Received with the same event.
         """
+        if not isinstance(gaplic_name, string_types):
+            raise TypeError(
+                'Destination gaplic %r must be a string'
+                % (gaplic_name)
+            )
         if not isinstance(role, string_types):
             raise TypeError(
                 'Destination role %r must be a string'
                 % (subscriber_gobj)
             )
 
-        return self.router.mt_send_event_to_external_role(
+        return self.router.mt_send_event_to_external_gaplic(
+            gaplic_name,
             role,
             gobj_name,
             event_name,
             kw
         )
 
-    def send_event_to_external_gaplic(
-            self, gaplic_name, gobj_name, event_name, subscriber_gobj, **kw):
-        """ Send an event to an external gaplic.
-
-        :param gaplic_name: name of external gaplic.
-        :param gobj_name: name of external gobj.
-        :param event_name: name of the event to send.
-        :param subscriber_gobj: subscriber obj that wants receive the response.
-        :param kw: keyword arguments.
-
-        Possible values for **kw** arguments:
-            * `__subscribe_response__`: ``Bool`` Subscribe the
-              response of external executed action.
-              Received with the same event.
-        """
-        if not isinstance(gaplic_name, string_types):
-            raise TypeError(
-                'Destination gaplic %r must be a string'
-                % (gaplic_name)
-            )
-        if not isinstance(gobj_name, string_types):
-            raise TypeError(
-                'Destination gobj %r must be a string'
-                % (gobj_name)
-            )
-
-        if not isinstance(event_name, string_types):
-            raise TypeError(
-                'Event name %r must be a string'
-                % (event_name)
-            )
-
-        if not isinstance(subscriber_gobj, (string_types, GObj)):
-            raise TypeError(
-                'Subscriber gobj %r must be a string'
-                % (subscriber_gobj)
-            )
-
-        if gaplic_name == self.name:
-            raise TypeError(
-                "Please don't use external methods to self gaplic."
-                % (gaplic_name)
-            )
-
-        if isinstance(subscriber_gobj, (GObj)):
-            subscriber_gobj = subscriber_gobj.name
-
-        subs_gobj = self.find_unique_gobj(subscriber_gobj)
-        if not subs_gobj:
-            raise TypeError(
-                'Subscriber gobj %r must be a __unique_named__ gobj'
-                % (subscriber_gobj)
-            )
-
-        return self.router.mt_send_event_to_external_gaplic(
-            gaplic_name,
-            gobj_name,
-            event_name,
-            subscriber_gobj,
-            kw
-        )
-
     def subscribe_event_from_external_gaplic(
-            self, gaplic_name, gobj_name, event_name, subscriber_gobj, **kw):
+            self, gaplic_name, role, gobj_name, event_name, subscriber_gobj, **kw):
         """ Subscribe an event of an external gaplic by name.
         """
         kw.update({'__subscribe_event__': True})
         return self.send_event_to_external_gaplic(
             gaplic_name,
-            gobj_name,
-            event_name,
-            subscriber_gobj,
-            **kw
-        )
-
-    def subscribe_event_from_external_role(
-            self, role, gobj_name, event_name, subscriber_gobj, **kw):
-        """ Subscribe an event of an external gaplic by role.
-        """
-        kw.update({'__subscribe_event__': True})
-        return self.send_event_to_external_role(
             role,
             gobj_name,
             event_name,
         )
 
     def unsubscribe_event_from_external_gaplic(
-            self, gaplic_name, gobj_name, event_name, subscriber_gobj, **kw):
+            self, gaplic_name, role, gobj_name, event_name, subscriber_gobj, **kw):
         """ Subscribe an event of an external gaplic by name.
         """
         kw.update({'__unsubscribe_event__': True})
         return self.send_event_to_external_gaplic(
             gaplic_name,
-            gobj_name,
-            event_name,
-            subscriber_gobj,
-            **kw
-        )
-
-    def unsubscribe_event_from_external_role(
-            self, role, gobj_name, event_name, subscriber_gobj, **kw):
-        """ Subscribe an event of an external gaplic by role.
-        """
-        kw.update({'__unsubscribe_event__': True})
-        return self.send_event_to_external_role(
             role,
             gobj_name,
             event_name,

ginsfsm/protocols/wsgi/common/wsgi_response.py

                     # waiting for more data when there are too few bytes
                     # to service content-length
                     self.close_on_finish = True
-                    self.wsgi_server.logger and self.wsgi_server.logger.error(
-                        'application returned too few bytes (%s) '
-                        'for specified Content-Length (%s) via app_iter' % (
-                            self.content_bytes_written, cl),
-                        )
+                    if self.request.command != 'HEAD':
+                        self.wsgi_server.logger.error(
+                            'application returned too few bytes (%s) '
+                            'for specified Content-Length (%s) via app_iter' % (
+                                self.content_bytes_written, cl),
+                            )
         finally:
             if hasattr(app_iter, 'close'):
                 app_iter.close()

ginsfsm/router.py

     """
     def __init__(self, name, roles, urls, connex_mode=None):
         self.gaplic_name = name
-        if isinstance(roles, (list,)):
+        if isinstance(roles, (list, tuple,)):
             self.roles = roles
         elif roles:
             self.roles = [roles]
             self.serial = 1
         return self.serial
 
+    def __repr__(self):
+        return "\nSTATIC ROUTE:\n  gaplic_name: %s\n  roles: %s\n  " \
+            "route_ref: %s\n  connex: %s\n" % (
+            self.gaplic_name,
+            self.roles,
+            self.route_ref,
+            self.connex_handler.config.destinations,
+        )
+
 
 class DynamicRoute(object):
     """ Dynamic route (when we are servers)
     def __init__(self, name, roles, write, gsock):
         self.gaplic_name = name
         self.roles = roles
-        if isinstance(roles, (list,)):
+        if isinstance(roles, (list, tuple,)):
             self.roles = roles
         elif roles:
             self.roles = [roles]
             route = self.dynamic_routes.get(route_ref, None)
         return route
 
+    def search_route(self, gaplic_name, role):
+        registry = self
+
+        #------------------------------#
+        #   Search by gaplic_name
+        #------------------------------#
+
+        # search in static routes
+        static_routes = registry.static_routes
+        for route_ref in static_routes:
+            route = static_routes[route_ref]
+            if route.gaplic_name == gaplic_name:
+                return route
+
+        # search in dynamic routes
+        dynamic_routes = registry.dynamic_routes
+        for route_ref in dynamic_routes:
+            route = dynamic_routes[route_ref]
+            if route.gsock.is_disconnected():
+                continue
+            if route.gaplic_name == gaplic_name:
+                return route
+
+        #------------------------------#
+        #   Search by role
+        #------------------------------#
+
+        # search in static routes
+        static_routes = registry.static_routes
+        for route_ref in static_routes:
+            route = static_routes[route_ref]
+            roles = route.roles
+            for ro in roles:
+                if ro == role:
+                    return route
+
+        # search in dynamic routes
+        dynamic_routes = registry.dynamic_routes
+        for route_ref in dynamic_routes:
+            route = dynamic_routes[route_ref]
+            if route.gsock.is_disconnected():
+                continue
+            roles = route.roles
+            # TODO: busca el rol conectado si hay varios
+            for ro in roles:
+                if ro == role:
+                    return route
+
+        return None
+
     def enqueue_pending_event(self, route, intra_event):
         dl_output_events = route.dl_output_events
         ln = len(dl_output_events)
     if not route:
         return -1
     if self.config.trace_router:
-        self.logger.info("%s: new STATIC route: %s: %s: %s: %s" % (
+        self.logger.info("%s: new STATIC route: %r" % (
             self.registry.my_gaplic_name,
-            route.route_ref,
-            route.gaplic_name,
-            route.roles,
-            route.connex_handler.config.destinations,
+            route
         ))
     return route.route_ref
 
         #-------------------------------------------#
         #           search in routes
         #-------------------------------------------#
-        route_dst = None
-        if intra_event.destination_gaplic:
-            route_dst = self.search_route_by_gaplic(
-                intra_event.destination_gaplic)
-        if not route_dst and intra_event.destination_role:
-            route_dst = self.search_route_by_role(
-                intra_event.destination_role)
+        route_dst = registry.search_route(
+            intra_event.destination_gaplic,
+            intra_event.destination_role)
 
         if not route_dst:
             # nothing found
     """
     routes = []
     if value:
+        # save each route separated by ;
         value = value.split(';')
         for r in value:
             r = r.strip()
             if r:
                 routes.append(r)
 
+        # split each route by ,
         for idx, r in enumerate(routes):
             items = r.split(',')
             v = []
 
         for r in routes:
             for idx, field in enumerate(r):
-                v = []
+                v = ()
                 if not '+' in field:
-                    v.append(field)
+                    v += (field,)
                     continue
                 items = field.split('+')
                 for e in items:
                     e = e.strip()
                     if e:
-                        v.append(e)
-                r[idx] = tuple(v)
-
-        for idx, r in enumerate(routes):
-            routes[idx] = tuple(r)
+                        v += (e,)
+                r[idx] = v
 
     return routes
 
                 exc_info=True,
             )
 
-    def search_route_by_role(self, role):
-        registry = self.registry
-
-        # search in static routes
-        static_routes = registry.static_routes
-        for route_ref in static_routes:
-            route = static_routes[route_ref]
-            roles = route.roles
-            for ro in roles:
-                if ro == role:
-                    return route
-
-        # search in dynamic routes
-        dynamic_routes = registry.dynamic_routes
-        for route_ref in dynamic_routes:
-            route = dynamic_routes[route_ref]
-            if route.gsock.is_disconnected():
-                continue
-            roles = route.roles
-            # TODO: busca el rol conectado si hay varios
-            for ro in roles:
-                if ro == role:
-                    return route
-
-        return None
-
-    def search_route_by_gaplic(self, gaplic_name):
-        registry = self.registry
-
-        # search in static routes
-        static_routes = registry.static_routes
-        for route_ref in static_routes:
-            route = static_routes[route_ref]
-            if route.gaplic_name == gaplic_name:
-                return route
-
-        # search in dynamic routes
-        dynamic_routes = registry.dynamic_routes
-        for route_ref in dynamic_routes:
-            route = dynamic_routes[route_ref]
-            if route.gsock.is_disconnected():
-                continue
-            if route.gaplic_name == gaplic_name:
-                return route
-
-        return None
-
     def send_identity_card(self, write):
         my_gaplic_name = self.registry.my_gaplic_name
         my_roles = self.registry.my_roles
             transmit_ready_event_name=None,
         )
 
-    def mt_send_event_to_external_role(
+    def mt_send_event_to_external_gaplic(
             self,
+            gaplic_name,
             role,
             gobj_name,
             event_name,
             subscriber_gobj,
             kw):
         registry = self.registry
-        route = self.search_route_by_role(role)
-        if not route:
-            self.logger.error("ERROR mt_send_event_to_external_role() "
-                              "role NOT FOUND: %r" % role)
-            return False
-
-        intra_event = IntraEvent(
-            message_type='__event__',
-            serial=route.incr_serial(),
-            event_name=event_name,
-            destination_role=role,
-            destination_gobj=gobj_name,
-            origin_gaplic=registry.my_gaplic_name,
-            origin_gobj=subscriber_gobj,
-            kw=kw)
-
-        registry.enqueue_pending_event(route, intra_event)
-        if not route.cur_pending_event:
-            registry.fire_pending_events(route)
-        return True
-
-    def mt_send_event_to_external_gaplic(
-            self,
-            gaplic_name,
-            gobj_name,
-            event_name,
-            subscriber_gobj,
-            kw):
-        registry = self.registry
-        route = self.search_route_by_gaplic(gaplic_name)
+        route = registry.search_route(gaplic_name, role)
         if not route:
             self.logger.error(
                 "ERROR mt_send_event_to_external_gaplic() "
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.