Free Download v4.5

Products


Java, Scala, and Groovy

GridGain is the industry first JVM-based distributed platform for Real Time Big Data processing that provides native support for all three major JVM languages:

  • Java 6
  • Scala 2.9
  • Groovy 1.8 and Groovy++

While GridGain is written natively in Java and Scala it provides two Domain Specific Languages (DSL):

  • Scalar - Scala-based DSL for GridGain
  • Grover - Groovy++ based DSL for GridGain

Consider the following three examples of the same application calculating Pi number in the distributed context written in Java, Scala and Groovy (full source code that works identically on one local node or on thousands of nodes in the cloud):

Using GridGain Functional Java APIs:

public final class GridPiCalculationExample {
    private static final int N = 1000;

    private static double calcPi(int start) {
        double acc = 0.0;

        for (int i = start; i < start + N; i++)
            acc += 4.0 * (1 - (i % 2) * 2) / (2 * i + 1);

        return acc;
    }

    public static void main(String[] args) throws GridException {
        G.start();

        Grid g = G.grid();

        try {
            System.out.println("Pi estimate: " +
                g.reduce(
                    SPREAD,
                    F.yield(F.range(0, g.size()),
                        new C1<Integer, Double>() {
                            @Override public Double apply(Integer i) {
                                return calcPi(i * N);
                            }
                        }
                    ),
                    F.sumDoubleReducer()
                )
            );
        }
        finally {
            G.stop(true);
        }
    }
}

Using Scalar – Scala-based DSL for GridGain:

object ScalarPiCalculationExample {
    private val N = 10000

    def main(args: Array[String]) = scalar { g: Grid =>
        println("Pi estimate: " +
            g @<[Double, Double] (
                    SPREAD,
                    for (i >- 0 until g.size())
                        yield () => calcPi(i * N),
                    _.sum
            )
        )
    }

    def calcPi(start: Int): Double =
        (start until (start + N)) map (i =>
               4.0 * (1 - (i % 2) * 2) / (2 * i + 1)) sum
}

Using Grover – Groovy++ based DSL for GridGain 3.0:

@Typed
@Use(GroverProjectionCategory)
class GroverPiCalculationExample {
    private static int N = 10000

    static void main(String[] args) {
        grover { Grid g ->
            println("Pi estimate: " +
                g.reduce$(
                    SPREAD,
                    (0..< g.size()).collect { { -> calcPi(it * N) } },
                    { it.sum() }
                )
            )
        }
    }

    private static double calcPi(int start) {
        (start..<(start + N)).inject(0) { double sum, int i ->
            sum + (4.0 * (1 - (i % 2) * 2) / (2 * i + 1))
        }
    }
}

First of all, notice how similar all three examples are yet they are written in a native APIs of the host language. Notice also that all three example use FP-based approach to solving a Pi calculation problem – even with Java.

Functional APIs (additionally to OOP and AOP-based) enable developers to dramatically simplify many distributed operations – yet gain in readability and expressiveness of their business logic build on top of GridGain.

Another important point is that distribution logic is brought onto language level in Java and even more so in Scala and Groovy. In Java, closures and typedefs significantly reduce the boilerplate code, and in Scala and Groovy the distributed operations brought completely on an operator syntax level via internal DSLs making complex distributed cloud operations no different syntactically or semantically from the standard Scala of Groovy code.

More Information