Very cool Scala code snippet from GridGain…

I just came across this very cool Scala code snippet from GridGain’s Visor (part of the Enterprise Edition that allows for advanced scriptable monitoring of GridGain installations). Visor is entirely written Scala and use Scalar – our distributed programming DSL.

This particular code snipped (actual screenshot) deals with restarting the remote node. Take a look:

What it essentially does is to check if we are to restart the node (reference to which we obtained above), check if reference is null and then ensure that remote node indeed supports remote restarting… And that’s the kicker – take a look how this check is performed!

Basically, this expression node #< grid.isRestartEnabled executes closure grid.isRestartEnabled on the remote target node and returns boolean (on whether the restart is enabled on that node).

As with anything else in GridGain:

  • there’s nothing to compile, build or deploy,
  • nothing to manually marshall or demarshal,
  • no need to care about versioning,
  • or failover, or class loading,
  • or anything else for that matter.

You just use distributed closure execution right in the if statement as if it was a local operation (minus the exception handling).

Pretty cool!

Simple extension for Scala Tuples.

I’ve found this trivial extension for Scala tuples to be often very handy:

implicit def toTuple2x[T1, T2](t: Tuple2[T1, T2]) = new {
    def isSome = t._1 != null || t._2 != null
    def isNone = !isSome
    def isAll = t._1 != null && t._2 != null
    def opt1 = Option(t._1)
    def opt2 = Option(t._2)

We have it for Pairs and Triples and it makes it for a bit cleaner and more expressive tuple handling.


Cleaning up “Multiple Returns” in Scala

Here’s a little titbit from GridGain’s Scalar DSL code:

Not frequently – but often enough – we have the following code in Scala:

def func() {
    if (this) {
    if (that) {

You get the picture… It’s not kosher to put the code like that into Scala compiler 🙂 Now, in some cases the algo can be rework to remove multiple returns, but in other cases this simply isn’t possible without unnecessary complicating the code. In other words, trade offs are not worth it.

So, for case where algo can’t be changed we’ve come up with a simple “cleaning” solution in a way of a “pimp” for Unit type using Scala’s scala.util.control.Break support:

implicit def f(v: Unit) = new { def ^^ = break }

Once you have that “pimp” in the scope you can rewrite previous example like this:

def func() = breakable {
    if (this) doThat() ^^
    if (that) doThis() ^^        

Few comments:

  • Operator ^^ has a nice visual connotation of exiting the function and code gets shorter which never hurts.
  • ^^ is also unique enough so that unlikely naming conflicts won’t confuse the compiler.
  • It enables user-defined scopes while simple return always defaults to the scope of the entire method.

This is, of course, more of a “’cause I can” type of the solution but nonetheless represents great flexibility of the Scala language.


GigaSpaces “borrows” marketing idea from… GridGain.

Here’s what happened.

About three weeks ago we’ve released the video called "Have You Ever Wondered?" that explains what GridGain is. It’s available on our YouTube Channel.

We worked very hard on it, hired a company that helped us to produce the video and hone the message. We blogged about it (look below in this blog), twit it, etc. We came up with what we believe is a very effective headline that helps non-technical person to understand what GridGain is all about. Our video starts with this headline:

Have you ever wondered how companies like Amazon, EBay and Google manage to build their software systems that seamlessly scale up on demand to thousands of computers?

Now, here comes the GigaSpaces, the company that competes with us. We’ve had pretty healthy battle over past several years for various customers and with the release of GridGain 3.0 last year we’ve actually started winning more. Be it as it may, about a week ago (just two weeks after we released our video), GigaSpaces sent out their newsletter with the following headline in it:

Have you ever wondered how industry leaders handle their scalability issues?

Screenshot of that newsletter is below:

As they say, find the similarities… Now, I understand competition and all. But blatant plagiarism is just not cool.

Not cool at all.