Summary: Allows you to use OpenSpaces within pure (non processing unit) client.

Overview

OpenSpaces are composed of a set of components (such as Space and Notify Container) which can be easily used both using pure code and using Spring support for different configuration mechanisms. Spring provides extensive support for integrating with web containers, as well as integrating with different web frameworks.

OpenSpaces does not require using Spring as the configuration mechanism. Each component in OpenSpaces has a respective "Configurer" that provides a DSL like construction of such components.

Required Libraries

Integrating with web containers requires that GigaSpaces required JAR files be copied over into the WEB-INF/lib directory (when using web container). The following JAR files need to be copied over: JSpaces.jar, openspaces.jar, commons-logging.jar, gs-boot.jar, gs-lib.jar, gs-service.jar, jsk-lib.jar, jsk-platform.jar, reggie.jar, start.jar, spring.jar (if you are using distributed transaction manager, also mahalo.jar).

Spring Configuration - Remote Connection

Most often the web container will connect to a remote Space/Processing Unit deployed within the Service Grid (possibly using a local cache). The following configuration allows to define a GigaSpace which can then be used to access the Space:

Namespace
<os-core:space id="space" url="jini://*/*/mySpace?groups=myGroup" />

<os-core:giga-space id="gigaSpace" space="space"/>

Plain XML
<bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean">
    <property name="url" value="jini://*/*/mySpace?groups=myGroup" />
</bean>

<bean id="gigaSpace" class="org.openspaces.core.GigaSpaceFactoryBean">
	<property name="space" ref="space" />
</bean>

Code
IJSpace space = // get Space either by injection or code creation

GigaSpace gigaSpace = new GigaSpaceConfigurer(space).gigaSpace();

Spring Configuration - Embedded Space

Certain scenarios require starting an embedded Space within the web container. Configuring it require to start an embedded Space. Here is how this can be done:

Namespace
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <!-- defines the default properties (which can be modified in the properties fiels) -->
    <property name="properties">
        <props>
            <prop key="gigaspaces.clusterGroup">myGroup</prop>
            <prop key="gigaspaces.nodeCount">3</prop>
            <prop key="gigaspaces.nodeId">1</prop>
        </props>
    </property>
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    <property name="ignoreUnresolvablePlaceholders" value="false"/>
</bean>

<os-core:space id="clustertest.space" url="/./mySpace">
    <os-core:url-properties>
        <props>
            <prop key="groups">${gigaspaces.clusterGroup}</prop>
            <prop key="cluster_schema">sync_replicated</prop>
            <prop key="total_members">${gigaspaces.nodeCount}</prop>
            <prop key="id">${gigaspaces.nodeId}</prop>
        </props>
    </os-core:url-properties>
</os-core:space>

<os-core:giga-space id="gigaSpace" space="space"/>

Plain XML
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <!-- defines the default properties (which can be modified in the properties fiels) -->
    <property name="properties">
        <props>
            <prop key="gigaspaces.clusterGroup">myGroup</prop>
            <prop key="gigaspaces.nodeCount">3</prop>
            <prop key="gigaspaces.nodeId">1</prop>
        </props>
    </property>
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    <property name="ignoreUnresolvablePlaceholders" value="false"/>
</bean>

<bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean">
    <property name="url" value="/./mySpace" />
    <property name="urlProperties">
        <props>
            <prop key="groups">${gigaspaces.clusterGroup}</prop>
            <prop key="cluster_schema">sync_replicated</prop>
            <prop key="total_members">${gigaspaces.nodeCount}</prop>
            <prop key="id">${gigaspaces.nodeId}</prop>
        </props>
    </property>
</bean>

<bean id="gigaSpace" class="org.openspaces.core.GigaSpaceFactoryBean">
	<property name="space" ref="space" />
</bean>

The above configuration allows to start an embedded sync replicated Space. It also allows to externally configure (through system properties) the node id of the different cluster members. The simplest way to provide this node ids (without changing the WAR file) is to start the different web containers using a proper value for the given system property. For example, with Tomcat, start the catalina shell with a system property of -Dgigaspaces.nodeId=1 for the first tomcat instance, and -Dgigaspaces.nodeId=2 for the second.

WAR configuration

Spring support extensive support for integration with web containers and web frameworks. If you are already using a web framework, consult its documentation on how Spring can be integrated with it. If Spring is not used, OpenSpaces components can still be fully configured through code.

Basic Spring integration with web application is documented here. Here is an example of how to configure Spring to load with a file called applicationContext.xml

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

This will start a Spring application context that is bounded to the lifecycle of the web application. Here is a very simple JSP that makes use of the configured application context and access the GigaSpace instance:

<%
    ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application);

    GigaSpace gigaSpace = (GigaSpace) context.getBean("clustertest.gigaSpace");

    if ("write".equals(request.getParameter("mode"))) {
        gigaSpace.write(new Message();
    } else {
        gigaSpace.readIfExists(new Message());
    }
%>
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence