Mercurial > hg > blitz_condensed
comparison test/org/dancres/blitz/LeaseTest.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 import java.rmi.MarshalledObject; | |
5 | |
6 import net.jini.core.entry.Entry; | |
7 import net.jini.core.lease.Lease; | |
8 | |
9 import net.jini.core.event.RemoteEvent; | |
10 import net.jini.core.event.RemoteEventListener; | |
11 | |
12 import net.jini.core.transaction.*; | |
13 import net.jini.core.transaction.server.*; | |
14 | |
15 import org.dancres.blitz.mangler.*; | |
16 | |
17 import org.dancres.blitz.lease.SpaceUID; | |
18 | |
19 import org.dancres.blitz.test.TxnMgr; | |
20 import org.dancres.blitz.test.TxnGatewayImpl; | |
21 | |
22 public class LeaseTest { | |
23 public static void main(String args[]) { | |
24 try { | |
25 System.out.println("Start space"); | |
26 | |
27 SpaceImpl mySpace = new SpaceImpl(new TxnGatewayImpl()); | |
28 | |
29 System.out.println("Prepare entry"); | |
30 | |
31 EntryMangler myMangler = new EntryMangler(); | |
32 TestEntry myEntry = new TestEntry(); | |
33 myEntry.init(); | |
34 | |
35 System.out.println("init'd entry"); | |
36 MangledEntry myPackedEntry = myMangler.mangle(new TestEntry()); | |
37 | |
38 System.out.println("Do write"); | |
39 | |
40 SpaceUID myEntryUID = | |
41 mySpace.write(myPackedEntry, null, 50000).getUID(); | |
42 | |
43 System.out.println("Do notify"); | |
44 | |
45 RegTicket myTicket = | |
46 mySpace.notify(myPackedEntry, null, new EventListener(), | |
47 20000, | |
48 new MarshalledObject(new Integer(12345))); | |
49 | |
50 SpaceUID myNotifyUID = myTicket.getUID(); | |
51 | |
52 System.out.println("Renew entry"); | |
53 mySpace.getLeaseControl().renew(myEntryUID, 500000); | |
54 System.out.println("Renew notify"); | |
55 mySpace.getLeaseControl().renew(myNotifyUID, 500000); | |
56 | |
57 System.out.println("Renew entry"); | |
58 mySpace.getLeaseControl().renew(myEntryUID, Lease.FOREVER); | |
59 System.out.println("Renew notify"); | |
60 mySpace.getLeaseControl().renew(myNotifyUID, Lease.FOREVER); | |
61 | |
62 System.out.println("Cancel entry"); | |
63 mySpace.getLeaseControl().cancel(myEntryUID); | |
64 System.out.println("Cancel notify"); | |
65 mySpace.getLeaseControl().cancel(myNotifyUID); | |
66 | |
67 System.out.println("Txn write renewal"); | |
68 | |
69 TxnMgr myMgr = new TxnMgr(1, mySpace.getTxnControl()); | |
70 | |
71 ServerTransaction myTxn = myMgr.newTxn(); | |
72 | |
73 myEntryUID = mySpace.write(myPackedEntry, myTxn, 50000).getUID(); | |
74 | |
75 mySpace.getLeaseControl().renew(myEntryUID, 500000); | |
76 | |
77 myTxn.commit(); | |
78 | |
79 System.out.println("Settling"); | |
80 | |
81 try { | |
82 Thread.sleep(5000); | |
83 } catch (InterruptedException anIE) { | |
84 } | |
85 | |
86 System.out.println("Do stop"); | |
87 | |
88 mySpace.stop(); | |
89 | |
90 } catch (Exception anE) { | |
91 System.err.println("Got exception :("); | |
92 anE.printStackTrace(System.err); | |
93 } | |
94 } | |
95 | |
96 public static class TestEntry implements Entry { | |
97 public String rhubarb; | |
98 public Integer count; | |
99 | |
100 public TestEntry() { | |
101 } | |
102 | |
103 public void init() { | |
104 rhubarb = "blah"; | |
105 count = new Integer(5); | |
106 } | |
107 | |
108 public String toString() { | |
109 return super.toString() + ", " + rhubarb + ", " + count; | |
110 } | |
111 } | |
112 | |
113 private static class EventListener implements RemoteEventListener, | |
114 Serializable { | |
115 public void notify(RemoteEvent anEvent) { | |
116 | |
117 try { | |
118 System.out.println("Got event: " + anEvent.getSource() + ", " + | |
119 anEvent.getID() + ", " + | |
120 anEvent.getSequenceNumber() + ", " + | |
121 anEvent.getRegistrationObject().get()); | |
122 } catch (Exception anE) { | |
123 System.out.println("Got event but couldn't display it"); | |
124 anE.printStackTrace(System.out); | |
125 } | |
126 } | |
127 } | |
128 } |