Inheritance Support

  Search Here
Searching XAP 6.0 Documentation

                                               

Summary: GigaSpaces provides implicit access to the inheritence capabilities in the JavaSpaces specification.

Read, Take, readIfExists, takeIfExists

If a Read or Take operation is performed using a template which does not have a matching instance in the space, but does have a matching instance for a class that extends the template class, this object is returned. If the matching template object class has multiple classes extending it, there is no guarantee that the same object will be returned each time since the space engine picks up different search paths – sub-classes to use when searching for matching Entries. If the template includes values (non-null values template) and the class-relevant attributes are indexed, the Entry lookup is done via an index list. This speeds up the search. Still, you need to make sure all relevant classes have the relevant attributes indexed.

ReadMultiple, takeMultiple

The ReadMultiple() and takeMultiple() methods have a parameter that specifies maximum Entries to be returned. If an operation is performed using a template which does not have enough matching instances, but does have matching instances for classes that extend the template class, these will be part of the population which the space engine evaluates as candidates for the operation return value. With readMultiple and takeMultiple you might get objects that match the given template class and also objects belonging to classes which extend the template class.

Notify Registration

Notification registration supports inheritance by notifying the client of operations conducted with objects that match the given template and also with objects belonging to classes that extend the given template class.

ExternalEntry

ExternalEntry inheritance is supported via the super-classes attribute. You can construct space classes and specify super-classes to form any class hierarchy, and later generate instances from these types without having the actual Java, C# or C++ classes as part of your application's library path. In this case, you should first specify the super-classes attributes, types and names.

IGSEntry

The IGSEntry is the data structure used with the space plug-in interfaces. When accessing the user object using the space plug-in (space filter, replication filter, CacheLoader or CacheStore) you can get the class's super-classes list.

BasicTypeInfo

This class allows you to get metadata info about a class stored in the space. As part of the class meta-data, you can also get a list of its super-classes.

GSIterator

The GSIterator uses readMultiple, so it covers the template class and its sub-classes when returning the match set back to the client application.

SQLQuery

The SQLQuery supports inheritance. You may query the root class and all its sub-classes as part of the candidate population.

Count

The count operation returns a count of matching Entries of the type of the template and its sub-classes.

The IRemoteJSpaceAdmin.getRuntimeInfo() does not support inheritance, and returns the class instance count without including the sub-classes instance count.

Clear

The clear operation covers the template class and all instances of its matching sub-classes.

RegExQuery

You can query and register for notification for a template class and its sub-classes.

Since the JDBC SELECT statement is based on the readMultiple operation, it supports inheritance – performing SELECT over classes that extend other classes might return a result set that encapsulates data from the queried class and its sub-classes.

Performance Implications

There is no major performance impact when using complex class hierarchy. Still, take into consideration that when performing space operations the returned result can be an object that extends the template object class.

Inheritance can be used for enhancing the application without shutting down the space (this is called schema evolving). For more details, see Schema Evolution.

Indexing

Indexing support class inheritance. You may specify the attributes to be indexed at the base class level. Implementing the public static String[] __getSpaceIndexedFields() method spans also sub-classes.

Example

See below simple example demonstrates the usage of the different JavaSpaces API with 3 classes. A , B and C , where A acting as base class for B and B acting as base class for C. The example writes one instance of Class B and one instance of class C into the space and later using read , take , readMultiple and takeMultiple to locate matching entries using an instance of A class.
With the following example the class A got its a attribute indexed. This will have a indexed for B and C classes.

The Entry Classes:

package test_inheritance;

import net.jini.core.entry.Entry;
public class A implements Entry {
public String a=null;
public A(){};
public A(String a){this.a=a;};

public static String [] __getSpaceIndexedFields ()  {
    String [] indexedFields = {"a"};
    return indexedFields;
  }

}

package test_inheritance;

public class B extends A {
	public B(){};
	public B(String a){this.a=a;};

}

package test_inheritance;

public class C extends B {
public C(){};
public C(String a){this.a=a;};

}

The application:

package test_inheritance;

import net.jini.core.entry.Entry;
import net.jini.core.lease.Lease;
import com.j_spaces.core.IJSpace;
import com.j_spaces.core.IJSpaceContainer;
import com.j_spaces.core.client.FinderException;
import com.j_spaces.core.client.SpaceFinder;
import com.j_spaces.map.CacheFinder;
import com.j_spaces.map.IMap;

public class Main {

	public static void main(String[] args) {
		try {

			IJSpace space = (IJSpace) SpaceFinder.find("jini://*/*/mySpace");
			space.write(new C("a"), null, Lease.FOREVER);
			space.write(new B("b"), null, Lease.FOREVER);
			Entry result = space.take(new A(), null, 0);
			if (result != null)
				System.out.println("Take operation using inheritance OK!");
			else
				System.out.println("Take operation using inheritance NOT OK!");

			space.clean();
			space.write(new C("a"), null, Lease.FOREVER);
			space.write(new B("b"), null, Lease.FOREVER);
			result = space.read(new A(), null, 0);
			if (result != null)
				System.out.println("Read operation using inheritance OK!");
			else
				System.out.println("Read operation using inheritance NOT OK!");

			space.clean();
			space.write(new C("a"), null, Lease.FOREVER);
			space.write(new B("b"), null, Lease.FOREVER);
			Entry results[] = space.takeMultiple(new A(), null, 10);
			if (results.length == 2)
				System.out.println("takeMultiple operation using inheritance OK!");
			else
				System.out.println("takeMultiple operation using inheritance NOT OK!");

			space.clean();
			space.write(new C("a"), null, Lease.FOREVER);
			space.write(new B("b"), null, Lease.FOREVER);
			results = space.readMultiple(new A(), null, 10);
			if (results.length == 2)
				System.out.println("readMultiple operation using inheritance OK!");
			else
				System.out.println("readMultiple operation using inheritance NOT OK!");

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}

The expected output:

Take operation using inheritance OK!
Read operation using inheritance OK!
takeMultiple operation using inheritance OK!
readMultiple operation using inheritance OK!


IMPORTANT: This is an old version of GigaSpaces XAP. Click here for the latest version.
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