Creating Invocation Grid Projects

An Invocation Grid project is a project containing all the code and libraries needed to run an Invocation Grid worker process on a cluster of ScaleOut hosts. To do this, create a Java project with your build tool of choice and add the com.scaleoutsoftware.invocationgrid version 1.0 Maven dependency to the project.

Note

This sample in its entirety is available on our GitHub Samples Repo.

Initializing the Worker

Write a startup class that implements the InvocationGridStartup interface to configure event handlers.

package com.scaleout.client.testing;

import com.scaleout.client.GridConnection;
import com.scaleout.client.ighosting.InvocationGridStartup;
import org.apache.logging.log4j.Logger;

public class InvocationGridStartupExample implements InvocationGridStartup {
        @Override
        public void configure(GridConnection connection, Logger logger, byte[] startupParam, String igName) {
                // register for event handlers, add additional loggers, deserialize the startup parameter
                ServiceEvents.setForEachEventHandler(// ...);
    ServiceEvents.setExpirationHandler(// ...);
    ServiceEvents.setPostedEventHandler(// ...);
        }
}

After the startup code is implemented, create a simple main instantiating the InvocationWorker:

package com.scaleout.client.testing;

import com.scaleout.client.GridConnectException;
import com.scaleout.client.ServiceEventsException;
import com.scaleout.client.caching.*;
import com.scaleout.client.ighosting.InvocationWorker;
import com.scaleout.client.ighosting.InvocationWorkerBuilder;

import java.io.IOException;

public class Main {
        public static void main(String[] args) throws GridConnectException, ServiceEventsException, CacheException, IOException {
                InvocationWorker worker = new InvocationWorkerBuilder(new InvocationGridStartupExample()).build();
                worker.waitForEvents();
        }
}

Initializing the Worker with Properties

In some cases, it may be best to configure the invocation grid exclusively through a properties file. All invocation grid parameters can be configured through a properties file.

package com.scaleout.client.testing;

import com.scaleout.client.GridConnectException;
import com.scaleout.client.ServiceEventsException;
import com.scaleout.client.caching.*;
import com.scaleout.client.ighosting.InvocationWorker;
import com.scaleout.client.ighosting.InvocationWorkerBuilder;

import java.io.IOException;

public class MyInvocationGrid {
        public static void main(String[] args) throws GridConnectException, ServiceEventsException, CacheException, IOException {
                Properties igProperties = new Properties();
                try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("/myIgProps.properties")) {
                        igProperties.load(stream);
                }
                InvocationWorker worker = new InvocationWorkerBuilder(igProperties).build();
                worker.waitForEvents();
        }
}

Invocation Worker Properties

All invocation worker properties are optional.

  • ig.connectionstring
    • the format for the value should be a ScaleOut connection string with %s for the server port.

    • For example, to limit the pool size to 16 connections per host, they could use the following value: ig.connectionstring=bootstrapGateways=127.0.0.1:%s;maxPoolSize=16

    • Default value: bootstrapGateways=127.0.0.1:%s

  • ig.startup
    • set to the fully qualified class name (FQCN) of the InvocationGridStartup class implementation.

    • For example, ig.startup=com.mycompany.invocationworker.InvocationWorkerStartupImpl

Invocation Worker Environment Variables

You can optionally set the IG_LOGGING environment variable to programmatic to use default logging. For example:

-DIG_LOGGING=programmatic

Packaging the Invocation Grid

Package the invocation grid by compiling the project and zipping up the build output with all dependent JARs. The ZIP file should not contain additional directories, for example the structure should look like the following:

MyInvocationGrid.zip
        MyInvocationGrid.jar
        MyDependency1.jar
        MyDependency2.jar
        MyDependency3.jar