# HG changeset patch # User Paul Boddie # Date 1454970279 -3600 # Node ID 068aa85f0c454af278c5b0c484c3dab422b6f89c # Parent 5abe3fb608d67ccdc38fcb68c508ccf13f5ef8d1 Made the retraction operation a complete transaction. Tidied up the locking and unlocking function application. diff -r 5abe3fb608d6 -r 068aa85f0c45 imiptools/handlers/scheduling/__init__.py --- a/imiptools/handlers/scheduling/__init__.py Mon Feb 08 23:24:09 2016 +0100 +++ b/imiptools/handlers/scheduling/__init__.py Mon Feb 08 23:24:39 2016 +0100 @@ -32,23 +32,17 @@ """ Apply the given scheduling 'functions' in the current object of the given - 'handler'. + 'handler'. This function starts a transaction that should be finalised using + the 'finish_scheduling' function. """ - # Obtain the actual scheduling functions with arguments. - # Also obtain functions to lock resources. - - schedulers = get_function_calls(functions, scheduling_functions) - locks = get_function_calls(functions, locking_functions) - # First, lock the resources to be used. - for fn, args in locks: + start_scheduling(functions, handler) - # Not all scheduling functions require compound locking. + # Obtain the actual scheduling functions with arguments. - if fn: - fn(handler, args) + schedulers = get_function_calls(functions, scheduling_functions) # Then, invoke the scheduling functions. @@ -84,7 +78,8 @@ """ Confirm scheduling using the given listener 'functions' for the current - object of the given 'handler'. + object of the given 'handler'. This function continues a transaction that + should be finalised using the 'finish_scheduling' function. """ # Obtain the actual listener functions with arguments. @@ -92,6 +87,39 @@ functions = get_function_calls(functions, confirmation_functions) apply_functions(functions, handler) +def retract_scheduling(functions, handler): + + """ + Retract scheduling using the given listener 'functions' for the current + object of the given 'handler'. This function is a complete transaction in + itself. + """ + + # First, lock the resources to be used. + + start_scheduling(functions, handler) + + # Obtain the actual listener functions with arguments. + + retractors = get_function_calls(functions, retraction_functions) + apply_functions(retractors, handler) + + # Finally, unlock the resources. + + finish_scheduling(functions, handler) + +def start_scheduling(functions, handler): + + """ + Apply locking functions for the given scheduling 'functions' and for the + current object of the given 'handler'. + """ + + # Obtain functions to lock resources. + + locks = get_function_calls(functions, locking_functions) + apply_functions(locks, handler) + def finish_scheduling(functions, handler): """ @@ -102,27 +130,7 @@ # Obtain functions to unlock resources. locks = get_function_calls(functions, unlocking_functions) - - # Unlock the resources that were used. - - for fn, args in locks: - - # Not all scheduling functions require compound locking. - - if fn: - fn(handler, args) - -def retract_scheduling(functions, handler): - - """ - Retract scheduling using the given listener 'functions' for the current - object of the given 'handler'. - """ - - # Obtain the actual listener functions with arguments. - - functions = get_function_calls(functions, retraction_functions) - apply_functions(functions, handler) + apply_functions(locks, handler) def apply_functions(functions, handler):