OverviewAn ISpaceFilter implementation that acts as an adapter, delegating the execution of the filter life-cycle methods and specific operation, to pluggable reflection-based methods. Using it, dismisses the need to implement the ISpaceFilter interface, and gives a more declarative filtering method. There are two ways to use the SpaceFilterOperationDelegate:
Attribute-Based ImplementationThe filter itself is a class that doesn't need to implement any interface. Instead, the filter methods are marked with specific attributes. public class SimpleAttributeFilter { [OnFilterInit] public void Initialize() { // performs operation on initialization } [BeforeWrite] public void ReportBeforeWrite() { Console.WriteLine(DateTime.Now + ": Before Write"); } } To use this class as the filter, simply use the AttributeSpaceFilterConfigFactory to create a SpaceFilterConfig instance, and use when starting a space integrated with the space filter. AttributeSpaceFilterConfigFactory filterConfigFactory = new AttributeSpaceFilterConfigFactory(); filterConfigFactory.Filter = new SimpleAttributeFilter(); // use this filter config when starting a space SpaceFilterConfig filterConfig = filterConfigFactory.CreateSpaceFilterConfig(); The AttributeSpaceFilterConfigFactory creates a SpaceFilterConfig instance, using a fully constructed SpaceFilterOperationDelegate as its Filter instance. The SpaceFilterOperationDelegate acts as the ISpaceFilter implementation, and delegates the filter operation to the SpaceAttributeFilter instance. Method Name-Based ImplementationA method name-based filter has the same basic principle as the one above. However, instead of using attributes to mark the method, the method names are specified by properties. public class SimpleMethodNameFilter { public void Initialize() { // performs operation on initialization } public void ReportBeforeWrite() { Console.WriteLine(DateTime.Now + ": Before Write"); } } ... MethodNameSpaceFilterConfigFactory filterConfigFactory = new MethodNameFilterConfigFactory(); filterConfigFactory.Filter = new SimpleAttributeFilter(); filterConfigFactory.OnFilterInit = "Initialize"; filterConfigFactory.BeforeWrite = "ReportBeforeWrite"; // use this filter config when starting a space SpaceFilterConfig filterConfig = filterConfigFactory.CreateSpaceFilterConfig(); How the SpaceFilterOperationDelegate WorksThe SpaceFilterOperationDelegate holds a map of FilterOperationDelegateInvoker for each filtered operation, which contains the logic that is used to delegate the filter operation to the supplied method. The supplied method parameters (e.g. in the code example above, the ReportBeforeWrite method) must maintain a certain structure:
Some filter operations have two entries, and therefore have a similiar, but different structure:
The filter initialization method parameter structure is different. It can receive no parameters, or one parameter which is an ISpaceProxy. If your filter needs to do things upon termination, implement the IDisposable interface, and the Dispose() method will be invoked when the space is shutting down.
|
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |