What is Groovy Remote Control?

Groovy remote control is a library for executing closures defined in one Groovy application to be executed in a different (possible remote) Groovy application.

The current version is 0.2.

What is it good for?

The original driver for developing this library was to assist in functionally testing Grails applications (the plugin for Grails can be found here). Its use there is to allow functional tests to define how test data is to be loaded and any other fixtures/mocks setup inside the application under test which may be remote.

However, it could be used as a kind of remote method invocation mechanism, or just for distributed systems generally.

What does it look like?

Here is an example using the HTTP transport module via the provided HttpHandler implementation for use with the JDK 6 com.sun.net.httpserver package (the http transport module also ships a servlet implementation).

Server Side

import com.sun.net.httpserver.HttpServer
import groovyx.remote.transport.http.RemoteControlHttpHandler
import groovyx.remote.server.Receiver

// the receiver of remote commands
def receiver = new Receiver()

// our handler (specific to the httpserver package)
def handler = new RemoteControlHttpHandler(receiver)

def server = HttpServer.create(new InetSocketAddress(8080), 0)
server.createContext("/groovy-remote-control", handler)
server.start()

Client Side

import groovyx.remote.client.RemoteControl
import groovyx.remote.transport.http.HttpTransport

// defines how to talk to the server
def transport = new HttpTransport("http://localhost:8080/groovy-remote-control")

// our agent for remote execution
def remote = new RemoteControl(transport)

// Do some math on the server
// The return value of the closure is returned to the client
assert remote.exec { 1 + 1 } == 2

// Multiple closures can be executed in a chain, with the result of the previous passed to the next
assert remote.exec({ 1 }, { it + 1 }, { it + 1 }) == 3

This is a basic sample and does not illustrate all of the features. Please see the manual for more examples.

How can I use it?

Please consult the manual for information on how to use this in your application.

How can I get help?

You can get help by asking questions on the Groovy user mailing list.

How is it licensed?

Groovy Remote Control is licensed under the Apache 2 License