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 i
f statement as if it was a local operation (minus the exception handling).