Mercurial > hg > blitz_stable
comparison examples/helloworld/Taker.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package helloworld; | |
2 | |
3 import java.rmi.RMISecurityManager; | |
4 | |
5 import net.jini.space.JavaSpace; | |
6 | |
7 import net.jini.core.entry.Entry; | |
8 | |
9 import net.jini.core.lease.Lease; | |
10 | |
11 /** | |
12 Taker will attempt to take as many entry's as it can find. If any take | |
13 blocks longer than 120 seconds, Taker assumes there are no more Entry's | |
14 and stops. | |
15 */ | |
16 public class Taker { | |
17 | |
18 public void exec() throws Exception { | |
19 // Locate a JavaSpace - we will only find those registered | |
20 // BEFORE we were started up - doing it properly requires | |
21 // ServiceDiscoveryManager - for another time.... | |
22 // | |
23 System.out.println("Looking for JavaSpace"); | |
24 | |
25 Lookup myFinder = new Lookup(JavaSpace.class); | |
26 | |
27 JavaSpace mySpace = (JavaSpace) myFinder.getService(); | |
28 | |
29 System.out.println("Got space - waiting for Entry's"); | |
30 | |
31 // We want to find any TestEntry instance so we don't set the | |
32 // fields which gives us wildcard match | |
33 Entry myTemplate = new TestEntry(); | |
34 | |
35 while (true) { | |
36 Entry myResult = mySpace.take(myTemplate, null, 120 * 1000); | |
37 | |
38 if (myResult == null) { | |
39 System.out.println("No more entry's in the last 120 seconds"); | |
40 break; | |
41 } | |
42 | |
43 System.out.println("Took: " + myResult); | |
44 } | |
45 } | |
46 | |
47 public static void main(String args[]) { | |
48 // We must set the RMI security manager to allow downloading of code | |
49 // which, in this case, is the Blitz proxy amongst other things | |
50 // | |
51 try { | |
52 if (System.getSecurityManager() == null) | |
53 System.setSecurityManager(new RMISecurityManager()); | |
54 | |
55 new Taker().exec(); | |
56 } catch (Exception anE) { | |
57 System.err.println("Whoops"); | |
58 anE.printStackTrace(System.err); | |
59 } | |
60 } | |
61 } |