comparison test/org/dancres/blitz/SpaceNotifyTest.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 org.dancres.blitz;
2
3 import java.io.Serializable;
4
5 import java.rmi.MarshalledObject;
6
7 import net.jini.core.entry.Entry;
8
9 import net.jini.core.lease.Lease;
10
11 import net.jini.core.event.RemoteEvent;
12 import net.jini.core.event.RemoteEventListener;
13
14 import org.dancres.blitz.mangler.*;
15
16 public class SpaceNotifyTest {
17 public static void main(String args[]) {
18
19 try {
20 System.out.println("Start space");
21
22 SpaceImpl mySpace = new SpaceImpl(null);
23
24 System.out.println("Prepare entry");
25
26 EntryMangler myMangler = new EntryMangler();
27 TestEntry myEntry = new TestEntry();
28 myEntry.init();
29
30 System.out.println("init'd entry");
31 MangledEntry myPackedEntry = myMangler.mangle(myEntry);
32
33 System.out.println("Do notify");
34 mySpace.notify(myPackedEntry, null, new EventListener(),
35 Lease.FOREVER,
36 new MarshalledObject(new String("Here's a handback")));
37
38 System.out.println("Do write");
39
40 for (int i = 0; i < 3; i++) {
41 mySpace.write(myPackedEntry, null, Lease.FOREVER);
42 }
43
44 try {
45 Thread.sleep(10000);
46 } catch (InterruptedException anIE) {
47 }
48
49 System.out.println("Do stop");
50
51 mySpace.stop();
52
53 } catch (Exception anE) {
54 System.err.println("Got exception :(");
55 anE.printStackTrace(System.err);
56 }
57
58 }
59
60 public static class TestEntry implements Entry {
61 public String rhubarb;
62 public Integer count;
63
64 public TestEntry() {
65 }
66
67 public void init() {
68 rhubarb = "blah";
69 count = new Integer(5);
70 }
71
72 public String toString() {
73 return super.toString() + ", " + rhubarb + ", " + count;
74 }
75 }
76
77 private static class EventListener implements RemoteEventListener,
78 Serializable {
79 public void notify(RemoteEvent anEvent) {
80
81 try {
82 System.out.println("Got event: " + anEvent.getSource() + ", " +
83 anEvent.getID() + ", " +
84 anEvent.getSequenceNumber() + ", " +
85 anEvent.getRegistrationObject().get());
86 } catch (Exception anE) {
87 System.out.println("Got event but couldn't display it");
88 anE.printStackTrace(System.out);
89 }
90 }
91 }
92 }