Storing Partition Summary Information

A scenario may occur where computation is done on a partition by partition basis and you wish to save the results, instead of recalculating them each time. This example calculates values per partition and saves it to the current partition. It will work regardless of the number of partitions that are running in the space. The example uses an Executor Service to make the calcuations on each partition. The ClusterInfo object is used to get information about the partition the service is currently executing in. The results are then saved to a PartitionSummary object.

The following code demonstrates Space Based Remoting, aka Service Executor. A complete example can be found here.

Service Interface

Configure the service interface as follows:

public interface ISummary {
    public void summary();

Service Implementation

The Service Implementation includes the code that is to be run on each partition and saves the summary information. The ClusterInfo object is used to gather the partition information.

package com.samples.remoting;

import javax.annotation.Resource;

import org.openspaces.core.GigaSpace;
import org.openspaces.core.cluster.ClusterInfo;
import org.openspaces.core.cluster.ClusterInfoContext;
import org.openspaces.remoting.RemotingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.samples.model.ISummary;
import com.samples.model.PartitionSummary;

public class SummaryService implements ISummary {

    final Logger logger = LoggerFactory.getLogger(SummaryService.class);
    GigaSpace gigaSpace;
    private ClusterInfo clusterInfo; 
    public void summary() {
        Integer instanceId = clusterInfo.getInstanceId();
        PartitionSummary partitionSummary = new PartitionSummary();
       "instanceId is " + instanceId);
        // ... do calculations ... save to PartitionSummary object



This is how a client might invoke the service:

        SpaceProxyConfigurer spaceProxyConfigurer = new SpaceProxyConfigurer(spaceName);
        gigaSpace = new GigaSpaceConfigurer(spaceProxyConfigurer).gigaSpace();

        iSummary = new ExecutorRemotingProxyConfigurer<ISummary>(gigaSpace, ISummary.class).broadcast(true).proxy();