This page describes an older version of the product. The latest stable version is 15.2.

Space Mode Context Loader

Most of the OpenSpaces built-in components take into account the state of the space (mainly applicable when starting an embedded space within the Processing Unit). This is important when working directly on a cluster member, since operations cannot be performed directly on a backup member.

Many times, custom beans or POJOs would like to operate directly on the cluster member. To do this, they need to take the space mode into account – by not performing any actions against the cluster member when it is in backup mode, and by starting to perform all relevant actions when the space mode changes to primary.

Using the custom space mode events described in the Space section, the bean can register for such events (by implementing the Spring ApplicationListener interface), and perform relevant actions based on the space mode event.

OpenSpaces provides a simpler solution, allowing you to load a Spring application context (based on a separate Spring XML configuration file) only when the Processing Unit or space is in primary mode, and unload it when the Processing Unit or space is in backup mode. If we take the following simple bean:

If there is more then one gigaSpace proxy in the pu you should bind the context to the gigaSpace instance by setting the giga-space property e.g.:

we can see that the SpaceModeContextBeanafterPropertiesSet callback is called when the Processing Unit instance is in primary mode. When it moves to backup mode, the Spring application context is unloaded, and the destroy callback is invoked. Note the usage of the GigaSpace instance, which is defined in the Processing Unit definition, as part of the bean defined in the mode.xml file. This is allowed because of the fact that the Processing Unit definition acts as a parent application context to the application context loaded with mode.xml.