Summary: OpenSpaces uses and enhances the Spring PropertyPlaceholderConfigurer to provide powerful and simple properties-based injection.

Overview

OpenSpaces allows you to use Java properties in order to further configure the Processing Unit when it is started or deployed. Built on top of Spring support for an externalized properties file configuration called PropertyPlaceholderConfigurer, OpenSpaces uses and enhances the mentioned feature to provide powerful and simple properties-based injection.

One of the core features of OpenSpaces is the fact that a Processing Unit should not change at all from the IDE stage till the production stage. ClusterInfo, different containers, and bean level properties enable this.

Context Properties

OpenSpaces supports properties-based configuration with a Spring application context scope. Below is an example of an XML configuration:

Namespace
<!-- Define sensible defaults -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="properties"><props>
        <prop key="space.schema">default</prop>
        <prop key="connectionTimeout">1000</prop>
    </props></property>
</bean>

<os-core:space id="space" url="/./space" schema="${space.schema}" />

<bean id="connBean" class="MyConnection">
    <property name="timeout" value="${connectionTimeout}" />
</bean>

Plain
<!-- Define sensible defaults -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="properties"><props>
        <prop key="space.schema">default</prop>
        <prop key="connectionTimeout">1000</prop>
    </props></property>
</bean>

<bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean">
    <property name="url" value="/./space" />
    <property name="schema" value="${space.schema}" />
</bean>

<bean id="connBean" class="MyConnection">
    <property name="timeout" value="${connectionTimeout}" />
</bean>

You can see that there are two externalized values for configuration: space.schema and connectionTimeout. They have defaults provided, using the Spring PropertyPlaceholderConfigurer. If no values are provided when running/deploying the Processing Unit, this value is used.

OpenSpaces Processing Unit containers provide common support for providing context properties. They can be defined using the following structure: -properties location. By default, the location is a file-system-based location of a properties file (follows Spring Resource Loader syntax). The following is an example of a properties file that can be used with the example above:

space.schema=persistent
connectionTimeout=15000

If the above file is called test.properties (used under a test environment for the example), the following properties parameter can be used: -properties test.properties.

OpenSpaces extends Spring's Resource Loader syntax when used with properties, and allows you to define these properties within the -properties option. Here is how the above properties can be defined:

-properties embed://space.schema=persistent;connectionTimeout=15000

Bean Level Properties

OpenSpaces allows you to inject properties directly to a specific bean, based on the Bean ID/name. The properties injected to the bean are a merged view of the context level properties, and the properties assigned to the specific bean name. Below is an example Spring XML:

<!-- Define sensible defaults -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="properties"><props>


        <prop key="connectionTimeout">1000</prop>
    </props></property>
</bean>

<bean id="connBean1" class="MyConnection">
    <property name="timeout" value="${connectionTimeout}" />
</bean>

<bean id="connBean2" class="MyConnection">
    <property name="timeout" value="${connectionTimeout}" />
</bean>

You can use this to inject the connectionTimeout using context level properties, which means that you have the same value for both beans. The following notation, can be used to specify the connectionTimeout in the bean level:

-properties connBean1 embed://connectionTimout=1000 -properties connBean2 embed://connectionTimeout=1500

This injects a connection timeout of 1000 to a bean named connBean1, and a connection timeout value of 15000 to a bean named connBean2.

Another solution to this problem can be to define connectionTimeout1 and connectionTimeout2, and inject them using context-level properties. This is a perfectly valid solution, bean-level properties support exceeds when injecting space properties, as defined later in this section.

@BeanLevelPropertiesContext

Like the BeanLevelPropertiesAware interface, this field level annotation allows beans to be injected with the BeanLevelProperties.

public class MyBean {

    @BeanLevelPropertiesContext
    public BeanLevelProperties beanLevelProperties;

    ...
}

BeanLevelMergedPropertiesAware

Another option for using bean-level properties, is implementing the BeanLevelMergedPropertiesAware interface. This interface is injected with the merged view, if context properties and properties are assigned directly to a specific bean.

public interface BeanLevelMergedPropertiesAware {

    /**
     * Sets the merged properties using
     * {@link BeanLevelProperties#getMergedBeanProperties(String) mergedProperties} and the bean
     * name that the bean implementing this interface is associated with.
     */
    void setMergedBeanLevelProperties(Properties beanLevelProperties);
}

This feature allows beans that use dynamic properties to be easily configured, without configuring the Spring XML in advance with such extensions. For a more concrete example, see the following section (i.e. how this feature can be used with the UrlSpaceFactoryBean).

@BeanLevelMergedPropertiesContext

Like the BeanLevelMergedPropertiesAware interface, this field level annotation allows beans to be injected with the merged view of the bean-level properties.

public class MyBean {

    @BeanLevelMergedPropertiesContext
    public Properties beanLevelMergedProperties;

    ...
}

UrlSpaceFactoryBean and BeanLevelProperties

The UrlSpaceFactoryBean uses the SpaceFinder in order to look up or create a Space. GigaSpaces allows you to use the space in the same manner, even though it has different characteristics. One of the downsides of using properties-based configuration, is the fact that you need to know in advance (when creating the space) what you would like to control. A good example of this is the space schema above. Many times, you would like to keep the Processing Unit as is, and add this information dynamically when running or deploying it. Below is a very simple embedded space creation:

Namespace
<os-core:space id="space" url="/./space" />

Plain
<bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean">
    <property name="url" value="/./space" />
</bean>

When using it, you can use the bean-level properties dynamic injection (the UrlSpaceFactoryBean implements BeanLevelMergedPropertiesAware) in order to dynamically change the space nature. Here is an example of how the space schema can be changed dynamically: -properties space embed://gs.space.url.arg.schema=persistent. Here is a more complete example of using a persistent space against an Oracle database:

gs.space.url.arg.schema=persistent
space-config.persistent.StorageAdapterClass=com.j_spaces.sadapter.GenericJDBC.JDBCStorageAdapter
space-config.persistent.StorageAdapterURL=/GenericJDBCProperties/OracleProperties

If the above properties file is called oracledb.properties, you can use the following: -properties space oracledb.properties.

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