KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javolution > realtime > HeapContext


1 /*
2  * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
3  * Copyright (C) 2005 - Javolution (http://javolution.org/)
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software is
7  * freely granted, provided that this notice is preserved.
8  */

9 package javolution.realtime;
10
11 /**
12  * <p> This class represents a heap context; it is used to allocate objects
13  * from the heap exclusively.</p>
14  *
15  * @author <a HREF="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
16  * @version 1.0, October 4, 2004
17  */

18 public final class HeapContext extends Context {
19
20     /**
21      * Default constructor.
22      */

23     HeapContext() {
24     }
25
26     /**
27      * Enters a {@link HeapContext}.
28      */

29     public static void enter() {
30         HeapContext ctx = (HeapContext) push(HEAP_CONTEXT_CLASS);
31         if (ctx == null) {
32             ctx = new HeapContext();
33             push(ctx);
34         }
35         PoolContext outer = ctx.getOuter().poolContext();
36         if (outer != null) {
37             outer.setInUsePoolsLocal(false);
38         }
39     }
40     private static final Class HEAP_CONTEXT_CLASS = new HeapContext().getClass();
41
42     /**
43      * Exits the current {@link HeapContext}.
44      *
45      * @throws ClassCastException if the current context is not a heap context.
46      * @throws UnsupportedOperationException if the current context is the root
47      * context.
48      */

49     public static void exit() {
50         HeapContext ctx = (HeapContext) pop();
51         PoolContext outer = ctx.getOuter().poolContext();
52         if (outer != null) {
53             outer.setInUsePoolsLocal(true);
54         }
55     }
56
57     // Implements abstract method.
58
protected void dispose() {
59         // No resource allocated.
60
}
61 }
Popular Tags