예제 #1
0
  private void displayDS(String connectionName, String where) {
    try {
      DataSource ds = null;
      if (connectionName == null) {
        ds = (DataSource) DatabaseConfig.getInstance().getPooledDataSource();
      } else {
        ds = (DataSource) DatabaseConfig.getInstance().getPooledDataSource(connectionName);
      }

      // make sure it's a c3p0 PooledDataSource
      if (ds != null && (ds instanceof PooledDataSource)) {
        PooledDataSource pds = (PooledDataSource) ds;
        log.debug(
            "displayDS for "
                + where
                + " -      num_connections: "
                + pds.getNumConnectionsDefaultUser());
        log.debug(
            "displayDS for "
                + where
                + " - num_busy_connections: "
                + pds.getNumBusyConnectionsDefaultUser());
        log.debug(
            "displayDS for "
                + where
                + " - num_idle_connections: "
                + pds.getNumIdleConnectionsDefaultUser());
      }
    } catch (Exception ex) {
      log.debug("displayDS for " + where + " - ERROR: " + ex.getMessage());
    }
  }
예제 #2
0
 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);
 }
예제 #3
0
    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;
    }
  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);
    }
  }
예제 #7
0
 UnknownPdsStatusReporter(PooledDataSource pds, Document doc) {
   this(pds.getClass().getName(), pds, doc);
 }
예제 #8
0
 private String getPdsObjectNameStr(PooledDataSource pds) {
   return "com.mchange.v2.c3p0:type=PooledDataSource[" + pds.getIdentityToken() + "]";
 }