Summary: Describing the built-in BasicProcessingUnitContainer which is an implementation of the IProcessingUnitContainer interface.
OverviewA processing unit container is a component that is implemented by the user and it can be deployed and managed by the service grid. XAP.NET comes with a built-in type implementation of the processing unit container named BasicProcessingUnitContainer which can be used as is for easier and faster processing unit development and let the implementor consentrate more on the business logic part and less with GigaSpaces components.
Using The ContainerThe basic container simplifies the actual implementation of the processing unit by managing on its own GigaSpaces related components which are commonly used when developing application which are deployed into the grid. Integrating The Container Into Your ProjectIn order to use the container as part of the processing unit project, you need a config file, which is used to deploy the Processing Unit Container. This config file must be named pu.config and needs to be placed together with your processing unit container implementation assemblies. The pu.config file should be as follows: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="GigaSpaces.XAP" type="GigaSpaces.XAP.Configuration.GigaSpacesXAPConfiguration, GigaSpaces.Core"/> </configSections> <GigaSpaces.XAP> <ProcessingUnitContainer Type="GigaSpaces.XAP.ProcessingUnit.Containers.BasicContainer.BasicProcessingUnitContainer, GigaSpaces.Core"/> </GigaSpaces.XAP> </configuration> This configuration file specify that the container that should be deployed is the BasicProcessingUnitContainer, in the same manner any other custom container implementation would have been deployed. Automatic Space Proxy Creation And ManagementThe container can create and manage the life cycle of space proxies, it reduces the need from the user to properly dispose proxies or shutdown started embedded spaces once the container is undeployed. A managed space proxy can be created in the container either by configuring it with a configuration file. The following config file will cause the container to create and manage an embedded space proxy: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="GigaSpaces.XAP" type="GigaSpaces.XAP.Configuration.GigaSpacesXAPConfiguration, GigaSpaces.Core"/> </configSections> <GigaSpaces.XAP> <ProcessingUnitContainer Type="GigaSpaces.XAP.ProcessingUnit.Containers.BasicContainer.BasicProcessingUnitContainer, GigaSpaces.Core"/> <BasicContainer> <SpaceProxies> <add Name="MySpace" Url="/./mySpace"/> </SpaceProxies> </BasicContainer> </GigaSpaces.XAP> </configuration> Basic Processing Unit ComponentsThere can be different user components that are part of the processing unit. Here's an example of a basic component which keeps a reference to a space proxy which is managed by the container: [BasicProcessingUnitComponent(Name="MyComponent")] public class MyComponent : IDisposable { private ISpaceProxy _proxy; [ContainerInitialized] public void Initialize(BasicProcessingUnitContainer container) { _proxy = container.GetSpaceProxy("MySpace"); [..] Console.WriteLine("MyComponent initialized"); } public void Dispose() { Console.WriteLine("MyComponent Disposing"); } }
In order for the container to automatically detect the component, the container needs to be configured with the specific assemblies that needs to be scanned for such components, this is done at the configuration file in the following manner: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="GigaSpaces.XAP" type="GigaSpaces.XAP.Configuration.GigaSpacesXAPConfiguration, GigaSpaces.Core"/> </configSections> <GigaSpaces.XAP> <ProcessingUnitContainer Type="GigaSpaces.XAP.ProcessingUnit.Containers.BasicContainer.BasicProcessingUnitContainer, GigaSpaces.Core"/> <BasicContainer> <ScanAssemblies> <add AssemblyName="MyAssembly"/> </ScanAssemblies> <SpaceProxies> <add Name="MySpace" Url="/./mySpace"/> </SpaceProxies> </BasicContainer> </GigaSpaces.XAP> </configuration>
Automatic Remote Services Creation And HostingOne of GigaSpaces grid components is remote services, which can be hosted in the grid. The basic container automatically detects such services, creates, host and managed their life cycle. This is done by marking the remote service with the [SpaceRemotingService] attribute and specifying the assembly name that contains the service class for auto scanning like in the above example. [SpaceRemotingService]
public class MyService : IService
{
[..]
}
As long as MyService is part of the assemblies which are specified for scanning (Like in the above example) it will be automatically instantiated and hosted in the grid by the container. Automatic Event Listener Creation And ManagementAn event listener container is one of the most commonly used GigaSpaces components as part of a processing unit. In a very similar way to the previous components, such event containers can be automatically detected, created and managed by the basic container. The basic container will automatically detect
[PollingEventDriven(Name="MyEventListener")] public class MyEventListener { [..] } An event listener container needs a space proxy that it will listen for events from according to its internal logic. If the basic container is managing a single proxy then that proxy will be supplied to the event listener container. If there are more than one proxies then the proxy name needs to be specified in the configuration file for that specific event listener container. The following basic container config will start two space proxies and supply the colocated proxy, named MySpace, to the event listener container: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="GigaSpaces.XAP" type="GigaSpaces.XAP.Configuration.GigaSpacesXAPConfiguration, GigaSpaces.Core"/> </configSections> <GigaSpaces.XAP> <ProcessingUnitContainer Type="GigaSpaces.XAP.ProcessingUnit.Containers.BasicContainer.BasicProcessingUnitContainer, GigaSpaces.Core"/> <BasicContainer> <ScanAssemblies> <add AssemblyName="MyAssembly"/> </ScanAssemblies> <SpaceProxies> <add Name="MySpace" Url="/./mySpace"/> <add Name="MyRemoteSpace" Url="jini://*/*/myRemoteSpace"/> </SpaceProxies> <EventContainers> <add Name="MyEventListener" SpaceProxyName="MySpace"/> </EventContainers> </BasicContainer> </GigaSpaces.XAP> </configuration>
|
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |