1 |
| package org.jboss.cache; |
2 |
| |
3 |
| import net.jcip.annotations.ThreadSafe; |
4 |
| import org.apache.commons.logging.Log; |
5 |
| import org.apache.commons.logging.LogFactory; |
6 |
| import org.jboss.cache.buddyreplication.BuddyManager; |
7 |
| import org.jboss.cache.config.ConfigurationException; |
8 |
| import org.jboss.cache.config.EvictionConfig; |
9 |
| import org.jboss.cache.config.EvictionRegionConfig; |
10 |
| import org.jboss.cache.eviction.EvictionTimerTask; |
11 |
| import org.jboss.cache.eviction.RegionNameConflictException; |
12 |
| import org.jboss.cache.lock.NodeLock; |
13 |
| import org.jgroups.Address; |
14 |
| |
15 |
| import java.util.ArrayList; |
16 |
| import java.util.Collections; |
17 |
| import java.util.HashSet; |
18 |
| import java.util.Iterator; |
19 |
| import java.util.List; |
20 |
| import java.util.Map; |
21 |
| import java.util.Set; |
22 |
| import java.util.concurrent.ConcurrentHashMap; |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| @ThreadSafe |
31 |
| public class RegionManager |
32 |
| { |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| public static final Fqn DEFAULT_REGION = new Fqn("_default_"); |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| private Map<Fqn, Region> regionsRegistry = new ConcurrentHashMap<Fqn, Region>(); |
44 |
| private boolean defaultInactive; |
45 |
| private Log log = LogFactory.getLog(RegionManager.class); |
46 |
| private CacheImpl cache; |
47 |
| private boolean usingEvictions; |
48 |
| private EvictionConfig evictionConfig; |
49 |
| private EvictionTimerTask evictionTimerTask = new EvictionTimerTask(); |
50 |
| |
51 |
| protected final Set<Fqn> activationChangeNodes = Collections.synchronizedSet(new HashSet<Fqn>()); |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
61
| public RegionManager()
|
57 |
| { |
58 |
| } |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
2908
| public RegionManager(CacheImpl cache)
|
64 |
| { |
65 |
2908
| this.cache = cache;
|
66 |
| } |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
2480570
| public boolean isUsingEvictions()
|
72 |
| { |
73 |
2480578
| return usingEvictions;
|
74 |
| } |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
1549
| public boolean isDefaultInactive()
|
80 |
| { |
81 |
1549
| return defaultInactive;
|
82 |
| } |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
2840
| public void setDefaultInactive(boolean defaultInactive)
|
88 |
| { |
89 |
2840
| this.defaultInactive = defaultInactive;
|
90 |
| } |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
| |
101 |
0
| public void setContextClassLoaderAsCurrent(Fqn fqn)
|
102 |
| { |
103 |
0
| if (fqn.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN))
|
104 |
| { |
105 |
0
| if (fqn.size() <= 2)
|
106 |
| { |
107 |
0
| fqn = Fqn.ROOT;
|
108 |
| } |
109 |
| else |
110 |
| { |
111 |
0
| fqn = fqn.getSubFqn(2, fqn.size());
|
112 |
| } |
113 |
| } |
114 |
0
| Region region = getRegion(fqn, false);
|
115 |
0
| ClassLoader regionCL = (region == null) ? null : region.getClassLoader();
|
116 |
0
| if (regionCL != null)
|
117 |
| { |
118 |
0
| Thread.currentThread().setContextClassLoader(regionCL);
|
119 |
| } |
120 |
| |
121 |
| } |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
1038795
| public Region getRegion(Fqn fqn, boolean createIfAbsent)
|
128 |
| { |
129 |
1038795
| return getRegion(fqn, Region.Type.ANY, createIfAbsent);
|
130 |
| } |
131 |
| |
132 |
| |
133 |
| |
134 |
| |
135 |
| |
136 |
| |
137 |
| |
138 |
2622279
| public Region getRegion(Fqn fqn, Region.Type type, boolean createIfAbsent)
|
139 |
| { |
140 |
2622279
| Fqn fqnToUse = fqn;
|
141 |
7
| if (DEFAULT_REGION.equals(fqnToUse)) fqnToUse = Fqn.ROOT;
|
142 |
| |
143 |
2622279
| if (regionsRegistry.containsKey(fqnToUse))
|
144 |
| { |
145 |
145764
| Region r = regionsRegistry.get(fqnToUse);
|
146 |
| |
147 |
| |
148 |
| |
149 |
145764
| if (type == Region.Type.ANY
|
150 |
| || (type == Region.Type.MARSHALLING && r.getClassLoader() != null) |
151 |
| || (type == Region.Type.EVICTION && r.getEvictionPolicyConfig() != null)) |
152 |
| { |
153 |
145758
| return r;
|
154 |
| } |
155 |
| } |
156 |
| |
157 |
| |
158 |
2476521
| if (createIfAbsent)
|
159 |
| { |
160 |
1549
| Region r = new RegionImpl(fqnToUse, this);
|
161 |
1549
| regionsRegistry.put(fqnToUse, r);
|
162 |
1549
| if (type == Region.Type.MARSHALLING)
|
163 |
| { |
164 |
| |
165 |
16
| r.registerContextClassLoader(getClass().getClassLoader());
|
166 |
| } |
167 |
1549
| return r;
|
168 |
| } |
169 |
| else |
170 |
| { |
171 |
| |
172 |
| |
173 |
2474972
| if (isUsingEvictions() && !regionsRegistry.containsKey(Fqn.ROOT))
|
174 |
| { |
175 |
1
| throw new RuntimeException("No default eviction region defined!");
|
176 |
| } |
177 |
| } |
178 |
| |
179 |
| |
180 |
2474971
| Region nextBestThing = null;
|
181 |
2474971
| Fqn nextFqn = fqnToUse;
|
182 |
| |
183 |
2474971
| while (nextBestThing == null)
|
184 |
| { |
185 |
7774419
| nextFqn = nextFqn.getParent();
|
186 |
7774419
| if (regionsRegistry.containsKey(nextFqn))
|
187 |
| { |
188 |
2474044
| Region r = regionsRegistry.get(nextFqn);
|
189 |
| |
190 |
| |
191 |
| |
192 |
2474044
| if (type == Region.Type.ANY
|
193 |
| || (type == Region.Type.MARSHALLING && r.getClassLoader() != null) |
194 |
| || (type == Region.Type.EVICTION && r.getEvictionPolicyConfig() != null)) |
195 |
| { |
196 |
2471832
| nextBestThing = r;
|
197 |
| } |
198 |
| } |
199 |
790236
| if (nextFqn.isRoot()) break;
|
200 |
| } |
201 |
| |
202 |
2474971
| return nextBestThing;
|
203 |
| } |
204 |
| |
205 |
| |
206 |
| |
207 |
| |
208 |
| |
209 |
| |
210 |
| |
211 |
| |
212 |
157
| public Region getRegion(String fqn, boolean createIfAbsent)
|
213 |
| { |
214 |
157
| return getRegion(Fqn.fromString(fqn), createIfAbsent);
|
215 |
| } |
216 |
| |
217 |
| |
218 |
| |
219 |
| |
220 |
| |
221 |
| |
222 |
| |
223 |
10
| public boolean removeRegion(Fqn fqn)
|
224 |
| { |
225 |
10
| Region r = regionsRegistry.remove(fqn);
|
226 |
0
| if (r == null) return false;
|
227 |
| |
228 |
10
| if (isUsingEvictions() && r.getEvictionPolicy() != null)
|
229 |
| { |
230 |
0
| evictionTimerTask.removeRegionToProcess(r);
|
231 |
| } |
232 |
10
| return true;
|
233 |
| } |
234 |
| |
235 |
| |
236 |
| |
237 |
| |
238 |
1235
| protected EvictionTimerTask getEvictionTimerTask()
|
239 |
| { |
240 |
1235
| return evictionTimerTask;
|
241 |
| } |
242 |
| |
243 |
| |
244 |
| |
245 |
| |
246 |
| |
247 |
| |
248 |
| |
249 |
| |
250 |
| |
251 |
| |
252 |
| |
253 |
| |
254 |
| |
255 |
| |
256 |
| |
257 |
| |
258 |
217
| public void activate(Fqn fqn) throws RegionNotEmptyException
|
259 |
| { |
260 |
217
| activate(fqn, false);
|
261 |
| } |
262 |
| |
263 |
| |
264 |
| |
265 |
| |
266 |
| |
267 |
| |
268 |
| |
269 |
0
| public void activateIfEmpty(Fqn fqn)
|
270 |
| { |
271 |
0
| activate(fqn, true);
|
272 |
| } |
273 |
| |
274 |
217
| private void activate(Fqn fqn, boolean suppressRegionNotEmptyException)
|
275 |
| { |
276 |
217
| try
|
277 |
| { |
278 |
0
| if (log.isTraceEnabled()) log.trace("Activating region " + fqn);
|
279 |
217
| Region r = getRegion(fqn, false);
|
280 |
217
| if (r != null)
|
281 |
| { |
282 |
208
| if (!defaultInactive && r.getClassLoader() == null)
|
283 |
| { |
284 |
| |
285 |
| |
286 |
| |
287 |
| |
288 |
| |
289 |
4
| removeRegion(fqn);
|
290 |
| } |
291 |
| else |
292 |
| { |
293 |
| |
294 |
204
| r.setActive(true);
|
295 |
| |
296 |
204
| if (cache.getConfiguration().isFetchInMemoryState())
|
297 |
| { |
298 |
203
| activateRegion(r.getFqn(), suppressRegionNotEmptyException);
|
299 |
| } |
300 |
| } |
301 |
| } |
302 |
9
| else if (defaultInactive)
|
303 |
| { |
304 |
| |
305 |
7
| r = getRegion(fqn, true);
|
306 |
7
| r.setActive(true);
|
307 |
| |
308 |
7
| if (cache.getConfiguration().isFetchInMemoryState())
|
309 |
| { |
310 |
2
| activateRegion(r.getFqn(), suppressRegionNotEmptyException);
|
311 |
| } |
312 |
| } |
313 |
| } |
314 |
| catch (RuntimeException re) |
315 |
| { |
316 |
0
| throw re;
|
317 |
| } |
318 |
| catch (Exception e) |
319 |
| { |
320 |
0
| throw new RuntimeException(e);
|
321 |
| } |
322 |
| } |
323 |
| |
324 |
| |
325 |
| |
326 |
| |
327 |
| |
328 |
| |
329 |
| |
330 |
| |
331 |
| |
332 |
| |
333 |
| |
334 |
| |
335 |
| |
336 |
| |
337 |
| |
338 |
| |
339 |
| |
340 |
205
| private void activateRegion(Fqn fqn, boolean suppressRegionNotEmptyException)
|
341 |
| { |
342 |
| |
343 |
205
| Node subtreeRoot = cache.findNode(fqn);
|
344 |
| |
345 |
| |
346 |
| |
347 |
| |
348 |
| |
349 |
| |
350 |
| |
351 |
| |
352 |
| |
353 |
205
| if (isActivatingDeactivating(fqn))
|
354 |
| { |
355 |
0
| throw new CacheException("Region " + subtreeRoot.getFqn() + " is already being activated/deactivated");
|
356 |
| } |
357 |
| |
358 |
205
| if (log.isDebugEnabled())
|
359 |
| { |
360 |
0
| log.debug("activating " + fqn);
|
361 |
| } |
362 |
| |
363 |
205
| try
|
364 |
| { |
365 |
| |
366 |
| |
367 |
| |
368 |
205
| activationChangeNodes.add(fqn);
|
369 |
| |
370 |
205
| Region region = getRegion(fqn, true);
|
371 |
| |
372 |
205
| BuddyManager buddyManager = cache.getBuddyManager();
|
373 |
| |
374 |
205
| if (buddyManager == null)
|
375 |
| { |
376 |
| |
377 |
| |
378 |
195
| if (subtreeRoot == null)
|
379 |
| { |
380 |
| |
381 |
189
| subtreeRoot = cache.createSubtreeRootNode(fqn);
|
382 |
| } |
383 |
| |
384 |
195
| List<Address> members = cache.getMembers();
|
385 |
195
| cache.fetchPartialState(members, subtreeRoot.getFqn());
|
386 |
| } |
387 |
| else |
388 |
| { |
389 |
| |
390 |
| |
391 |
10
| List<Address> buddies = buddyManager.getBuddyAddresses();
|
392 |
10
| for (Address buddy : buddies)
|
393 |
| { |
394 |
8
| List<Address> sources = new ArrayList<Address>(1);
|
395 |
8
| sources.add(buddy);
|
396 |
8
| Fqn base = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, BuddyManager.getGroupNameFromAddress(buddy));
|
397 |
8
| Fqn buddyRoot = new Fqn(base, fqn);
|
398 |
8
| subtreeRoot = cache.findNode(buddyRoot);
|
399 |
8
| if (subtreeRoot == null)
|
400 |
| { |
401 |
| |
402 |
8
| subtreeRoot = cache.createSubtreeRootNode(buddyRoot);
|
403 |
| } |
404 |
8
| cache.fetchPartialState(sources, fqn, subtreeRoot.getFqn());
|
405 |
| } |
406 |
| } |
407 |
| } |
408 |
| catch (Throwable t) |
409 |
| { |
410 |
0
| log.error("failed to activate " + fqn, t);
|
411 |
| |
412 |
| |
413 |
0
| try
|
414 |
| { |
415 |
0
| inactivateRegion(fqn);
|
416 |
| } |
417 |
| catch (Exception e) |
418 |
| { |
419 |
0
| log.error("failed inactivating " + fqn, e);
|
420 |
| |
421 |
| } |
422 |
| |
423 |
| |
424 |
0
| if (t instanceof RegionNotEmptyException)
|
425 |
| { |
426 |
0
| if (!suppressRegionNotEmptyException) throw (RegionNotEmptyException) t;
|
427 |
| } |
428 |
0
| else if (t instanceof CacheException)
|
429 |
| { |
430 |
0
| throw (CacheException) t;
|
431 |
| } |
432 |
| else |
433 |
| { |
434 |
0
| throw new CacheException(t.getClass().getName() + " " +
|
435 |
| t.getLocalizedMessage(), t); |
436 |
| } |
437 |
| } |
438 |
| finally |
439 |
| { |
440 |
201
| activationChangeNodes.remove(fqn);
|
441 |
| } |
442 |
| } |
443 |
| |
444 |
| |
445 |
| |
446 |
| |
447 |
| |
448 |
| |
449 |
| |
450 |
| |
451 |
1067
| public boolean isInactive(Fqn fqn)
|
452 |
| { |
453 |
1067
| Region region = getRegion(fqn, false);
|
454 |
1067
| return region == null ? defaultInactive : !region.isActive();
|
455 |
| } |
456 |
| |
457 |
| |
458 |
| |
459 |
| |
460 |
| |
461 |
| |
462 |
| |
463 |
| |
464 |
| |
465 |
| |
466 |
| |
467 |
| |
468 |
| |
469 |
| |
470 |
| |
471 |
| |
472 |
| |
473 |
| |
474 |
| |
475 |
| |
476 |
11
| private void inactivateRegion(Fqn fqn) throws CacheException
|
477 |
| { |
478 |
11
| if (isActivatingDeactivating(fqn))
|
479 |
| { |
480 |
0
| throw new CacheException("Region " + fqn + " is already being activated/deactivated");
|
481 |
| } |
482 |
| |
483 |
11
| NodeSPI parent = null;
|
484 |
11
| NodeSPI subtreeRoot = null;
|
485 |
11
| boolean parentLocked = false;
|
486 |
11
| boolean subtreeLocked = false;
|
487 |
11
| NodeLock parentLock = null;
|
488 |
11
| NodeLock subtreeLock = null;
|
489 |
| |
490 |
11
| try
|
491 |
| { |
492 |
| |
493 |
11
| activationChangeNodes.add(fqn);
|
494 |
| |
495 |
11
| if (!isInactive(fqn))
|
496 |
| { |
497 |
0
| deactivate(fqn);
|
498 |
| } |
499 |
| |
500 |
| |
501 |
11
| BuddyManager buddyManager = cache.getBuddyManager();
|
502 |
11
| ArrayList<Fqn> list = new ArrayList<Fqn>();
|
503 |
11
| list.add(fqn);
|
504 |
| |
505 |
11
| if (buddyManager != null)
|
506 |
| { |
507 |
2
| Set buddies = cache.getChildrenNames(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
|
508 |
2
| if (buddies != null)
|
509 |
| { |
510 |
2
| for (Iterator it = buddies.iterator(); it.hasNext();)
|
511 |
| { |
512 |
2
| Fqn base = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, it.next());
|
513 |
2
| list.add(new Fqn(base, fqn));
|
514 |
| } |
515 |
| } |
516 |
| } |
517 |
| |
518 |
11
| long stateFetchTimeout = cache.getConfiguration().getLockAcquisitionTimeout() + 5000;
|
519 |
| |
520 |
11
| for (Iterator<Fqn> it = list.iterator(); it.hasNext();)
|
521 |
| { |
522 |
13
| Fqn subtree = it.next();
|
523 |
13
| subtreeRoot = cache.findNode(subtree);
|
524 |
13
| if (subtreeRoot != null)
|
525 |
| { |
526 |
| |
527 |
11
| Object owner = cache.getOwnerForLock();
|
528 |
11
| subtreeLock = subtreeRoot.getLock();
|
529 |
11
| subtreeLock.acquireAll(owner, stateFetchTimeout, NodeLock.LockType.WRITE);
|
530 |
11
| subtreeLocked = true;
|
531 |
| |
532 |
| |
533 |
11
| parent = subtreeRoot.getParent();
|
534 |
11
| if (parent != null)
|
535 |
| { |
536 |
9
| parentLock = parent.getLock();
|
537 |
9
| parentLock.acquire(owner, stateFetchTimeout, NodeLock.LockType.WRITE);
|
538 |
9
| parentLocked = true;
|
539 |
| } |
540 |
| |
541 |
| |
542 |
11
| cache._evictSubtree(subtree);
|
543 |
| |
544 |
| |
545 |
11
| if (parent != null)
|
546 |
| { |
547 |
9
| log.debug("forcing release of locks in parent");
|
548 |
9
| parentLock.releaseAll();
|
549 |
| } |
550 |
| |
551 |
11
| parentLocked = false;
|
552 |
| |
553 |
11
| log.debug("forcing release of all locks in subtree");
|
554 |
11
| subtreeLock.releaseAll();
|
555 |
11
| subtreeLocked = false;
|
556 |
| } |
557 |
| } |
558 |
| } |
559 |
| catch (InterruptedException ie) |
560 |
| { |
561 |
0
| throw new CacheException("Interrupted while acquiring lock", ie);
|
562 |
| } |
563 |
| finally |
564 |
| { |
565 |
| |
566 |
| |
567 |
| |
568 |
| |
569 |
| |
570 |
| |
571 |
11
| if (parentLocked)
|
572 |
| { |
573 |
0
| log.debug("forcing release of locks in parent");
|
574 |
0
| try
|
575 |
| { |
576 |
0
| parentLock.releaseAll();
|
577 |
| } |
578 |
| catch (Throwable t) |
579 |
| { |
580 |
0
| log.error("failed releasing locks", t);
|
581 |
| } |
582 |
| } |
583 |
11
| if (subtreeLocked)
|
584 |
| { |
585 |
0
| log.debug("forcing release of all locks in subtree");
|
586 |
0
| try
|
587 |
| { |
588 |
0
| subtreeLock.releaseAll();
|
589 |
| } |
590 |
| catch (Throwable t) |
591 |
| { |
592 |
0
| log.error("failed releasing locks", t);
|
593 |
| } |
594 |
| } |
595 |
| |
596 |
11
| activationChangeNodes.remove(fqn);
|
597 |
| } |
598 |
| } |
599 |
| |
600 |
| |
601 |
| |
602 |
| |
603 |
| |
604 |
| |
605 |
| |
606 |
| |
607 |
| |
608 |
| |
609 |
216
| private boolean isActivatingDeactivating(Fqn fqn)
|
610 |
| { |
611 |
216
| return activationChangeNodes.contains(fqn);
|
612 |
| } |
613 |
| |
614 |
| |
615 |
| |
616 |
| |
617 |
| |
618 |
| |
619 |
| |
620 |
| |
621 |
1
| public boolean hasRegion(Fqn fqn, Region.Type type)
|
622 |
| { |
623 |
1
| Region r = regionsRegistry.get(fqn);
|
624 |
0
| if (r == null) return false;
|
625 |
1
| switch (type)
|
626 |
| { |
627 |
0
| case ANY:
|
628 |
0
| return true;
|
629 |
0
| case EVICTION:
|
630 |
0
| return r.getEvictionPolicy() != null && evictionTimerTask.isRegionRegisteredForProcessing(r);
|
631 |
1
| case MARSHALLING:
|
632 |
1
| return r.isActive() && r.getClassLoader() != null;
|
633 |
| } |
634 |
| |
635 |
0
| return false;
|
636 |
| } |
637 |
| |
638 |
| |
639 |
| |
640 |
| |
641 |
| |
642 |
| |
643 |
| |
644 |
23
| public void deactivate(Fqn fqn)
|
645 |
| { |
646 |
23
| try
|
647 |
| { |
648 |
23
| Region region = getRegion(fqn, false);
|
649 |
| |
650 |
23
| if (region != null)
|
651 |
| { |
652 |
14
| if (defaultInactive && region.getClassLoader() == null)
|
653 |
| { |
654 |
| |
655 |
| |
656 |
| |
657 |
| |
658 |
| |
659 |
3
| removeRegion(fqn);
|
660 |
| } |
661 |
| else |
662 |
| { |
663 |
| |
664 |
11
| region.setActive(false);
|
665 |
| |
666 |
| |
667 |
11
| if (cache.getConfiguration().isFetchInMemoryState())
|
668 |
| { |
669 |
11
| inactivateRegion(fqn);
|
670 |
| } |
671 |
| } |
672 |
| } |
673 |
9
| else if (!defaultInactive)
|
674 |
| { |
675 |
5
| region = getRegion(fqn, true);
|
676 |
5
| region.setActive(false);
|
677 |
| |
678 |
| |
679 |
5
| if (cache.getConfiguration().isFetchInMemoryState())
|
680 |
| { |
681 |
0
| inactivateRegion(fqn);
|
682 |
| } |
683 |
| } |
684 |
| } |
685 |
| catch (RuntimeException re) |
686 |
| { |
687 |
0
| throw re;
|
688 |
| } |
689 |
| catch (Exception e) |
690 |
| { |
691 |
0
| throw new RuntimeException(e);
|
692 |
| } |
693 |
| } |
694 |
| |
695 |
| |
696 |
| |
697 |
| |
698 |
2
| public void reset()
|
699 |
| { |
700 |
2
| regionsRegistry.clear();
|
701 |
| } |
702 |
| |
703 |
| |
704 |
| |
705 |
| |
706 |
| |
707 |
| |
708 |
| |
709 |
| |
710 |
35
| public List<Region> getAllRegions(Region.Type type)
|
711 |
| { |
712 |
35
| List<Region> regions;
|
713 |
| |
714 |
35
| if (type != Region.Type.ANY)
|
715 |
| { |
716 |
26
| regions = new ArrayList<Region>();
|
717 |
| |
718 |
26
| for (Region r : regionsRegistry.values())
|
719 |
| { |
720 |
63
| if ((type == Region.Type.EVICTION && r.getEvictionPolicy() != null && evictionTimerTask.isRegionRegisteredForProcessing(r)) ||
|
721 |
| (type == Region.Type.MARSHALLING && r.isActive() && r.getClassLoader() != null)) |
722 |
31
| regions.add(r);
|
723 |
| } |
724 |
| } |
725 |
| else |
726 |
| { |
727 |
| |
728 |
9
| regions = new ArrayList<Region>(regionsRegistry.values());
|
729 |
| } |
730 |
| |
731 |
35
| Collections.sort(regions);
|
732 |
| |
733 |
35
| return regions;
|
734 |
| } |
735 |
| |
736 |
| |
737 |
| |
738 |
| |
739 |
2846
| public void setUsingEvictions(boolean usingEvictions)
|
740 |
| { |
741 |
2846
| this.usingEvictions = usingEvictions;
|
742 |
| } |
743 |
| |
744 |
| |
745 |
| |
746 |
| |
747 |
377
| public void setEvictionConfig(EvictionConfig evictionConfig)
|
748 |
| { |
749 |
377
| this.evictionConfig = evictionConfig;
|
750 |
377
| boolean setDefault = false;
|
751 |
| |
752 |
377
| for (EvictionRegionConfig erc : evictionConfig.getEvictionRegionConfigs())
|
753 |
| { |
754 |
1133
| Fqn fqn = erc.getRegionFqn();
|
755 |
0
| if (log.isTraceEnabled()) log.trace("Creating eviction region " + fqn);
|
756 |
| |
757 |
1133
| if (fqn.equals(DEFAULT_REGION))
|
758 |
| { |
759 |
377
| if (setDefault)
|
760 |
| { |
761 |
0
| throw new ConfigurationException("A default region for evictions has already been set for this cache");
|
762 |
| } |
763 |
0
| if (log.isTraceEnabled()) log.trace("Applying settings for " + DEFAULT_REGION + " to Fqn.ROOT");
|
764 |
377
| fqn = Fqn.ROOT;
|
765 |
377
| setDefault = true;
|
766 |
| } |
767 |
1133
| Region r = getRegion(fqn, true);
|
768 |
1133
| r.setEvictionPolicy(erc.getEvictionPolicyConfig());
|
769 |
| } |
770 |
| } |
771 |
| |
772 |
| |
773 |
| |
774 |
| |
775 |
377
| public void startEvictionThread()
|
776 |
| { |
777 |
377
| evictionTimerTask.init(evictionConfig.getWakeupIntervalSeconds());
|
778 |
| } |
779 |
| |
780 |
| |
781 |
| |
782 |
| |
783 |
358
| public void stopEvictionThread()
|
784 |
| { |
785 |
360
| evictionTimerTask.stop();
|
786 |
| } |
787 |
| |
788 |
| |
789 |
| |
790 |
| |
791 |
| |
792 |
1
| public String dumpRegions()
|
793 |
| { |
794 |
1
| StringBuilder sb = new StringBuilder();
|
795 |
1
| for (Region r : regionsRegistry.values())
|
796 |
| { |
797 |
5
| sb.append("\tRegion " + r);
|
798 |
5
| sb.append("\n");
|
799 |
| } |
800 |
1
| return sb.toString();
|
801 |
| } |
802 |
| |
803 |
| |
804 |
| |
805 |
| |
806 |
0
| public String toString()
|
807 |
| { |
808 |
0
| return "RegionManager " + dumpRegions();
|
809 |
| } |
810 |
| |
811 |
| |
812 |
| |
813 |
| |
814 |
1230
| public CacheImpl getCache()
|
815 |
| { |
816 |
1230
| return this.cache;
|
817 |
| } |
818 |
| |
819 |
| } |