Skip to content

Latest commit

 

History

History
100 lines (57 loc) · 2.49 KB

part1_compute-grid.md

File metadata and controls

100 lines (57 loc) · 2.49 KB

Compute Grid

img

Computations are used to execute arbitrary code in server nodes.

Ignite ensures code is serialized, sent over the network, deserialized and executed in server nodes.

Example

import org.apache.ignite.*;

public class Main {

    public static void main(String[] args) {

        Ignite ignite = Ignition.start();

        ignite.compute().run(() -> System.out.println("Hello World"));
    }
}

This code prints Hello World in one server node only.

Runnable

An IgniteRunnable is executed on a server node without a result being returned.

Complete TODOs in Step1_Runnable to fix all tests in Step1_RunnableTest.

Callable

An IgniteCallable is executed on a server node but returns a result to calling node.

Complete TODOs in Step2_Callable to fix all tests in Step2_CallableTest.

Spot the difference

Can you spot the difference between case 1 and 2 ?

import org.apache.ignite.*;

public class App {

    public static void main(String[] args) {

        Ignite ignite = Ignition.start();

        // Case 1
        String nodeId1 = ignite.compute().call(() -> System.getProperty("node.id"));

        // Case 2
        String nodeId2 = System.getProperty("node.id");
        String nodeId3 = ignite.compute().call(() -> nodeId2);
    }
}

Solution

  • Case 1: value is computed inside the lambda, on the remote server node.
  • Case 2: value is computed outside the lambda, its value is fixed on client node, serialized, sent to server node and returned back to client node.

Cluster Nodes and Groups

ClusterNode class represents a node in the cluster.

ClusterGroup class represents a set of nodes in the cluster.

Node and groups can be used to restrict the set of nodes where an operation is executed. They can be retrieved like this for example:

import org.apache.ignite.*;
import org.apache.ignite.cluster.*;

public class App {

    public static void main(String[] args) {

        Ignite ignite = Ignition.start();

        ClusterNode clusterNode = ignite.cluster().localNode();
        ClusterGroup clusterGroup = ignite.cluster().forNode(clusterNode);

        ignite.compute(clusterGroup).run(() -> System.out.println("Hello local node!"));
    }
}

Complete TODOs in Step3_Cluster to fix all tests in Step3_ClusterTest.

Home | Back | Next