Summary: Describing the built-in BasicProcessingUnitContainer which is an implementation of the IProcessingUnitContainer interface.

Overview

A 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.

For a full example of a processing unit and a usage of the BasicProcessingUnitContainer refer to the .NET Processing Unit Data Example page

Using The Container

The 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 Project

In 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 Management

The 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 Components

There can be different user components that are part of the processing unit.
Such components can be automatically generated and managed by the container by creating a class, which represent the logical component, and marking it with the [BasicProcessingUnitComponent] attribute. Optionally, the component can mark methods with the [ContainerInitializing] and [ContainerInitialized] which will be called when the managing basic ontainer is initializing and after it is initialized correspondigly. Moreover, it can implement the IDisposable interface which will be called once the managing container is disposing upon undeployment.

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");
  }
}

The method which has one of the attributes [ContainerInitialized] or [ContainerInitializing] can have zero arguments or one argument which will be injected with the managing container

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>

The assmebly name is the actual name and not a file path, the assembly should be part of the processing unit project output directory and be placed beside the pu.config file.

Automatic Remote Services Creation And Hosting

One 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 Management

An 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
classes that needs to be wrapped with the proper event listener container by the corresponding EventDriven attributes that marks it. Either PollingEventDriven or NotifyEventDriven.


See Polling Container Component and Notify Container Component for more info regarding event listener containers.

[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>


For more details about the Basic Processing Unit Container please refer to Detailed Basic Processing Unit Container page.

GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence