Running a Space Instance

  GigaSpaces 5.X

Documentation Home
Quick Start Guide
Release Notes

Previous release

  Search Here
Searching GigaSpaces Platform 5.X Documentation

                                               

Summary: How to run a space/cache instance in different modes, using SpaceFinder or CacheFinder.

Overview

There are several command lines and APIs you can use to run a space instance. Most of them are URL based and use the SpaceFinder or the CacheFinder factory class. The space factory classes use a URL to determine the space location (embedded, remote or master-local), the space name, and other space properties.

The following section demonstrates different usages of the space factory classes to start a space instance in different configuration modes. In addition to the space factory classes, a CLI (Command Line Interface) is provided to run a space instance in a separate process.

The <GigaSpaces Root>\bin\gsServer CLI is based on a generic container utility and set by default to run space instances in a separate process. Since it is based on a generic container architecture, it can be easily configured to run several space instances.

In addition to the API and CLI approaches, GigaSpaces provides a grid-based dynamic deployment approach, which enables auto deployment of space instances over the network using a dynamic deployment and management environment called a Service Grid.

The Service Grid allows users to deploy any service, including spaces using easy to use GUI and CLI tools from one central console. The system figures out automatically how many services of that instance should be deployed and where (on which machines). It can also determine during runtime whether or not a new space instance should be allocated, based on capacity, CPU, and memory load criteria.
For more information about the dynamic deployment section, see the Service Grid chapter.

Running Embedded Transient Instance

JavaSpaces API:
To start a space instance within your application using the JavaSpaces API, use the following lines of code:

import net.jini.space.*;
import com.j_spaces.core.client.*;
import net.jini.core.lease.*;
 
 
public class MyEntry implements Entry
{
    public String content;
 
    public MyEntry ()
    {
    }
}
 
public static void main(String[] args)
{
IJSpace space = (IJSpace)SpaceFinder.find("/./mySpace" );
MyEntry entry = new MyEntry();
entry.content = "Hello World";
space.write(entry, null, Lease.FOREVER);
MyEntry template = new MyEntry ();
MyEntry result = (MyEntry)space.read(template, null, Long.MAX_VALUE);
}

The IJSpace interface (com.j_spaces.core.IJSpace; see Javadoc) extends the net.jini.space.JavaSpace interface and allows you to call the write, read, take, notify and all other methods defined as part of the IJSpace interface. The space running within your application can be accessed by other processes. In this case, it will be accessed as a remote space.

Map API
To start a space instance within your application using the Map API, use the following lines of code:

import com.j_spaces.map.*;
 
IMap cache = (IMap)CacheFinder.find("/./myCache");
 
cache.put("key" , "value");
Object value = cache.get("key");
cache.remove("key");

The IMap interface extends the java.util.Map and allows you to call the get, put, remove and all other methods defined as part of the Map interface. The space running within your application can be accessed by other processes. In this case, it will be accessed as a remote space.

Using the CLI

The gsServer CLI allows you to start a space as a separate process. To start the space instance, use the gsServer command line located at <GigaSpaces Root>\bin and pass the space URL as an argument:

gsServer "/./mySpace"

The gsServer instantiates a space instance named "mySpace" using a default schema configuration. The default schema is set to transient space configuration and it is equivalent to using the following full URL string:

"java://localhost:10098/mySpace_container/mySpace?schema=default".
You can use "." as the container name in the space URL. A value of "." as the container name will be translated to a <space name>_container name. In the above example, the container name is explicitly defined as mySpace_container.
When a URL is provided without the protocol (java) and host name (localhost), GigaSpaces treats /./mySpace as java://localhost:10098/mySpace_container/mySpace?schema=default.

Using a Java protocol

You may run a space in embedded mode using a Java protocol. In the URL properties string, you can specify one of three space operations:

create Creates a new space. Sample URL: java://myHost/myContainer/mySpace?create
open Opens an existing space in an embedded mode. This is the default option if you do not specify a query string. Sample URL: java://myHost/myContainer/mySpace?open
destroy Destroys an existing space. Sample URL: java://myHost/myContainer/mySpace?destroy

If you want to run the embedded container in standalone mode, SpaceFinder can initialize the JNDI Registry on the specified port. This means that the container registers on the JNDI Registry and remote clients can access it.

For example: java://myHost:port/myContainer/mySpace, where the myHost:port should be equal to the value defined as part of the <com><j_spaces><core><container><jndi><url> tag in the container configuration file.

Running Embedded Persistent Instance

Running a persistent space is similar to running a transient space. The only difference is with the schema name, which is required to be defined explicitly:

JavaSpace API

IJSpace space = (IJSpace)SpaceFinder.find("/./mySpace?schema=persistent");

Map API:

IMap cache = (IMap)CacheFinder.find("/./myCache?schema=persistent");

CLI:

gsServer "/./mySpace?schema=persistent"

The persistent schema uses, by default, an indexed file as the durable media to store the space data. You can also use any relational database as the durable storage.

To persist large amounts of data with the highest quality of service use an industrial database such as Oracle or DB2.

For more information about persistent space options, see the Database Cache and Persistency Section.

Accessing a Space Instance Remotely

Once a space instance has been created using one of the above methods, it can be accessed by a remote client application using the following URL format:

The following line of code should be placed as part of your application in order to access remote space:
JavaSpace API

IJSpace space = (IJSpace)SpaceFinder.find("jini://*/./mySpace")

Map API:

IMap cache = (IMap)CacheFinder.find("jini://*/./myCache")

The example above looks for a space instance (named "mySpace" with the JavaSpace API and "myCache" using the Map API) running somewhere on the network. The * allows the application to use the first Jini Lookup Service it finds over the network as the directory service - this is done via multicast. The Jini Lookup Service will return a matching space proxy back to the client.

The container name can be ignored if the value of "*" is provided. In this case, the value of the container name is "." which means that it will be treated as <space_name>_container.

Other examples:

JavaSpace API:

IJSpace cache = (IJSpace)SpaceFinder.find("jini://localhost/./myCache");

Map API:

IMap cache = (IMap)CacheFinder.find("jini://localhost/./myCache");

The example above uses the SpaceFinder/CacheFinder to look for a space instance named "myCache" where the Jini Lookup Service is running locally on the same machine as the application.

JavaSpace API:

IJSpace space = (IJSpace)SpaceFinder.find ("rmi://localhost:10098/./mySpace");

Map API:

IMap cache = (IMap)CacheFinder.find("rmi://localhost:10098/./myCache");

The API above looks for a space instance (named "mySpace" with the JavaSpace API and "myCache" with the Map API) using a RMI/JNDI discovery mechanism, where the rmiregistry is running on the same machine as the application. In many cases, the rmiregistry is running embedded within the process running the space. The port to use in this case would be 10098 (the default space RMI registry port).


Wiki Content Tree


Your Feedback Needed!

We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.

Labels

 
(None)