/* LocalClientTracker.java
*/
package org.ozoneDB.core;
import java.util.WeakHashMap;
import java.util.Iterator;
import org.ozoneDB.core.DbRemote.DbLocalClient;
/**
Tracks local database clients. This is necessary for tracking references
from these clients into the database.
*/
public class LocalClientTracker {
/**
The WeakHashMaps where local clients
are keys.
If the local clients are not referenced by any other object,
they will vanish here as well soon or later.
*/
protected WeakHashMap localClients;
/**
The value for all entries of {@link #localClients}
*/
protected final static Object value = new Object();
public LocalClientTracker() {
localClients = new WeakHashMap();
}
/**
Adds a client to this local client tracker.
*/
public void addClient(DbLocalClient client) {
synchronized (localClients) {
localClients.put(client,value);
}
}
/**
Starts filtering references to database objects ({@link OzoneProxy}s) which
are exported to clients at all client connections.
Every reference which is exported will be notified to the given GarbageCollector.
Additionally, references which are known to be used by clients are notified to the
given GarbageCollector within this call.
*/
public void startFilterDatabaseObjectReferencesExports(GarbageCollector garbageCollector) {
synchronized (localClients) {
Iterator i = localClients.keySet().iterator();
/*
What do we if just during iteration a client disappears?
Will a ConcurrentModificationException be thrown?
If so how do we handle such an Exception?
Should we restart the iteration?
*/
while (i.hasNext()) {
((DbLocalClient) i.next()).getProxyObjectGate().startFilterDatabaseObjectReferencesExports(garbageCollector);
}
}
}
}