Summary: Obtaining information about the clustering topology, member id and other cluster related information can be useful in many cases. Cluster information can be provided to the processing unit instances at deployment time via the class
org.openspaces.core.cluster.ClusterInfo, which can be injected into the processing unit components
OverviewOne of the core concepts of GigaSpaces processing units is the fact that the clustering topology of the processing unit is determined at deployment time. Therefore, when building a processing unit, there is almost no need to be aware of the actual clustering topology with which the processing unit is deployed. Available Cluster InformationAs mentioned above the cluster information is passed to the components of each processing unit instance via an instance of the org.openspaces.core.cluster.ClusterInfo class, which holds the following information:
Obtaining the Cluster InformationA ClusterInfo instance can be injected to the processing unit instances upon their creation.
Once injected, the processing unit components can access all the information within the ClusterInfo instance and cache it locally for later usage (by saving it as an instance variable for example). ClusterInfoAwareGigaSpaces provides the ClusterInfoAware interface, which allows beans to be injected with the ClusterInfo instance. This is similar to Spring's ApplicationContextAware interface, that allows beans to be injected with Spring's ApplicationContext by implementing the interface. public interface ClusterInfoAware { /** * Sets the cluster information. * * <p>Note, the cluster information is obtained externally from the application 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 of the processing unit runtime modes provide support for the ClusterInfo and ClusterInfoAware interfaces by default. Built-in GigaSpaces 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). @ClusterInfoContextSimilar to the the ClusterInfoAware interface, this field level annotation allows beans to be injected with the ClusterInfo instance. Here's an example: public class MyBean { @ClusterInfoContext private ClusterInfo clusterInfo; ... } Space Construction and ClusterInfoThe 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 XML InjectionWhen running the processing unit in any of the runtime modes, ClusterInfo can also be used directly within the Spring XML configuration. In a similar manner, properties can be injected. Here is an example of how this 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 property of myBean is built based on the runningNumber provided by the ClusterInfo instance. Here is a list mapping the ClusterInfo properties to their equivalent ${clusterInfo.*} syntax:
Processing Unit Container InjectionEach of the runtime modes supports the injection of ClusterInfo. However, when running in standalone mode or within your IDE, the -cluster parameter controls the clustering aspects of the processing unit instance(s). Below is a list of the parameters you can specify for the standalone and IDE runtime modes, and how they are mapped the ClusterInfo properties:
|
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |