001 package org.hackystat.telemetry.analyzer.configuration; 002 003 /** 004 * Provides a Factory class for generating the single PersistentTelemetryDefinitionManager 005 * and as many non-persistent ones as required. 006 * 007 * @author (Cedric) Qin Zhang 008 */ 009 public class TelemetryDefinitionManagerFactory { 010 011 private static TelemetryDefinitionManager theGlobalInstance; 012 013 /** 014 * Gets the singleton global instance of <code>TelemetryDefinitionManger</code>. 015 * 016 * @return The global instance of <code>TelemetryDefinitionManager</code>. 017 */ 018 public static TelemetryDefinitionManager getGlobalPersistentInstance() { 019 // The null situation should only occur during testing. 020 if (theGlobalInstance == null) { //NOPMD because this only happens during testing. 021 theGlobalInstance = new PersistentTelemetryDefinitionManager(null); 022 } 023 return theGlobalInstance; 024 } 025 026 /** 027 * Creates the singleton persistent instance, using the passed defDir to find telemetry 028 * definitions. Note that this must be called when the Restlet server is being created and 029 * thus in advance of any calls to getGlobalPersistentInstance. 030 * @param defDir A string indicating the directory where telemetry definitions (in addition to 031 * the "builtin" definitions) will be found. 032 */ 033 public static void buildGlobalPersistentInstance(String defDir) { 034 theGlobalInstance = new PersistentTelemetryDefinitionManager(defDir); 035 } 036 037 /** 038 * Creates a new non-persistent version of 039 * <code>TelemetryDefinitionManager</code> instance. Note that the returned 040 * instance merges its name space with the name space in the global instance. 041 * This means that if a definition name is used in the global instance, it 042 * cannot be used in the returned instance. 043 * 044 * @param linkToGlobalSingleton True if the definitions in global singleton telemetry manager 045 * should be merged to this instance. 046 * 047 * @return A non-persistent version of <code>TelemetryDefinitionManager</code> 048 * instance. 049 */ 050 public static TelemetryDefinitionManager createNonPersistentInstance( 051 boolean linkToGlobalSingleton) { 052 return new NonPersistentTelemetryDefinitionManager(linkToGlobalSingleton); 053 } 054 }