Ginés Martínez Sánchez avatar Ginés Martínez Sánchez committed 186737a Draft

viewing the examples

Comments (0)

Files changed (8)

ginsfsm/examples/essential_gobjs/ongconnex.py

 
 def ac_rx_data(self, event):
     data = event.kw['data']
-    if self.verbose:
+    if self.config.verbose:
         print('Receiving %d bytes' % len(data))
         print(hexdump('<=', data))
 
             GConnex,
             self,
             destinations=[
-                (self.url1, 80),
-                (self.url2, 80),
+                (self.config.url1, 80),
+                (self.config.url2, 80),
             ],
             timeout_inactivity=5,
             # only want receive EV_RX_DATA event
             transmit_ready_event_name=None,
         )
 
-        if self.verbose > 1:
-            settings = {
-                'GObj.trace_mach': True,
-                'GObj.logger': logging,
-            }
-            self.overwrite_parameters(-1, **settings)
-
         self.set_timeout(5)
 
     def set_timeout(self, seconds):
     )
     args = parser.parse_args()
 
-    ga = GAplic()
+    local_conf = {
+        'GObj.trace_mach': True if args.verbose else False,
+        'GObj.logger': logging,
+    }
+
+    ga = GAplic(name='', roles='', **local_conf)
     ga.create_gobj(
         'ongconnex',
         OnGConnex,

ginsfsm/examples/essential_gobjs/ongsock.py

 
 def ac_connected(self, event):
     self.clear_timeout()
-    self.set_timeout(self.seconds)
+    self.set_timeout(self.config.seconds)
 
 
 def ac_transmit(self, event):
-    data = QUERY % self.url
-    if self.verbose:
+    data = QUERY % self.config.url
+    if self.config.verbose:
         print('Send %s' % data)
     self.send_event(self.gsock, 'EV_SEND_DATA', data=data)
 
 
 
 def ac_disconnected(self, event):
-    self.set_timeout(self.seconds)
+    self.set_timeout(self.config.seconds)
 
 
 def ac_rx_data(self, event):
     data = event.kw['data']
-    if self.verbose:
+    if self.config.verbose:
         print('Receiving %d bytes' % len(data))
         print(hexdump('<=', data))
 
             self,
             connected_event_name='EV_CONNECTED',
             disconnected_event_name='EV_DISCONNECTED',
-            host=self.url,
+            host=self.config.url,
             port=80,
         )
 
-        if self.verbose > 1:
-            settings = {
-                'GObj.trace_mach': True,
-                'GObj.logger': logging,
-            }
-            self.overwrite_parameters(-1, **settings)
-
         self.set_timeout(1)
 
     def set_timeout(self, seconds):
     )
     args = parser.parse_args()
 
-    ga = GAplic()
+    local_conf = {
+        'GObj.trace_mach': True if args.verbose else False,
+        'GObj.logger': logging,
+    }
+
+    ga = GAplic(name='', roles='', **local_conf)
     ga.create_gobj(
         'ongsock',
         OnGSock,

ginsfsm/examples/essential_gobjs/ontimer.py

 
 
 def ac_exec_command(self, event):
-    if self.verbose:
-        print('Executing %s...' % self.command)
+    if self.config.verbose:
+        print('Executing %s...' % self.config.command)
 
-    response = envoy.run(self.command)
+    response = envoy.run(self.config.command)
 
-    if self.verbose:
+    if self.config.verbose:
         print(response.std_out)
 
-    self.send_event(self.timer, 'EV_SET_TIMER', seconds=self.seconds)
+    self.send_event(self.timer, 'EV_SET_TIMER', seconds=self.config.seconds)
 
 
 ONTIMER_FSM = {
             self        # parent
         )
 
-        if self.verbose > 1:
-            settings = {
-                'GObj.trace_mach': True,
-                'GObj.logger': logging,
-            }
-            self.overwrite_parameters(-1, **settings)
-
-        self.send_event(self.timer, 'EV_SET_TIMER', seconds=self.seconds)
+        self.send_event(self.timer, 'EV_SET_TIMER', seconds=self.config.seconds)
 
 
 if __name__ == "__main__":
     )
     args = parser.parse_args()
 
-    ga = GAplic()
+    local_conf = {
+        'GObj.trace_mach': True if args.verbose else False,
+        'GObj.logger': logging,
+    }
+
+    ga = GAplic(name='', roles='', **local_conf)
     ga.create_gobj(
         'ontimer',
         OnTimer,

ginsfsm/examples/essential_gobjs/stress_client_echo.py

 
 def ac_client_timeout(self, event):
     if self.connex is None:
-        self.connex = range(self.connections)
+        self.connex = range(self.config.connections)
 
-    if self.n_clients < self.connections:
-        for i in range(self.n_clients, self.connections):
+    if self.n_clients < self.config.connections:
+        for i in range(self.n_clients, self.config.connections):
             self.n_clients += 1
             self.connex[i] = self.create_gobj(
                 'client-%d' % i,
                 GConnex,  # GSock,
                 self,
-                destinations=[(self.host, self.port)],
+                destinations=[(self.config.host, self.config.port)],
                 transmit_ready_event_name=None,
             )
 
             #if not ret:
             #    break
     print "conectados: %d" % self.n_connected_clients
-    if self.n_connected_clients == self.connections:
+    if self.n_connected_clients == self.config.connections:
         n_echoes = 0
         n_total = 0
         diff = datetime.timedelta(seconds=0)
         for cli in self.connex:
-            #print 'cli %d txed_msgs %d, rxed_msgs %d' % (cli.idx, cli._gsock.txed_msgs, cli._gsock.rxed_msgs)
-            if cli._gsock.rxed_msgs == cli._gsock.txed_msgs:
+            #print 'cli %d txed_msgs %d, rxed_msgs %d' % (cli.idx, cli.gsock.txed_msgs, cli.gsock.rxed_msgs)
+            if cli.gsock.rxed_msgs == cli.gsock.txed_msgs:
                 n_total += 1
             if cli.sended_msgs == cli.received_msgs:
                 n_echoes += 1
             diff += self.diff
-        print "Echoes OK: %d of %d, taverage %s" % (n_echoes, self.connections, diff/self.connections)
+        print "Echoes OK: %d of %d, taverage %s" % (n_echoes, self.config.connections, diff/self.config.connections)
 
         for cli in self.connex:
-            if cli._gsock.connected:
+            if cli.gsock.connected:
                 cli.sended_msgs = 1
                 cli.received_msgs = 0
                 cli.tx_time = datetime.datetime.now()
         self.max_response_time = datetime.timedelta(seconds=0)
         self.diff = datetime.timedelta(seconds=0)
 
-        if self.verbose > 1:
-            settings = {
-                'GObj.trace_mach': True,
-                'GObj.logger': logging,
-            }
-            self.overwrite_parameters(-1, **settings)
-
         self.set_timeout(1)
 
     def set_timeout(self, seconds):
     args = parser.parse_args()
     run_as_process = args.run_as_process
 
-    ga_cli = GAplic('Client')
+    local_conf = {
+        'GObj.trace_mach': True if args.verbose else False,
+        'GObj.logger': logging,
+    }
+
+    ga_cli = GAplic(name='client', roles='', **local_conf)
     ga_cli.create_gobj(
         'client',
         OnClient,

ginsfsm/examples/essential_gobjs/stress_connections.py

     print('connected FROM %s' % str(event.peername))
     print("Server's clients: %d" % len(self.dl_childs))
 
-    if len(self.dl_childs) == self.connections + 2:
+    if len(self.dl_childs) == self.config.connections + 2:
         end_time = time.clock()
         print("Time for %d connections: %f seconds" % (
-            self.connections,
+            self.config.connections,
             end_time - self.start_time))
 
 
             transmit_ready_event_name=None,
         )
 
-        if self.verbose > 1:
-            settings = {
-                'GObj.trace_mach': True,
-                'GObj.logger': logging,
-            }
-            self.overwrite_parameters(-1, **settings)
-
         self.set_timeout(5)
 
     def set_timeout(self, seconds):
 
 def ac_client_timeout(self, event):
     if self.connex is None:
-        self.connex = range(self.connections)
+        self.connex = range(self.config.connections)
         for i in self.connex:
             print i
             self.connex[i] = self.create_gobj(
             self,
         )
 
-        if self.verbose > 1:
-            settings = {
-                'GObj.trace_mach': True,
-                'GObj.logger': logging,
-            }
-            self.overwrite_parameters(-1, **settings)
-
         self.connex = None
         self.set_timeout(1)
 
     args = parser.parse_args()
     run_as_process = args.run_as_process
 
+    local_conf = {
+        'GObj.trace_mach': True if args.verbose else False,
+        'GObj.logger': logging,
+    }
+
     if run_as_process:
         # run server gaplic as child daemon process
-        ga_srv = GAplic('Server')
+        ga_srv = GAplic(name='Server', roles='', **local_conf)
         ga_srv.create_gobj(
             'server',
             OnServer,
         srv_worker.start()
 
         # run client gaplic as main process
-        ga_cli = GAplic('Client')
+        ga_cli = GAplic(name='Client', roles='', **local_conf)
         ga_cli.create_gobj(
             'client',
             OnClient,
         )
 
         try:
-            ga_cli.start()
+            ga_cli.run_forever()
         except (KeyboardInterrupt, SystemExit):
             ga_srv.stop()
             srv_worker.join()
 
     else:
         # run server gaplic as thread
-        ga_srv = GAplic('Server')
+        ga_srv = GAplic(name='Server', roles='', **local_conf)
         ga_srv.create_gobj(
             'server',
             OnServer,
         srv_worker.start()
 
         # run client gaplic as main process
-        ga_cli = GAplic('Client')
+        ga_cli = GAplic(name='Client', roles='', **local_conf)
         ga_cli.create_gobj(
             'client',
             OnClient,
         )
 
         try:
-            ga_cli.start()
+            ga_cli.run_forever()
         except (KeyboardInterrupt, SystemExit):
             ga_srv.stop()
             srv_worker.join()

ginsfsm/examples/essential_gobjs/stress_server_echo.py

 import logging
 logging.basicConfig(level=logging.DEBUG)
 
-from ginsfsm.smachine import SMachine
 from ginsfsm.gobj import GObj
 from ginsfsm.gaplic import GAplic
 from ginsfsm.c_timer import GTimer
             transmit_ready_event_name=None,
         )
 
-        if self.verbose > 0:
-            settings = {
-                'GObj.trace_mach': True,
-                'GObj.logger': logging,
-            }
-            self.overwrite_parameters(-1, **settings)
-            SMachine.global_trace_mach(True)
-
     def set_timeout(self, seconds):
         self.send_event(self.timer, 'EV_SET_TIMER', seconds=seconds)
 
 #                   Main
 #===============================================================
 if __name__ == "__main__":
-    ga_srv = GAplic('Server')
+    local_conf = {
+        'GObj.trace_mach': True,
+        'GObj.logger': logging,
+    }
+
+    ga_srv = GAplic(name='server', roles='', **local_conf)
     ga_srv.create_gobj(
         'server',
         OnServer,

ginsfsm/examples/http/simple_http_server.py

             maximum_simultaneous_requests=0,
         )
 
-        if self.verbose > 0:
+        if self.config.verbose > 0:
             settings = {
                 'GObj.trace_mach': True,
                 'GObj.logger': logging,

ginsfsm/gaplic.py

             gobj_name,
             event_name,
             subscriber_gobj,
-            **kw
+            kw
         )
 
     def delete_all_references(self, gobj):
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.