Add a method to allow LifecycleManager to free keys (#138) · eclipse-sisu/sisu-project@f7bd80c (original) (raw)
`@@ -12,6 +12,7 @@
`
12
12
``
13
13
`import java.util.ArrayDeque;
`
14
14
`import java.util.Deque;
`
``
15
`+
import java.util.Iterator;
`
15
16
`import java.util.Map;
`
16
17
`import java.util.concurrent.ConcurrentHashMap;
`
17
18
``
`@@ -37,16 +38,19 @@ public final class LifecycleManager
`
37
38
`// Public methods
`
38
39
`// ----------------------------------------------------------------------
`
39
40
``
``
41
`+
@Override
`
40
42
`public boolean manage( final Class<?> clazz )
`
41
43
` {
`
42
44
`return buildLifecycle( clazz );
`
43
45
` }
`
44
46
``
``
47
`+
@Override
`
45
48
`public PropertyBinding manage( final BeanProperty<?> property )
`
46
49
` {
`
47
50
`return null; // no custom property bindings
`
48
51
` }
`
49
52
``
``
53
`+
@Override
`
50
54
`public boolean manage( final Object bean )
`
51
55
` {
`
52
56
`final BeanLifecycle lifecycle = lifecycleFor( bean );
`
`@@ -61,6 +65,7 @@ public boolean manage( final Object bean )
`
61
65
`return true;
`
62
66
` }
`
63
67
``
``
68
`+
@Override
`
64
69
`public boolean unmanage( final Object bean )
`
65
70
` {
`
66
71
`if ( removeStoppable( bean ) )
`
`@@ -70,6 +75,7 @@ public boolean unmanage( final Object bean )
`
70
75
`return true;
`
71
76
` }
`
72
77
``
``
78
`+
@Override
`
73
79
`public boolean unmanage()
`
74
80
` {
`
75
81
`for ( Object bean; ( bean = popStoppable() ) != null; )
`
`@@ -156,4 +162,41 @@ private Object popStoppable()
`
156
162
`return stoppableBeans.pollLast();
`
157
163
` }
`
158
164
` }
`
``
165
+
``
166
`+
/**
`
``
167
`+
- Flush the cache for each key that satisfies the given predicate
`
``
168
`+
*
`
``
169
`+
- @param remove a tester that can decide if this key needs to be flushed or
`
``
170
`+
- not.
`
``
171
`+
- @since TBD
`
``
172
`+
*/
`
``
173
`+
public void flushCacheFor( ClassTester remove )
`
``
174
`+
{
`
``
175
`+
for ( Iterator<Class<?>> iterator = lifecycles.keySet().iterator(); iterator.hasNext(); )
`
``
176
`+
{
`
``
177
`+
if ( remove.shouldFlush( iterator.next() ) )
`
``
178
`+
{
`
``
179
`+
iterator.remove();
`
``
180
`+
}
`
``
181
`+
}
`
``
182
`+
}
`
``
183
+
``
184
`+
/**
`
``
185
`+
- Allows testing if a class should be flushed from the cache
`
``
186
`+
`
``
187
`+
- @since TBD
`
``
188
`+
*/
`
``
189
`+
public static interface ClassTester
`
``
190
`+
{
`
``
191
+
``
192
`+
/**
`
``
193
`+
- Test if class should be flushed
`
``
194
`+
*
`
``
195
`+
- @param clz the class to test
`
``
196
`+
- @return
trueif class must be flushed,false
`
``
197
`+
- otherwise
`
``
198
`+
*/
`
``
199
`+
boolean shouldFlush( Class<?> clz );
`
``
200
+
``
201
`+
}
`
159
202
`}
`