KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > runtime > TCRuntime


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.runtime;
5
6 import com.tc.util.Assert;
7 import com.tc.util.runtime.Vm;
8
9 import java.lang.reflect.Constructor JavaDoc;
10
11 public class TCRuntime {
12
13   private static JVMMemoryManager memoryManager;
14
15   static {
16     init();
17   }
18
19   public static final JVMMemoryManager getJVMMemoryManager() {
20     Assert.assertNotNull(memoryManager);
21     return memoryManager;
22   }
23
24   private static void init() {
25     if (Vm.isJDK15Compliant()) {
26       memoryManager = getMemoryManagerJdk15();
27     } else {
28       memoryManager = new TCMemoryManagerJdk14();
29     }
30   }
31
32   /*
33    * XXX::This method is intensionally written using Reflection so that we dont have any 1.5 dependences.
34    * TODO:: Figure a better way to do this.
35    */

36   private static JVMMemoryManager getMemoryManagerJdk15() {
37     try {
38       Class JavaDoc c = Class.forName("com.tc.runtime.TCMemoryManagerJdk15");
39       Constructor JavaDoc constructor = c.getConstructor(new Class JavaDoc[0]);
40       return (JVMMemoryManager) constructor.newInstance(new Object JavaDoc[0]);
41     } catch (Exception JavaDoc e) {
42       throw new AssertionError JavaDoc(e);
43     }
44   }
45
46 }
47
Popular Tags