comparison examples/helloworld/Writer.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 import java.util.Random;
12
13 /**
14 Writer puts 5 randomly generated Entry's in the space which should
15 hopefully be found by Taker.
16 */
17 public class Writer {
18
19 public void exec() throws Exception {
20 // Locate a JavaSpace - we will only find those registered
21 // BEFORE we were started up - doing it properly requires
22 // ServiceDiscoveryManager - for examples of lookup (including
23 // the use of SDM) see:
24 // http://www.dancres.org/cottage/service_lookup.html
25 //
26 System.out.println("Looking for JavaSpace");
27
28 Lookup myFinder = new Lookup(JavaSpace.class);
29
30 JavaSpace mySpace = (JavaSpace) myFinder.getService();
31
32 System.out.println("Got space - writing Entry's");
33
34 Random myRNG = new Random();
35
36 for (int i = 0; i < 5; i++) {
37 TestEntry myEntry =
38 new TestEntry(Integer.toString(myRNG.nextInt()));
39
40 mySpace.write(myEntry, null, Lease.FOREVER);
41
42 System.out.println("Wrote: " + myEntry);
43 }
44 }
45
46 public static void main(String args[]) {
47 // We must set the RMI security manager to allow downloading of code
48 // which, in this case, is the Blitz proxy amongst other things
49 //
50 try {
51 if (System.getSecurityManager() == null)
52 System.setSecurityManager(new RMISecurityManager());
53
54 new Writer().exec();
55 } catch (Exception anE) {
56 System.err.println("Whoops");
57 anE.printStackTrace(System.err);
58 }
59 }
60 }