Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/remote/AdminIteratorImpl.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.remote; | |
2 | |
3 import java.rmi.RemoteException; | |
4 | |
5 import net.jini.core.entry.Entry; | |
6 import net.jini.core.entry.UnusableEntryException; | |
7 | |
8 import com.sun.jini.outrigger.AdminIterator; | |
9 | |
10 import org.dancres.blitz.EntryChit; | |
11 | |
12 import org.dancres.blitz.mangler.EntryMangler; | |
13 | |
14 import org.dancres.blitz.remote.view.EntryViewUID; | |
15 | |
16 public class AdminIteratorImpl implements AdminIterator { | |
17 static final int CHUNK_SIZE = 50; | |
18 | |
19 private EntryViewUID theViewId; | |
20 private AdminServer theStub; | |
21 private EntryMangler theMangler; | |
22 | |
23 private boolean isDone; | |
24 | |
25 private EntryChit[] theCurrentBatch; | |
26 private int theOffset = -1; | |
27 | |
28 private int theChunkSize; | |
29 | |
30 AdminIteratorImpl(EntryMangler aMangler, EntryViewUID aViewId, | |
31 AdminServer aStub) { | |
32 this(aMangler, aViewId, CHUNK_SIZE, aStub); | |
33 } | |
34 | |
35 AdminIteratorImpl(EntryMangler aMangler, EntryViewUID aViewId, | |
36 AdminServer aStub, EntryChit[] anInitialBatch) { | |
37 this(aMangler, aViewId, CHUNK_SIZE, aStub, anInitialBatch); | |
38 } | |
39 | |
40 AdminIteratorImpl(EntryMangler aMangler, EntryViewUID aViewId, | |
41 int aChunkSize, AdminServer aStub) { | |
42 theViewId = aViewId; | |
43 theStub = aStub; | |
44 theMangler = aMangler; | |
45 theChunkSize = aChunkSize; | |
46 } | |
47 | |
48 AdminIteratorImpl(EntryMangler aMangler, EntryViewUID aViewId, | |
49 int aChunkSize, AdminServer aStub, EntryChit[] anInitialBatch) { | |
50 theViewId = aViewId; | |
51 theStub = aStub; | |
52 theMangler = aMangler; | |
53 theChunkSize = aChunkSize; | |
54 | |
55 if (anInitialBatch != null) { | |
56 theCurrentBatch = anInitialBatch; | |
57 theOffset = 0; | |
58 } | |
59 } | |
60 | |
61 public Entry next() throws UnusableEntryException, RemoteException { | |
62 if (isDone) | |
63 return null; | |
64 | |
65 if ((theOffset == -1) || (theOffset >= theCurrentBatch.length)) { | |
66 // Haven't got a batch yet | |
67 theCurrentBatch = theStub.getNext(theViewId, theChunkSize); | |
68 theOffset = 0; | |
69 } | |
70 | |
71 if (theCurrentBatch == null) { | |
72 isDone = true; | |
73 return null; | |
74 } | |
75 | |
76 return theMangler.unMangle(theCurrentBatch[theOffset++].getEntry()); | |
77 } | |
78 | |
79 public void delete() throws RemoteException { | |
80 if (theCurrentBatch != null) | |
81 theStub.delete(theCurrentBatch[theOffset - 1].getCookie()); | |
82 } | |
83 | |
84 public void close() throws RemoteException { | |
85 theStub.close(theViewId); | |
86 } | |
87 } |