Download KLAVA: a Java package for distributed and mobile applications
Transcript
01: public class EvalProcessAtRemote {
02: public static void main(String[] args) throws IMCException, KlavaException {
03:
PhysicalLocality serverLoc = new PhysicalLocality("tcp-127.0.0.1:9999");
04:
KlavaNode serverNode = new Net (serverLoc);
05:
06:
/* insert a tuple in the server node */
07:
Tuple tuple = new Tuple(new KString("foo"), new KInteger(10));
08:
serverNode.out (tuple);
09:
10:
/* will automatically log to the server */
11:
KlavaNode clientNode = new ClientNode(serverLoc);
12:
13:
/* retrieve the physical locality of the client */
14:
PhysicalLocality clientLoc = clientNode.getPhysical (KlavaNode.self);
15:
16:
/* the process will be sent to the server by EvalProcess */
17:
InOutProcess inOutProcess = new InOutProcess(new Tuple(new KString(), new KInteger()));
18:
inOutProcess.outDestination = clientLoc;
19:
clientNode.addNodeProcess(new EvalProcess(inOutProcess, serverLoc));
20:
21:
/* let’s wait for the response at the client */
22:
Tuple result = new Tuple(new KString(), new KInteger());
23:
clientNode.in(result);
24:
25:
System.out.println("result: " + result);
26:
System.exit (0);
27: }
28: }
29:
ClientNode → ClientNode.java:13, page 17
ClientNode → ClientNode.java:20, page 17
ClientNode → ClientNode.java:7, page 17
EvalProcess → EvalProcess.java:7, page 20
InOutProcess → InOutProcess.java:8, page 14
Net → Net.java:12, page 16
Net → Net.java:8, page 16
in → TupleSpace.java:2, page 6
out → TupleSpace.java:4, page 6
outDestination → InOutProcess.java:13, page 14
The output of this examples should be something similar to the following one (since the physical
locality consists of an IP and a fixed port number, the result should be the same each time for the
server, while it might change every time for the client):
klava.examples.process.EvalProcess-4:
eval(klava.examples.process.InOutProcess-3)@tcp-127.0.0.1:9999
klava.examples.process.EvalProcess-4: done
terminated klava.examples.process.EvalProcess-4
Thread-5: performing in( !KString, !KInteger )@self
Thread-5: retrieved ( foo, 10 )
Thread-5: performing out( foo, 10 )@tcp-127.0.0.1:38763
result: ( foo, 10 )
Notice that the InOutProcess, since migrated, did not keep its own name. The tcp-127.0.0.1:38763
is the physical locality of the client, which, as said above, might change each time the program is
executed (since the TCP port is chosen each time by the operating system).
2
Example 2.13 (MigratingProcess). This simple process migrates to a destination, using migrate(), and executes another process once arrived (via executeProcess()). It extends EvalProcess
(Example 2.11) in order to reuse its fields.
01: package klava.examples.process;
02:
03: import klava.KlavaException;
04: import klava.Locality;
21