1.1 --- a/imiptools/handlers/scheduling/__init__.py Tue Feb 09 12:19:13 2016 +0100
1.2 +++ b/imiptools/handlers/scheduling/__init__.py Tue Feb 09 14:17:52 2016 +0100
1.3 @@ -28,21 +28,21 @@
1.4
1.5 # Function application/invocation.
1.6
1.7 -def apply_scheduling_functions(functions, handler):
1.8 +def apply_scheduling_functions(handler):
1.9
1.10 """
1.11 - Apply the given scheduling 'functions' in the current object of the given
1.12 + Apply the scheduling functions for the current object of the given
1.13 'handler'. This function starts a transaction that should be finalised using
1.14 the 'finish_scheduling' function.
1.15 """
1.16
1.17 # First, lock the resources to be used.
1.18
1.19 - start_scheduling(functions, handler)
1.20 + start_scheduling(handler)
1.21
1.22 # Obtain the actual scheduling functions with arguments.
1.23
1.24 - schedulers = get_function_calls(functions, scheduling_functions)
1.25 + schedulers = get_function_calls(handler.get_scheduling_functions(), scheduling_functions)
1.26
1.27 # Then, invoke the scheduling functions.
1.28
1.29 @@ -74,41 +74,40 @@
1.30
1.31 return response
1.32
1.33 -def confirm_scheduling(functions, handler):
1.34 +def confirm_scheduling(handler):
1.35
1.36 """
1.37 - Confirm scheduling using the given listener 'functions' for the current
1.38 - object of the given 'handler'. This function continues a transaction that
1.39 - should be finalised using the 'finish_scheduling' function.
1.40 + Confirm scheduling using confirmation functions for the current object of
1.41 + the given 'handler'. This function continues a transaction that should be
1.42 + finalised using the 'finish_scheduling' function.
1.43 """
1.44
1.45 - # Obtain the actual listener functions with arguments.
1.46 + # Obtain the actual confirmation functions with arguments.
1.47
1.48 - functions = get_function_calls(functions, confirmation_functions)
1.49 + functions = get_function_calls(handler.get_scheduling_functions(), confirmation_functions)
1.50 apply_functions(functions, handler)
1.51
1.52 -def retract_scheduling(functions, handler):
1.53 +def retract_scheduling(handler):
1.54
1.55 """
1.56 - Retract scheduling using the given listener 'functions' for the current
1.57 - object of the given 'handler'. This function is a complete transaction in
1.58 - itself.
1.59 + Retract scheduling using retraction functions for the current object of the
1.60 + given 'handler'. This function is a complete transaction in itself.
1.61 """
1.62
1.63 # First, lock the resources to be used.
1.64
1.65 - start_scheduling(functions, handler)
1.66 + start_scheduling(handler)
1.67
1.68 - # Obtain the actual listener functions with arguments.
1.69 + # Obtain the actual retraction functions with arguments.
1.70
1.71 - retractors = get_function_calls(functions, retraction_functions)
1.72 - apply_functions(retractors, handler)
1.73 + functions = get_function_calls(handler.get_scheduling_functions(), retraction_functions)
1.74 + apply_functions(functions, handler)
1.75
1.76 # Finally, unlock the resources.
1.77
1.78 - finish_scheduling(functions, handler)
1.79 + finish_scheduling(handler)
1.80
1.81 -def start_scheduling(functions, handler):
1.82 +def start_scheduling(handler):
1.83
1.84 """
1.85 Apply locking functions for the given scheduling 'functions' and for the
1.86 @@ -117,10 +116,10 @@
1.87
1.88 # Obtain functions to lock resources.
1.89
1.90 - locks = get_function_calls(functions, locking_functions)
1.91 - apply_functions(locks, handler)
1.92 + functions = get_function_calls(handler.get_scheduling_functions(), locking_functions)
1.93 + apply_functions(functions, handler)
1.94
1.95 -def finish_scheduling(functions, handler):
1.96 +def finish_scheduling(handler):
1.97
1.98 """
1.99 Finish scheduling using the given scheduling 'functions' for the current
1.100 @@ -129,24 +128,28 @@
1.101
1.102 # Obtain functions to unlock resources.
1.103
1.104 - locks = get_function_calls(functions, unlocking_functions)
1.105 - apply_functions(locks, handler)
1.106 + functions = get_function_calls(handler.get_scheduling_functions(), unlocking_functions)
1.107 + apply_functions(functions, handler)
1.108
1.109 def apply_functions(functions, handler):
1.110
1.111 """
1.112 Apply the given notification 'functions' for the current object of the given
1.113 - 'handler'.
1.114 + 'handler'. Where functions are provided more than once, they will be called
1.115 + only once for each distinct set of arguments.
1.116 """
1.117
1.118 + applied = set()
1.119 +
1.120 for fn, args in functions:
1.121
1.122 # NOTE: Should signal an error for incorrectly configured resources.
1.123
1.124 - if not fn:
1.125 + if not fn or (fn, args) in applied:
1.126 continue
1.127
1.128 fn(handler, args)
1.129 + applied.add((fn, args))
1.130
1.131 # Function lookup.
1.132
1.133 @@ -169,7 +172,7 @@
1.134
1.135 for line in lines:
1.136 parts = parse_line(line)
1.137 - functions.append((registry.get(parts[0]), parts[1:]))
1.138 + functions.append((registry.get(parts[0]), tuple(parts[1:])))
1.139
1.140 return functions
1.141