01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.runtime;
05:
06: import com.tc.properties.TCProperties;
07: import com.tc.properties.TCPropertiesImpl;
08: import com.tc.util.Assert;
09: import com.tc.util.runtime.Vm;
10:
11: import java.lang.reflect.Constructor;
12:
13: public class TCRuntime {
14:
15: private static JVMMemoryManager memoryManager;
16:
17: static {
18: init();
19: }
20:
21: public static final JVMMemoryManager getJVMMemoryManager() {
22: Assert.assertNotNull(memoryManager);
23: return memoryManager;
24: }
25:
26: private static void init() {
27: TCProperties props = TCPropertiesImpl.getProperties();
28:
29: if (Vm.isJDK15Compliant()) {
30: if (props.getBoolean("memory.monitor.forcebasic")) {
31: memoryManager = getMemoryManagerJdk15Basic();
32: } else {
33: memoryManager = getMemoryManagerJdk15PoolMonitor();
34: }
35: } else {
36: memoryManager = new TCMemoryManagerJdk14();
37: }
38: }
39:
40: private static JVMMemoryManager getMemoryManagerJdk15PoolMonitor() {
41: return getMemoryManagerJdk15("com.tc.runtime.TCMemoryManagerJdk15PoolMonitor");
42: }
43:
44: private static JVMMemoryManager getMemoryManagerJdk15Basic() {
45: return getMemoryManagerJdk15("com.tc.runtime.TCMemoryManagerJdk15Basic");
46: }
47:
48: /*
49: * XXX::This method is intentionally written using Reflection so that we dont have any 1.5 dependences.
50: * TODO:: Figure a better way to do this.
51: */
52: private static JVMMemoryManager getMemoryManagerJdk15(
53: String className) {
54: try {
55: Class c = Class.forName(className);
56: Constructor constructor = c.getConstructor(new Class[0]);
57: return (JVMMemoryManager) constructor
58: .newInstance(new Object[0]);
59: } catch (Exception e) {
60: throw new AssertionError(e);
61: }
62: }
63: }
|