/** * Returns the standard singleton instance of the {@code ConnectionPoolManager}. * If an instance has been obtained with a user-specified {@link Properties} object * then this instance is returned, otherwise an attempt is made to return an * instance using the default properties file ({@code dbpool.properties}). * @return An instance of {@code ConnectionPoolManager} * @throws IOException if there was an problem loading the properties */ public static synchronized ConnectionPoolManager getInstance() throws IOException { Object o = managers.get(PROPERTIES_INSTANCE_KEY); ConnectionPoolManager cpm = (o != null) ? (ConnectionPoolManager)o : null; if (cpm == null || cpm.isReleased()) cpm = getInstance(DEFAULT_PROPERTIES_FILE); return cpm; }
/** * Creates a singleton instance of the {@code ConnectionPoolManager} for the specified * {@link Properties} object. To subsequently use this instance user's should call the * {@link #getInstance()} method. This mechanism is used to provide the maximum * separation between creation and use of this instance to avoid haphazard * changes to any referenced {@code Properties} object that may occur between calls. * (This method can only be used successfully if no default properties * instance exists and is in use at the time of calling.) * @param props {@code Properties} object to use * @throws IllegalStateException if default properties instance already exists and is in use */ public static synchronized void createInstance(Properties props) { // Check for presence of default properties file instance. Object o = managers.get(DEFAULT_PROPERTIES_FILE); ConnectionPoolManager cpm = (o != null) ? (ConnectionPoolManager)o : null; if (cpm != null && !cpm.isReleased()) throw new IllegalStateException("Default properties file instance already exists"); // Create new instance and store reference. cpm = new ConnectionPoolManager(props, props); cpm.instanceKey = PROPERTIES_INSTANCE_KEY; managers.put(cpm.instanceKey, cpm); cpm.fireInstancesChangedEvent(); }
@Override public void run() { if (instance == null) { for (ConnectionPoolManager cpm : getInstances()) { if (!cpm.isReleased()) cpm.release(); } } else { if (!instance.isReleased()) instance.release(); } } }
/** * Returns the singleton instance of the {@code ConnectionPoolManager} for the specified properties file. * @param propsFile filename of the properties file to use (path info should not be specified; available CLASSPATH will be searched for the properties file) * @param enc character-encoding to use for reading properties file * @return instance of {@code ConnectionPoolManager} relating to the specified properties file * @throws IOException if there was an problem loading the properties */ public static synchronized ConnectionPoolManager getInstance(String propsFile, String enc) throws IOException { if (propsFile == null) throw new NullPointerException("Invalid value for propsFile specified: null"); String s = propsFile.startsWith("/") ? propsFile : ("/" + propsFile); Object o = managers.get(s); ConnectionPoolManager cpm = (o != null) ? (ConnectionPoolManager)o : null; if (cpm == null || cpm.isReleased()) { Properties props = loadProperties(s, enc); if (props == null) throw new FileNotFoundException("Unable to find properties file: " + propsFile); cpm = new ConnectionPoolManager(props, propsFile); cpm.instanceKey = s; managers.put(cpm.instanceKey, cpm); cpm.fireInstancesChangedEvent(); } return cpm; }
if (cpm == null || cpm.isReleased())
if (isReleased()) return;