01: /* LocalClientTracker.java
02: */
03:
04: package org.ozoneDB.core;
05:
06: import java.util.WeakHashMap;
07: import java.util.Iterator;
08:
09: import org.ozoneDB.core.DbRemote.DbLocalClient;
10:
11: /**
12: Tracks local database clients. This is necessary for tracking references
13: from these clients into the database.
14: */
15: public class LocalClientTracker {
16:
17: /**
18: The WeakHashMaps where local clients
19: are keys.
20: If the local clients are not referenced by any other object,
21: they will vanish here as well soon or later.
22: */
23: protected WeakHashMap localClients;
24:
25: /**
26: The value for all entries of {@link #localClients}
27: */
28: protected final static Object value = new Object();
29:
30: public LocalClientTracker() {
31: localClients = new WeakHashMap();
32: }
33:
34: /**
35: Adds a client to this local client tracker.
36: */
37: public void addClient(DbLocalClient client) {
38: synchronized (localClients) {
39: localClients.put(client, value);
40: }
41: }
42:
43: /**
44: Starts filtering references to database objects ({@link OzoneProxy}s) which
45: are exported to clients at all client connections.
46: Every reference which is exported will be notified to the given GarbageCollector.
47: Additionally, references which are known to be used by clients are notified to the
48: given GarbageCollector within this call.
49: */
50: public void startFilterDatabaseObjectReferencesExports(
51: GarbageCollector garbageCollector) {
52: synchronized (localClients) {
53: Iterator i = localClients.keySet().iterator();
54:
55: /*
56: What do we if just during iteration a client disappears?
57: Will a ConcurrentModificationException be thrown?
58: If so how do we handle such an Exception?
59: Should we restart the iteration?
60: */
61: while (i.hasNext()) {
62: ((DbLocalClient) i.next()).getProxyObjectGate()
63: .startFilterDatabaseObjectReferencesExports(
64: garbageCollector);
65: }
66: }
67: }
68: }
|