/** * <b>Note:</b> If multiple PooledDataSources in your JVM share the same <tt>dataSourceName</tt>, * which of those multiple DataSources will be returned by this method is undefined! * * @return a PooledDataSource with the given <tt>dataSourceName</tt>, if at least one exists. * <tt>null</tt> otherwise. */ public static synchronized PooledDataSource pooledDataSourceByName(String dataSourceName) { for (Iterator ii = unclosedPooledDataSources.iterator(); ii.hasNext(); ) { PooledDataSource pds = (PooledDataSource) ii.next(); if (pds.getDataSourceName().equals(dataSourceName)) return pds; } return null; }
private StatusReporter findStatusReporter(PooledDataSource pds, Document doc) { if (pds.getClass() == ComboPooledDataSource.class) return new CpdsStatusReporter((ComboPooledDataSource) pds, doc); else if (pds.getClass() == PoolBackedDataSource.class) return new PbdsStatusReporter((PoolBackedDataSource) pds, doc); else return new UnknownPdsStatusReporter(pds, doc); }
public synchronized int getNumThreadsAllThreadPools() throws SQLException { int count = 0; for (Iterator ii = unclosedPooledDataSources.iterator(); ii.hasNext(); ) { PooledDataSource pds = (PooledDataSource) ii.next(); count += pds.getNumHelperThreads(); } return count; }
/** @return the set of all PooledDataSources sharing the given dataSourceName */ public static synchronized Set pooledDataSourcesByName(String dataSourceName) { Set out = new HashSet(); for (Iterator ii = unclosedPooledDataSources.iterator(); ii.hasNext(); ) { PooledDataSource pds = (PooledDataSource) ii.next(); if (pds.getDataSourceName().equals(dataSourceName)) out.add(pds); } return out; }
public Element reportDtElem() { StringBuffer sb = new StringBuffer(255); sb.append(shortTypeName); sb.append(" [ dataSourceName: "); sb.append(pds.getDataSourceName()); sb.append("; identityToken: "); sb.append(pds.getIdentityToken()); sb.append(" ]"); Element dtElem = doc.createElement("dt"); dtElem.appendChild(doc.createTextNode(sb.toString())); return dtElem; }
private static void destroy(DataSource pooledDataSource, boolean force) throws SQLException { if (pooledDataSource instanceof PoolBackedDataSource) { ConnectionPoolDataSource cpds = ((PoolBackedDataSource) pooledDataSource).getConnectionPoolDataSource(); if (cpds instanceof WrapperConnectionPoolDataSource) destroy(((WrapperConnectionPoolDataSource) cpds).getNestedDataSource(), force); } if (pooledDataSource instanceof PooledDataSource) ((PooledDataSource) pooledDataSource).close(force); }
static String getPdsObjectNameStr(PooledDataSource pds) { String dataSourceName = pds.getDataSourceName(); // if we are excluding the identity token attribute, then we always need a valid name attribute. // hopefully users who set EXCLUDE_IDENTITY_TOKEN will update dataSourceName to a reasonable // value. // in the meantime, we use the identity token value for the name. // // but note that at present, pds.getDataSourceName() returns the identity token when // dataSourceName // is unset or set to null. So, this predicate is unlikely ever to be true. if (dataSourceName == null && EXCLUDE_IDENTITY_TOKEN) dataSourceName = pds.getIdentityToken(); // when EXCLUDE_IDENTITY_TOKEN is false, in practice we nearly always generate a 3-attribute // name (type, identityToken, name), because even when dataSourceName is not set or set to null, // getDataSourceName() returns the identity token rather than null. // // when EXCLUDE_IDENTITY_TOKEN is true, we reliably generate a two-attribute name. StringBuilder sb = new StringBuilder(256); sb.append("com.mchange.v2.c3p0:type=PooledDataSource"); if (!EXCLUDE_IDENTITY_TOKEN) { sb.append(",identityToken="); sb.append(pds.getIdentityToken()); } if (dataSourceName != null) { sb.append(",name="); sb.append(dataSourceName); } return sb.toString(); // String out = "com.mchange.v2.c3p0:type=PooledDataSource,identityToken=" + // pds.getIdentityToken(); // if ( dataSourceName != null ) // out += ",name=" + dataSourceName; // return out; }
public void attemptUnmanagePooledDataSource(PooledDataSource pds) { String nameStr = null; try { nameStr = getPdsObjectNameStr(pds); ObjectName name = new ObjectName(nameStr); if (mbs.isRegistered(name)) { mbs.unregisterMBean(name); if (logger.isLoggable(MLevel.FINE)) logger.log(MLevel.FINE, "MBean: " + nameStr + " unregistered."); } else if (logger.isLoggable(MLevel.FINE)) logger.fine( "The mbean " + nameStr + " was not found in the registry, so could not be unregistered."); } catch (Exception e) { if (logger.isLoggable(MLevel.WARNING)) logger.log( MLevel.WARNING, "An Exception occurred while unregistering mBean. [" + (nameStr == null ? pds.toString() : nameStr) + "] ", e); } }
public void attemptManagePooledDataSource(PooledDataSource pds) { String name = null; try { name = getPdsObjectNameStr(pds); ObjectName oname = new ObjectName(name); if (mbs.isRegistered(oname)) { if (logger.isLoggable(MLevel.WARNING)) logger.warning( "You are attempting to register an mbean '" + name + "', but an mbean by that name is already registered. " + "The new mbean will replace the old one in the MBean server. " + (EXCLUDE_IDENTITY_TOKEN ? "Since you have excluded the guaranteed-unique identity token, you must take care to give each PooledDataSource a unique dataSourceName." : "This should not happen unless you have (pathologically) modified the DataSource's guaranteed-unique identityToken.")); } // PooledDataSourceManager mbean = new PooledDataSourceManager( pds ); // mbs.registerMBean(mbean, ObjectName.getInstance(name)); // if (logger.isLoggable(MLevel.FINER)) // logger.log(MLevel.FINER, "MBean: " + name + " registered."); // DynamicPooledDataSourceManagerMBean registers itself on construction (and logs its own // registration) DynamicPooledDataSourceManagerMBean mbean = new DynamicPooledDataSourceManagerMBean(pds, name, mbs); } catch (Exception e) { if (logger.isLoggable(MLevel.WARNING)) logger.log( MLevel.WARNING, "Failed to set up a PooledDataSourceManager mBean. [ " + (name == null ? pds.toString() : name) + " ] c3p0 will still function normally, but management of this DataSource by JMX may not be possible.", e); } }
UnknownPdsStatusReporter(PooledDataSource pds, Document doc) { this(pds.getClass().getName(), pds, doc); }
private String getPdsObjectNameStr(PooledDataSource pds) { return "com.mchange.v2.c3p0:type=PooledDataSource[" + pds.getIdentityToken() + "]"; }