1 13 package mondrian.util; 14 15 import org.eigenbase.util.property.StringProperty; 16 import mondrian.olap.MondrianProperties; 17 import mondrian.olap.Util; 18 19 43 public final class MemoryMonitorFactory 44 extends ObjectFactory.Singleton<MemoryMonitor> { 45 46 49 private static final MemoryMonitorFactory factory; 50 static { 51 factory = new MemoryMonitorFactory(); 52 } 53 54 59 public static MemoryMonitor getMemoryMonitor() { 60 return factory.getObject(); 61 } 62 63 67 private static final ThreadLocal <String > ClassName = 68 new ThreadLocal <String >(); 69 70 76 private static String getThreadLocalClassName() { 77 return ClassName.get(); 78 } 79 80 89 public static void setThreadLocalClassName(String className) { 90 ClassName.set(className); 91 } 92 93 99 public static void clearThreadLocalClassName() { 100 ClassName.set(null); 101 if (factory.testSingleInstance != null) { 102 factory.testSingleInstance.removeAllListener(); 103 factory.testSingleInstance = null; 104 } 105 if (factory.singleInstance instanceof MemoryMonitor.Test) { 106 ((MemoryMonitor.Test) factory.singleInstance).resetFromTest(); 107 } 108 } 109 110 115 private MemoryMonitorFactory() { 116 super(MemoryMonitor.class); 117 } 118 119 124 protected boolean enabled() { 125 return MondrianProperties.instance().MemoryMonitor.get(); 126 } 127 128 133 protected String getClassName() { 134 return getThreadLocalClassName(); 135 } 136 137 142 protected StringProperty getStringProperty() { 143 return MondrianProperties.instance().MemoryMonitorClass; 144 } 145 146 162 protected MemoryMonitor getDefault(Class [] parameterTypes, 163 Object [] parameterValues) 164 throws CreationException { 165 return (! enabled() || Util.PreJdk15) 166 ? new FauxMemoryMonitor() 168 : new NotificationMemoryMonitor(); 170 } 171 172 } 173 174 | Popular Tags |