Skip to content
Nadeem Mohammad edited this page Oct 11, 2016 · 4 revisions

To distribute the execution of tasks using Hazelcast, you have to use HazelcastExecutionEngine, and follow this steps :

Step 1: Add dexecutor-hazelcast dependency

    <dependency>
     <groupId>com.github.dexecutor</groupId>
     <artifactId>dexecutor-hazelcast</artifactId>
     <version>LATEST_RELEASE</version>
   </dependency>

Step 2 : Start Hazelcast

   Config cfg = new Config();
   HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
   IExecutorService executorService = instance.getExecutorService("test");

Step 3 : Create Dexecutor using Hazelcast

if (isMaster) {
	DefaultDependentTasksExecutor<Integer, Integer> dexecutor = newTaskExecutor(executorService);

	buildGraph(dexecutor);
	dexecutor.execute(ExecutionConfig.TERMINATING);
}

private DefaultDependentTasksExecutor<Integer, Integer> newTaskExecutor(IExecutorService executorService) {
		DependentTasksExecutorConfig<Integer, Integer> config = new DependentTasksExecutorConfig<Integer, Integer>(
				new HazelcastExecutionEngine<Integer, Integer>(executorService), new SleepyTaskProvider());
		return new DefaultDependentTasksExecutor<Integer, Integer>(config);
}

Step 4: Execution

Open three terminals and execute the following :

Terminal #1

 mvn test-compile exec:java -Djava.net.preferIPv4Stack=true -Dexec.mainClass="com.github.dexecutor.hazelcast.Node" -Dexec.classpathScope="test" -Dexec.args="s node-A"

Terminal #2

 mvn test-compile exec:java -Djava.net.preferIPv4Stack=true -Dexec.mainClass="com.github.dexecutor.hazelcast.Node" -Dexec.classpathScope="test" -Dexec.args="s node-B"
Terminal #3
  mvn test-compile exec:java -Djava.net.preferIPv4Stack=true -Dexec.mainClass="com.github.dexecutor.hazelcast.Node"  -Dexec.classpathScope="test" -Dexec.args="m node-C"

Refer this example for more detail.

Refer this blog post for more detail