Wiki

Clone wiki

pymoult / updates

#Updates

Update classes are used to supply information about the update to the managers. This information are the requirements of the update (what other update is required for this update to be safely applied?), its alterability (in wich state the application must be?), its update code and its ending condition (when is the update complete?).

Updates are supplied to a manager using the add_update method of that manager.

##Update

This is the base class that must be extended to define new updates. It has a method every step of the update life cycle :

  1. check_requirements : checking if the update is compatible with the application
  2. preupdate_setup : preliminary setup before waiting for quiescence
  3. wait_alterability : returns when alterablity is reached (used by ThreadedManager)
  4. check_alterability : returns whether alterability criteria were met (used by Manager)
  5. apply : modifies the application
  6. preresume_setup : setup phase before resuming the application
  7. wait_over : waits for the update to be over (used by ThreadedManager)
  8. check_over : checks if the update is over (used by Manager)
  9. clean_failed_alterability : cleans everything if alterability could not be reached

lowlevel functions from Pymoult are to be used in these methods. For each function, a commentary in the source code will tell at which step it should be called.

The Update class has other methods such as set_max_tries and set_sleep_time for regulating the waiting time of the manager when waiting for alterability (or for the update to be over)

The suspend_hook and resume_hook methods will be called by the manager when suspending threads and resuming them.

##Functions

isApplied(updateName)

This function returns true if the update named updateName has been applied. False otherwise.

##Preconfigured Update classes

These preconfigured classes use classic setups of mechanisms. They take as arguments the targets of the update.

Every update class can be given a name by specifying the keyword argument e.g.name=foo. By default that name is None.

SafeRedefineUpdate

This update class redefines a function when it is not in the stack of the threads watched by the manager.

It takes as arguments the module where the function to be redefined is defined, the function to be redefined and its new version

EagerConversionUpdate

This update class uses the Eager strategy to access and update objects of a given class. In order to use this update, an ObjectsPool (from lowlevel.data_access) must have been created when starting the application.

It takes as arguments the class to be updated, its new version and a transformer that will applied to eavery instance of class.

LazyConversionUpdate

This update class uses the Lazy strategy to access and update objects of a given class. In order to use this update, an ObjectsPool (from lowlevel.data_access) must have been created when starting the application.

It takes as arguments the class to be updated, its new version and a transformer that will applied to eavery instance of class.

ThreadRebootUpdate

This update class reboots a thread after swaping its main method. Only DSU_Thread can be rebooted in such a way.

It takes as arguments the thread to be rebooted, its new main function and a list of args that will be given to that new main function.

HeapTraversalUpdate

This update walks the heap to update the data (or apply a function on it). It takes as arguments a walker that will walk the heap and do the work and a list of module (only __main__ by default) to which the walker will be applied.

Updated