01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tcclient.cache;
06:
07: import java.util.Collection;
08: import java.util.HashSet;
09: import java.util.Set;
10:
11: /**
12: * Accumulate all keys being managed by other nodes participating in this cache during
13: * this global eviction cycle with the goal of discovering what keys <strong>aren't</strong>
14: * managed by any local cache. These are the keys that need to be worked on by the global evictor.
15: * The cycle is "started" by setting the global eviction flag then other nodes will report in as
16: * they do eviction until all nodes have been accounted for.
17: *
18: * Whatever keys aren't in the global key set are assumed to be orphans and are then undergo eviction
19: * by the node assigned as the global evictor.
20: */
21: class GlobalKeySet {
22: // State - all guarded by "this" lock
23: private boolean globalEvictionStarted;
24: private Set keys = new HashSet();
25:
26: synchronized boolean inGlobalEviction() {
27: return this .globalEvictionStarted;
28: }
29:
30: synchronized void addLocalKeySet(Object[] keySet) {
31: if (globalEvictionStarted) {
32: if (keySet != null) {
33: for (int i = 0; i < keySet.length; i++) {
34: keys.add(keySet[i]);
35: }
36: }
37: }
38: }
39:
40: synchronized void globalEvictionStart(Object[] localKeys) {
41: this .keys.clear();
42: globalEvictionStarted = true;
43: addLocalKeySet(localKeys);
44: }
45:
46: synchronized Collection globalEvictionEnd() {
47: globalEvictionStarted = false;
48: Set remoteKeys = new HashSet(keys);
49: this.keys.clear();
50: return remoteKeys;
51: }
52:
53: }
|