Commits

Sébastien Martinez committed f812db5

Using the Update classes with the product example

Comments (0)

Files changed (4)

examples/products/products_example.sh

 sleep 2
 echo "Products example :  Starting second update" 
 echo "update products_update_v3.py" | netcat $hostname 4242
-sleep 11
+sleep 15
 echo "Products example : Ending the program"
 kill $prog
 

examples/products/products_update_v2.py

 """products_update_v2.py
    Published under the GPLv2 license (see LICENSE.txt)
 """
-import pymoult
-import pymoult.controllers
-import pymoult.stack
-import pymoult.heap
-import pymoult.stack.tools
-import pymoult.heap.tools
+from pymoult.stack.high_level import *
+from pymoult.heap.high_level import *
+from pymoult.common.high_level import *
 import time
 import sys
+import threading
 
-
-
-threads = sys.modules["__main__"].threads 
-manager_thread = threads[0]
-socket_thread = threads[1]
+manager_thread = get_thread_by_name("Site_Manager")
+socket_thread = get_thread_by_name("Command_Socket")
 
 
 #Object updates
 			self.mark = self.votes*(self.mark + mark) / float((self.votes*( self.votes +1) ))
 			self.votes +=1
 
-
-pymoult.heap.tools.start_lazy_update_class(sys.modules["__main__"].Product,ProductV2)
+product_update_v2 = sys.modules["__main__"].Product_Updater(ProductV2)
+product_update_v2.apply()
 
 # Site updates
 
 			m += product.mark
 		self.mark = float(m) / float(n)
 
-
-site_update_function = pymoult.heap.tools.eager_class_update(sys.modules["__main__"].Site,SiteV2)
-#We execute the eager update in the manager thread
-pymoult.controllers.set_update_function(site_update_function,manager_thread)
+site_update_v2 = sys.modules["__main__"].Site_Updater(SiteV2)
+site_update_v2.apply()
 
 #Function updates
 #################
 	print(the_site.mark_product(product,mark))
 
 
-
 def new_do_command(command):
 	operands = command.split()
 	if operands[0] == "order" and len(operands) == 4:
 	if operands[0] == "rate" and len(operands) == 4:
 		rate(float(operands[1]),operands[2],operands[3])
 
-
-socket_update_function = pymoult.stack.tools.safe_redefine("do_command",new_do_command,"__main__")
-
-pymoult.controllers.set_update_function(socket_update_function,socket_thread)
-
-
+command_update_v2 = sys.modules["__main__"].Command_Updater(new_do_command) 
+command_update_v2.apply()

examples/products/products_update_v3.py

 """products_update_v3.py
    Published under the GPLv2 license (see LICENSE.txt)
 """
-import pymoult
-import pymoult.controllers
-import pymoult.stack
-import pymoult.stack.tools
+from pymoult.stack.high_level import *
+from pymoult.common.high_level import *
 import time
 import sys
 
 
 
-threads = sys.modules["__main__"].threads 
-manager_thread = threads[0]
 
 #Function updates
 #################
 		for x in range(10):
 			time.sleep(1)
 
-manager_update_function = pymoult.stack.tools.reboot_thread(new_manager_main)
-
-pymoult.controllers.set_update_function(manager_update_function,manager_thread)
-
-
+manager_update_v3 = sys.modules["__main__"].Manager_Updater(new_manager_main)
+manager_update_v3.apply()

examples/products/products_v1.py

-#!/usr/bin/env pypy
+#!/usr/bin/pypy-dsu
+
 """products_v1.py
    Published under the GPLv2 license (see LICENSE.txt)
 """
 
 import pymoult
-import pymoult.controllers
+from pymoult.threads import *
+from pymoult.updates import *
+from pymoult.collector import *
+from pymoult.controller import *
+from pymoult.stack.generators import *
+from pymoult.heap.generators import *
 import socket
 import time
 
 
+
 Socket_port = 5678
 
-
 class Product(object):
 	def __init__(self,name,quantity):
 		self.name = name
 	while True:
 		conn,addr = s.accept()
 		command = conn.recv(9999)
-		pymoult.controllers.start_passive_update()
+		start_active_update()
 		do_command(command)
-		pymoult.controllers.start_passive_update()
+		start_active_update()
 		data = ""
 		conn.close()
 
+enable_pool()
+manager = DSU_Thread(name="Site_Manager",target=site_manager_main)
+socket_thread = DSU_Thread(name="Command_Socket",target=socket_main)
+start_controller()
+manager.start()
+socket_thread.start()
 
 
+Site_Updater = eager_class_updater(make_global_element("__main__","Site"))
+Product_Updater = lazy_class_updater(make_global_element("__main__","Product"))
 
-pool = pymoult.controllers.enable_eager_object_conversion()
-threads = pymoult.controllers.start_active_threads(pool,site_manager_main)
-threads+= pymoult.controllers.start_passive_threads(pool,socket_main)
-pymoult.controllers.register_threads(threads)
+Command_Updater = safe_redefinition(make_global_element("__main__","do_command"),[make_thread_element(socket_thread)])
+Manager_Updater = thread_rebooting(make_thread_element(manager))
+
+
+
+
+
+