Greetings all. In this post I want to get a little bit deeper into the block’s data collection components’ implementation.
At the core of the metering block are two main concepts, the TickTock component and the providers. The TickTock component is a concept we borrowed from the Patterns and Practices Microsoft Enterprise Library 5.0 Integration Pack for Windows Azure, The Autoscaling Application Block which we have also contributed. The heart of the Autoscaling block is a sub-component referred as “Metronome”, we are using a similar concept, with a few changes in the Metering core as well and named it as “TickTock”.
After the block is started the Start() method gets hold of the custom configuration section. This results in getting the configuration object graph built by the .Net framework. The mandatory CreateNewElement() method on the ProvidersCollection class, derived from the ConfigurationElementCollection is the one that is responsible for loading the appropriate provider configuration type into the AppDomain with the typical GetType(), Activator.CreateInstance() pattern. The provider’s class should carry a custom attribute which specifies the type for the configuration element for the provider. Using this pattern and getting the type for the configuration element through the custom attribute, this method for the collection knows which collection element class, thus the appropriate element for the provider needs to be loaded in and activated.
At this point we will have the whole configuration section loaded, with the appropriate provider types loaded into the AppDomain.
The metering block Start() method calls the Initialize() method and this in turn continues with calling the RegisterType() method of the providers that implement the ITypeRegistration interface. Each provider configuration element, that derives from ProviderElement base class implements that interface, and is responsible for registering the respective provider type with the Unity framework.
Having completed loading in the provider types, and getting them registered with Unity, next step Initialize() does is to register the Collect() methods of the provider with the TickTock class, with their collect intervals, so TickTock can call the Collect() methods at those intervals. We utilize Reactive Extensions for the TickTock class to call the Collect() methods of the providers.