Calling a remote actor with cajo

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling a remote actor with cajo

bgoetzmann
Hello,

After reading the GINA 2 chapter on GPars (thanks for this), I tried to use the cajo project (http://java.net/projects/cajo/pages/Home) to call a GPars actor remotely.

Here, what I would like to share with you, hoping this can give some ideas (it's based on what I wrote sometimes ago, on Groovy and cajo, here: http://www.odelia-technologies.com/node/162).

The server part defines an actor that just echoes the received message :

import static groovyx.gpars.actor.Actors.*
import gnu.cajo.utils.ItemServer
import gnu.cajo.invoke.Remote


def echo = reactor { it }

Remote.config(null, 1198, null, 0)
ItemServer.bind(echo, "unNom")

println 'Server is starting...'

sleep 120000


echo.stop()
echo.join()


The client part:

import gnu.cajo.invoke.Remote

def serverHost = 'localhost' // the host running the remote actor
def test = Remote.getItem("//${serverHost}:1198/unNom")

println test.invoke('sendAndWait', 'Salut !')


When executed, the client invokes the remote actor and prints "Salut !".


We can do the same thing in a more Groovy manner :

import gnu.cajo.invoke.Remote

def serverHost = 'localhost' // Nom de l'hôte (serveur)
def test = Remote.getItem("//${serverHost}:1198/unNom")

test.metaClass.methodMissing = { String name, args ->
        if (args.length == 1)
                args = args[0]
        delegate.invoke(name, args)
}

println test.sendAndWait('Salut !')


Bertrand Goetzmann ;-)
http://www.odelia-technologies.com/
Reply | Threaded
Open this post in threaded view
|

Re: Calling a remote actor with cajo

Vaclav
Administrator
Hello Bertrand,

thanks for the cool demo! I really like it, especially the second, enhanced client.

Cheers,

Vaclav


On Sat, Jun 11, 2011 at 12:25 PM, bgoetzmann <[hidden email]> wrote:
Hello,

After reading the GINA 2 chapter on GPars (thanks for this), I tried to use
the cajo project (http://java.net/projects/cajo/pages/Home) to call a GPars
actor remotely.

Here, what I would like to share with you, hoping this can give some ideas
(it's based on what I wrote sometimes ago, on Groovy and cajo, here:
http://www.odelia-technologies.com/node/162).

The server part defines an actor that just echoes the received message :

import static groovyx.gpars.actor.Actors.*
import gnu.cajo.utils.ItemServer
import gnu.cajo.invoke.Remote


def echo = reactor { it }

Remote.config(null, 1198, null, 0)
ItemServer.bind(echo, "unNom")

println 'Server is starting...'

sleep 120000


echo.stop()
echo.join()


The client part:

import gnu.cajo.invoke.Remote

def serverHost = 'localhost' // the host running the remote actor
def test = Remote.getItem("//${serverHost}:1198/unNom")

println test.invoke('sendAndWait', 'Salut !')


When executed, the client invokes the remote actor and prints "Salut !".


We can do the same thing in a more Groovy manner :

import gnu.cajo.invoke.Remote

def serverHost = 'localhost' // Nom de l'hôte (serveur)
def test = Remote.getItem("//${serverHost}:1198/unNom")

test.metaClass.methodMissing = { String name, args ->
       if (args.length == 1)
               args = args[0]
       delegate.invoke(name, args)
}

println test.sendAndWait('Salut !')


Bertrand Goetzmann ;-)
http://www.odelia-technologies.com/

--
View this message in context: http://gpars-user-mailing-list.19372.n3.nabble.com/Calling-a-remote-actor-with-cajo-tp3052197p3052197.html
Sent from the GPars - user mailing list mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





--
E-mail: [hidden email]
Blog: http://www.jroller.com/vaclav
Linkedin page: http://www.linkedin.com/in/vaclavpech