|
Summary: Allows you to use OpenSpaces within a Web Container.
OverviewOpenSpaces 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. Required LibrariesIntegrating with web containers will require to copy over GigaSpaces required jar files into the WEB-INF/lib directory. Spring Configuration - Remote ConnectionMost 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: Spring Configuration - Embedded SpaceCertain 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: 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 configurationSpring 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());
}
%>
|
(works on Firefox 2 and Internet Explorer 7)