On Nov 14, 2008, at 14.02h, Sripriya G wrote:
>
> I have a producer-consumer pattern;
> A main site(process) does boot-strapping which creates 2 channels
> which reside on its site, one for the data for consumption and the
> other for results to be posted to. Both these channels are meant to
> serve as some form of a blackboard, i.e., a place where other agents
> can read data from or post data to.
>
> Then depending on other parameters, a specified number of agents
> should be remotely invoked to read data off the channel-1, process it
> and post results to channel-2
>
> Regarding the tickets bit:
> I pack the structure that has a channel & its associated operations
> and offer it; Then i pickle the ticket and put it in a
> specific(hardwired) location.
>
> These pickles get picked up by the worker-agent and they are unpickled
> to get the ticket; and then using a take operation, access to the
> channel is established.
>
If you invoke the agents from the main process using Remote.run, then
you don't need any tickets at all. Simply pass the respective
channels as part of the component.
For example:
val ch1 = Channel.channel ()
val ch2 = Channel.channel ()
val ch1get = proxy (fn () => Channel.get ch1)
val ch2put = proxy (fn x => Channel.put (ch2, x))
val agent =
comp
import structure Remote ...
in
val doJob : unit -> unit
with
fun doJob' () = (ch2put (ch1get ()); doJob' ()) (*) ping
val doJob = proxy doJob'
end
structure Agent = unpack Remote.run (host, agent) : (val doJob : unit
-> unit)
do Agent.doJob ()
do Channel.put (ch1, "Hello world!\n")
do print (Channel.get ch2)
Note how this makes use of the fact that agent is a "computed"
component that can capture dynamic data (here, proxies for the
channels to the manager) in its closure.
In fact, if you want to run the job on the remote site immediately
anyway, you don't even need to export the doJob function, just start
it in the component body:
...
val agent =
comp
with
fun doJob () = ...
do doJob ()
end
do Remote.run (host, agent)
...
> Here is a code-fragment:
> ======================
> val myAgentComp =
> comp
> import structure Remote:REMOTE from "x-alice:/lib/
> distribution/Remote"
> in
> val doJob : unit -> string
> with
> fun doJob1 () = "hello"
> val doJob = Remote.proxy doJob1
> end
>
> val host1 = "hefty"
> val s = spawn
> let
> structure s1 = unpack Remote.run (host1,myAgentComp) : (val doJob :
> unit -> string)
> in
> s1.doJob()
> end
> ======================
>
> This code fails with exception Remote(_val)
>
> Here is what it says:
> s;
> val it : string = _failed{|Remote (_val)|}
>
Mh. Can you unwrap the Remote constructor to see what cause exception
it carries?
>> Note that myAgentComp creates a proxy each time it's run on a remote
>> site. For that it has to import the Remote module on the respective
>> site. The component contains the full code of doJob (which has to be
>>
>
> This is what the import announcement does, isn't it?
>
Yes, exactly.
Best,
- Andreas
_______________________________________________
alice-users mailing list
[email protected]
http://www.ps.uni-sb.de/mailman/listinfo/alice-users