Registry
Pacemaker Import Community is designed to operate in single and multithreaded/multiprocess environments and requires sharing of data even between components in a single process and between threads and processes.
-
The registry takes effect whenever data needs to be shared
The default registry implementation works only in a single-threaded environment, where it must not handle multiple issues simultaneously that might occur in multithreaded or multiprocess environments. |
Multithreading and multiprocessing considerations
In most use cases, a single process is enough and already given with the core components of a registry implementation.
Depending on the environment in which Pacemaker Import Community gets used e.g., Pacemaker Enterprise, you may need a registry processor implementation that meets the requirements of that environment.
Example
- Version of a method for a multiprocessing environment:
RegistryProcessorInterface.php
<?php
namespace TechDivision\Import\Services;
class RegistryProcessor implements RegistryProcessorInterface
{
// other methods still go here
/**
* This method merges the passed attributes with an array that
* has already been added under the given key.
*
* If no value will be found under the passed key, the attributes
* will be registered.
*
* @param mixed $key The key of the attributes that have to be merged with the passed ones
* @param array $attributes The attributes that have to be merged with the existing ones
*
* @return void
* @throws \Exception Is thrown, if the already registered value is no array
* @link http://php.net/array_replace_recursive
*/
public function mergeAttributesRecursive($key, array $attributes) (1)
{
// merge the passed attributes in a safe manner
return function ($k, $a) use ($key, $attributes) {
// do the merge here assuming we've to handle multiple processes
};
// throw an exception if the key exists, but the found value is not of type array
throw new \Exception(sprintf('Can\'t merge attributes, because value for key %s already exists, but is not of type array', $key));
}
}
1 | As for Pacemaker Enterprise, e.g., with the use of consumer we provide
the method mergeAttributesRecursive() |