Summary: Cluster construction information is provided by the different Processing Unit containers, and is abstracted in a class called ClusterInfo, which is injected into the Spring application context.

Overview

One of the core ideas of the OpenSpaces Processing Unit is the fact that the topology the Processing Unit is deployed in, is decided in deploy-time. Therefore, when building a Processing Unit, there is almost no need to be aware of the actual cluster topology that the Processing Unit is deployed under.

For a Processing Unit to be cluster topology independent, there are two aspects that are important to remember when building it:

  • Define a routing index on the domain model written to the space, so the partitioned topology can work.
  • When working directly against a cluster member, make sure you don't perform operations against the backup member. This is simplified if working with one of the event containers, since they provide it by default, or when using the space mode context loader.

When constructing an embedded space, information regarding its cluster topology is required. In OpenSpaces, cluster construction*** information is provided by the different Processing Unit containers. The information itself is abstracted in a class called ClusterInfo, which is injected into the Spring application context (encapsulated within the Processing Unit).

ClusterInfo

The ClusterInfo class holds the following information:

Name Description
ClusterInfo#getSchema The cluster topology cluster schema*** .
ClusterInfo#getNumberOfInstances The number of primary instances this cluster holds.
ClusterInfo#getNumberOfBackups The number of backups per primary instance.
ClusterInfo#getInstanceId 1 to the numberOfInstances value, denoting the primary instance ID of the current Processing Unit instance.
ClusterInfo#getBackupId 1 to the numberOfBackups value, denoting the backup ID of the instanceId of the current Processing Unit instance. null if there is no backup id.
ClusterInfo#getRunningNumber A running number of the cluster instance. Takes into account different topologies and provides a unique identifier (starting from 0) of the cluster member.
ClusterInfo#getRunningNumberOffset1 Same as getRunningNumber with the addition of 1.

Defining a null value in one of these properties means that they are not set.

ClusterInfoAware

In a similar manner to the Spring ApplicationContextAware interface, that allows beans to be injected with Spring's ApplicationContext by implementing the interface; OpenSpaces provides the ClusterInfoAware interface:

public interface ClusterInfoAware {

    /**
     * Sets the cluster information.
     * 
     * <p>Note, the cluster information is obtained externally from the applicaiton context which means
     * that this feature need to be supported by specific containers (and is not supported by plain
     * Spring application context). This means that beans that implement {@link ClusterInfoAware}
     * should take into account the fact that the cluster info provided might be null.
     * 
     * @param clusterInfo
     *            The cluster information to be injected
     */
    void setClusterInfo(ClusterInfo clusterInfo);
}

All built-in Processing Unit containers provide support for the ClusterInfo and ClusterInfoAware interfaces by default. Built-in OpenSpaces components make use of this feature. User-defined beans can make use of this information as well (for example, to connect to a specific database based on the ID of the Processing Unit instance).

@ClusterInfoContext

Like the ClusterInfoAware interface, this field level annotation allows beans to be injected with ClusterInfo.

public class MyBean {

    @ClusterInfoContext
    private ClusterInfo clusterInfo;

    ...
}

Space Construction and ClusterInfo

The Space component implements the ClusterInfoAware, and uses it in order to construct an embedded space by mapping ClusterInfo properties to Space URL properties (if provided). Here is a mapping from ClusterInfo to Space URL properties:

ClusterInfo Space URL
ClusterInfo#getSchema cluster_schema
ClusterInfo#getNumberOfInstances total_members first value (before the comma)
ClusterInfo#getNumberOfBackups total_members second value (after the comma)
ClusterInfo#getInstanceId id
ClusterInfo#getBackupId backup_id

ClusterInfo XML Injection

When using one of the built-in containers, ClusterInfo can also be used within the Spring XML configuration. In a similar manner, properties can be injected. Here is an example of how they can be used:

<bean id="myBean" class="MyBean">
    <property name="connectionUrl" value="testconnection_${clusterInfo.runnimgNumber}" />
</bean>

In the above example, the value of the connectionUrl and property of MyBean are built based on the runningNumber provided by the ClusterInfo interface. Here is a list mapping the ClusterInfo properties to their equivalent {...} values.

ClusterInfo Space URL
ClusterInfo#getSchema clusterInfo.schema
ClusterInfo#getNumberOfInstances clusterInfo.numberOfInstances
ClusterInfo#getNumberOfBackups clusterInfo.numberOfBackups
ClusterInfo#getInstanceId clusterInfo.instanceId
ClusterInfo#getBackupId clusterInfo.backupId
ClusterInfo#getRunningNumber clusterInfo.runningNumber
ClusterInfo#getRunningNumberOffest1 clusterInfo.runningNumberOffest1

Processing Unit Container Injection

Every Processing Unit container supports injection of ClusterInfo in a common manner. When running the container or deploying a Processing Unit to it, the -cluster command-line parameter should be supported: The -cluster option has the following optional parameters:

  • schema clusterSchemaName: Maps to ClusterInfo#setSchema.
  • total_members numberOfInstances[,numberOfBackups]: Maps to ClusterInfo#setNumberOfInstances, and optionally ClusterInfo#setNumberOfBackups.
  • id instanceId: Maps to ClusterInfo#setInstanceId (only applies for runnable Processing Unit containers such as integrated and standalone).
  • backup_id backupId: Maps to ClusterInfo#setBackupId (only applies for runnable Processing Unit containers such as integrated and standalone).

For more details on how to use the -cluster option, see the Processing Unit Containers section.

***Link required

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