KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > LocalClientTracker


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: $
8

9 package org.ozoneDB.core;
10
11 import java.util.WeakHashMap JavaDoc;
12
13 import java.util.Iterator JavaDoc;
14
15
16
17 import org.ozoneDB.core.DbRemote.DbLocalClient;
18
19 /**
20     Tracks local database clients. This is necessary for tracking references
21     from these clients into the database.
22 */

23
24 public class LocalClientTracker {
25
26     /**
27         The WeakHashMaps where local clients
28         are keys.
29         If the local clients are not referenced by any other object,
30         they will vanish here as well soon or later.
31     */

32
33     protected WeakHashMap JavaDoc localClients;
34
35     /**
36         The value for all entries of {@link #localClients}
37     */

38     protected final static Object JavaDoc value = new Object JavaDoc();
39
40     public LocalClientTracker() {
41         localClients = new WeakHashMap JavaDoc();
42     }
43
44     /**
45         Adds a client to this local client tracker.
46     */

47     public void addClient(DbLocalClient client) {
48         synchronized (localClients) {
49             localClients.put(client,value);
50         }
51     }
52
53     /**
54         Starts filtering references to database objects ({@link org.ozoneDB.OzoneProxy}s) which
55         are exported to clients at all client connections.
56         Every reference which is exported will be notified to the given GarbageCollector.
57         Additionally, references which are known to be used by clients are notified to the
58         given GarbageCollector within this call.
59     */

60     public void startFilterDatabaseObjectReferencesExports(GarbageCollector garbageCollector) {
61         synchronized (localClients) {
62             Iterator JavaDoc i = localClients.keySet().iterator();
63
64             /*
65                 What do we if just during iteration a client disappears?
66                 Will a ConcurrentModificationException be thrown?
67                 If so how do we handle such an Exception?
68                 Should we restart the iteration?
69             */

70             while (i.hasNext()) {
71                 ((DbLocalClient) i.next()).getProxyObjectGate().startFilterDatabaseObjectReferencesExports(garbageCollector);
72             }
73         }
74     }
75 }
Popular Tags