1.1 --- a/imiptools/handlers/scheduling/__init__.py Mon Feb 08 23:24:09 2016 +0100
1.2 +++ b/imiptools/handlers/scheduling/__init__.py Mon Feb 08 23:24:39 2016 +0100
1.3 @@ -32,23 +32,17 @@
1.4
1.5 """
1.6 Apply the given scheduling 'functions' in the current object of the given
1.7 - 'handler'.
1.8 + 'handler'. This function starts a transaction that should be finalised using
1.9 + the 'finish_scheduling' function.
1.10 """
1.11
1.12 - # Obtain the actual scheduling functions with arguments.
1.13 - # Also obtain functions to lock resources.
1.14 -
1.15 - schedulers = get_function_calls(functions, scheduling_functions)
1.16 - locks = get_function_calls(functions, locking_functions)
1.17 -
1.18 # First, lock the resources to be used.
1.19
1.20 - for fn, args in locks:
1.21 + start_scheduling(functions, handler)
1.22
1.23 - # Not all scheduling functions require compound locking.
1.24 + # Obtain the actual scheduling functions with arguments.
1.25
1.26 - if fn:
1.27 - fn(handler, args)
1.28 + schedulers = get_function_calls(functions, scheduling_functions)
1.29
1.30 # Then, invoke the scheduling functions.
1.31
1.32 @@ -84,7 +78,8 @@
1.33
1.34 """
1.35 Confirm scheduling using the given listener 'functions' for the current
1.36 - object of the given 'handler'.
1.37 + object of the given 'handler'. This function continues a transaction that
1.38 + should be finalised using the 'finish_scheduling' function.
1.39 """
1.40
1.41 # Obtain the actual listener functions with arguments.
1.42 @@ -92,6 +87,39 @@
1.43 functions = get_function_calls(functions, confirmation_functions)
1.44 apply_functions(functions, handler)
1.45
1.46 +def retract_scheduling(functions, handler):
1.47 +
1.48 + """
1.49 + Retract scheduling using the given listener 'functions' for the current
1.50 + object of the given 'handler'. This function is a complete transaction in
1.51 + itself.
1.52 + """
1.53 +
1.54 + # First, lock the resources to be used.
1.55 +
1.56 + start_scheduling(functions, handler)
1.57 +
1.58 + # Obtain the actual listener functions with arguments.
1.59 +
1.60 + retractors = get_function_calls(functions, retraction_functions)
1.61 + apply_functions(retractors, handler)
1.62 +
1.63 + # Finally, unlock the resources.
1.64 +
1.65 + finish_scheduling(functions, handler)
1.66 +
1.67 +def start_scheduling(functions, handler):
1.68 +
1.69 + """
1.70 + Apply locking functions for the given scheduling 'functions' and for the
1.71 + current object of the given 'handler'.
1.72 + """
1.73 +
1.74 + # Obtain functions to lock resources.
1.75 +
1.76 + locks = get_function_calls(functions, locking_functions)
1.77 + apply_functions(locks, handler)
1.78 +
1.79 def finish_scheduling(functions, handler):
1.80
1.81 """
1.82 @@ -102,27 +130,7 @@
1.83 # Obtain functions to unlock resources.
1.84
1.85 locks = get_function_calls(functions, unlocking_functions)
1.86 -
1.87 - # Unlock the resources that were used.
1.88 -
1.89 - for fn, args in locks:
1.90 -
1.91 - # Not all scheduling functions require compound locking.
1.92 -
1.93 - if fn:
1.94 - fn(handler, args)
1.95 -
1.96 -def retract_scheduling(functions, handler):
1.97 -
1.98 - """
1.99 - Retract scheduling using the given listener 'functions' for the current
1.100 - object of the given 'handler'.
1.101 - """
1.102 -
1.103 - # Obtain the actual listener functions with arguments.
1.104 -
1.105 - functions = get_function_calls(functions, retraction_functions)
1.106 - apply_functions(functions, handler)
1.107 + apply_functions(locks, handler)
1.108
1.109 def apply_functions(functions, handler):
1.110