1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.river.outrigger.proxy;
19
20 import java.rmi.RemoteException;
21
22 import net.jini.core.entry.Entry;
23 import net.jini.core.entry.UnusableEntryException;
24 import net.jini.core.lease.Lease;
25 import net.jini.id.Uuid;
26 import net.jini.space.MatchSet;
27
28
29
30
31
32
33
34
35
36
37
38
39
40 class MatchSetProxy implements MatchSet {
41
42 final private OutriggerServer space;
43
44
45 final private Uuid uuid;
46
47
48 final private Lease lease;
49
50
51 private volatile EntryRep[] reps;
52
53
54 private volatile EntryRep lastRepReturned;
55
56
57 private volatile int i;
58
59
60 private volatile boolean unpackFailure = true;
61
62 MatchSetProxy(MatchSetData inital, SpaceProxy2 parent, OutriggerServer space) {
63 uuid = inital.uuid;
64 this.space = space;
65 if (uuid != null)
66 lease = parent.newLease(uuid, inital.intialLeaseDuration);
67 else
68 lease = null;
69 reps = inital.reps;
70
71 i=0;
72 }
73
74 public Lease getLease() {
75 return lease;
76 }
77
78 public Entry next() throws RemoteException, UnusableEntryException {
79 if (i >= reps.length) {
80
81 i = 0;
82 reps = space.nextBatch(uuid, lastRepReturned.id());
83 }
84
85 if (reps[i] == null)
86 return null;
87
88 unpackFailure = true;
89 lastRepReturned = reps[i++];
90 final Entry rslt = lastRepReturned.entry();
91 unpackFailure = false;
92 return rslt;
93 }
94
95 public Entry getSnapshot() {
96 if (unpackFailure)
97 throw new IllegalStateException(
98 "getSnapshot - need successful next call first");
99
100 return new SnapshotRep(lastRepReturned);
101 }
102
103 public String toString() {
104 return getClass().getName() + " for " + uuid +
105 " (through " + space + ")";
106 }
107 }