|
BDE 4.14.0 Production release
|
Provide a multiplexing observer that forwards to other observers.
This component provides a concrete implementation of the ball::Observer protocol for receiving and processing log records:
ball::MultiplexObserver is a concrete class derived from ball::Observer that processes the log records it receives through its publish method by forwarding them to other concrete observers. ball::MultiplexObserver maintains a registry of observers to which it forwards log records. Clients of ball::MultiplexObserver register observers using the registerObserver method and unregister observers with the deregisterObserver method. Once registered, an observer receives all log records that its associated multiplexing observer receives.
ball::MultiplexObserver is thread-safe and thread-enabled, meaning that multiple threads may share the same instance, or may have their own instances.
This section illustrates intended use of this component.
Note: This usage example retained here for reference purposes for legacy code that still uses multiplex observers. The use of this component is strongly discouraged.
Multiplexing observers are used to interface a ball logging system, which generates log records, with the multiplicity of observers that are to receive the generated records that are published. Establishing this interface proceeds in three logical steps:
This example demonstrates the use of a multiplexing observer to forward log records from a ball logging system to three registered observers. Each of the three registered observers performs distinct actions upon receipt of log records:
First, we create the three downstream observers that will be registered with multiplexor observer:
Next, we create an initially empty multiplexing observer multiplexor and register the three downstream observers multiplexor:
Then, multiplexor is installed within a ball logging system to be the direct recipient of published log records. The code uses deprecated ball::LoggerManager API and is elided.
Henceforth, all log records that are published by the logging system will be transmitted to the publish method of multiplexor which, in turn, forwards them to defaultObserver, logfileObserver, and encryptingObserver by calling their respective publish methods.
Finally, deregister the three observers when the logs have been all forwarded:
Note that any observer must exist before registering with multiplexor. Any observer already registered must deregister before its destruction. Additional observers may be registered with multiplexor at any time. Similarly, observers may be unregistered at any time. This capability allows for extremely flexible observation scenarios.