OpenSpaces Core Component - Space

  Search Here
Searching XAP 6.0 Documentation

                                               

Summary: A Space component allows you to create an IJSpace (or JavaSpace) based on a space URL.

Overview

The different space components allow you to configure a space within a Spring application context (or a Processing Unit). A Space component allows you to create an IJSpace (or JavaSpace) with the most common practice of creating one based on a Space URL.

Here is an example of creating a space within a Spring XML-based configuration:

This example creates an embedded space (IJSpace) within the Spring application context (using the /./ prefix) with the name space and a Spring bean id of the space.

URL Properties

The UrlSpaceFactoryBean allows you to set different URL properties (as defined in the Space URL) either explictly using explicit properties or using a custom Properties object. All of the current URL properties are exposed using explicit properties in order to simplify the configuration, except for clustering properties (see the Cluster Configuration section).

Here is an example a space with specific schema working in FIFO mode, using specific lookup groups.

General Properties

The space allows you to override specific schema element values using the Properties object, that uses an XPath-like navigation as the name value. The UrlSpaceFactoryBean allows you to set the Properties object, specifying it within the Spring configuration.

Embedded vs. Remote Space

When looking up or creating a space, OpenSpaces qualifies the state of the Space as either embedded or remote. An embedded space uses /./ as the URL "protocol", and causes the space to be created and be part of the application context (or processing unit). A remote space is one that was looked up using one of the remote protocols (Jini or RMI). The previous example showed how to look up an embedded space, while the example below shows you how to look up a remote space using the Jini protocol (looks up a space called space on all machines under the same lookup group).

Clustering

OpenSpaces views clustering as a deployment or runtime decision. The idea is not to configure a space with clustering information (total_members, id, etc.) within the Spring configuration, but allows the application context to be injected with this information when it is deployed (or run within the IDE).

Built on the same concept of Spring ApplicationContextAware callback interface, OpenSpaces defines ClusterInfo – an object holding the specific Processing Unit instance cluster parameters (id, total_members, backup_id, etc.), and ClusterInfoAware – allows any Spring bean to implement this interface and be injected with the cluster parameters.

The UrlSpaceFactoryBean implements this ClusterInfoAware and uses the ClusterInfo in order to automatically amend the Space URL with cluster parameters. The ClusterInfo is provided by external containers that can run a Processing Unit.

For more details on ClusterInfo, refer to the Cluster Info section.

Primary/Backup

When working in clustered mode (schema) that includes a primary/backup schema, several components within the Processing Unit need to be aware of the current space mode and any changes made to it (such as event containers). Using Spring support for application events, two events are defined within OpenSpaces: BeforeSpaceModeChangeEvent and AfterSpaceModeChangeEvent. Both are raised when a space changes its mode from primary to backup or versa, and holds the current space mode.

Custom beans that need to be aware of the space mode (for example, working directly against a cluster member, i.e. not using a clustered proxy of the space, and performing operations against the space only when it is in primary mode) can implement the Spring ApplicationListener and check for the mentioned events.

OpenSpaces also provides the space mode context loader, which can load Spring application context when it has become primary, and unload it when it moves to backup.

In embedded mode, the space factory bean registers with the space for space mode changes. The registration is performed on the actual space instance (and not a clustered proxy of it), and any events raised are translated to the equivalent OpenSpaces space mode change events. In remote mode, a single primary event is raised.

Space mode registration can be overridden and explicitly set within the space factory configuration. Here is an example of how it can be set (cannot register for notifications even though it is an embedded space):

Security Context

A secured space should be configured with a security context so that it can be accessed (when connecting to it remotely). Here is an example of how this can be configured:

Here is how to define security with an embedded space. In this case, we enable security and specify the username and password.

Fore more details, refer to the [Space Security] section.

Space Filters

The UrlSpaceFactoryBean allows you to configure Space Filters. It uses the space support for a FilterProvider which is a wrapper for an ISpaceFilter implementation and its characteristics (such as priority, activeWhenBackup), allowing to provide space filters without changing the space schema.

Space Filters can only be used with embedded spaces.

ISpaceFilter

An actual implementation of the ISpaceFilter interface can be provided using the SpaceFilterProviderFactory class. Here is a very simple example of an ISpaceFilter implementation:

public class SimpleFilter implements ISpaceFilter {

    public void init(IJSpace space, String filterId, String url, int priority) 
                throws RuntimeException {
        // perform operations on init
    }

    public void process(SpaceContext context, ISpaceFilterEntry entry, int operationCode) 
                throws RuntimeException {
        // process single entry filter operations
    }

    public void process(SpaceContext context, ISpaceFilterEntry[] entries, int operationCode) 
                throws RuntimeException {
        // process multiple entries filter operation (such as update)
    }

    public void close() throws RuntimeException {
        // perform operation when filter closes
    }
}

The following Spring configuration registers this filter for before write (0), before read (2), and before take (3) operations:


GigaSpaces 6.0 Documentation Contents (Current Page in Bold)

    Java

    C++

    .NET

    Middleware Capabilities

    Configuration and Management

Add GigaSpaces wiki search to your browser search engines!
(works on Firefox 2 and Internet Explorer 7)

Labels