try {
Set dsNames = server.queryNames(new ObjectName("jboss.jca:service=ManagedConnectionPool,*"), null);
for (Iterator it = dsNames.iterator(); it.hasNext();) {
ObjectName managedConnectionPoolOName = (ObjectName) it.next();
ApplicationResource resource = new ApplicationResource();
resource.setName(managedConnectionPoolOName.getKeyProperty("name"));
resource.setType("jboss");
String criteria = (String) server.getAttribute(managedConnectionPoolOName, "Criteria");
if ("ByApplication".equals(criteria)) {
resource.setAuth("Application");
} else if ("ByContainerAndApplication".equals(criteria)) {
resource.setAuth("Both");
} else {
resource.setAuth("Container");
}
DataSourceInfo dsInfo = new DataSourceInfo();
dsInfo.setMaxConnections(((Integer) server.getAttribute(managedConnectionPoolOName, "MaxSize")).intValue());
dsInfo.setEstablishedConnections(((Integer) server.getAttribute(managedConnectionPoolOName, "ConnectionCount")).intValue());
dsInfo.setBusyConnections(((Long) server.getAttribute(managedConnectionPoolOName, "InUseConnectionCount")).intValue());
ObjectName connectionFactoryOName = new ObjectName("jboss.jca:service=ManagedConnectionFactory,name=" + resource.getName());
Element elm = (Element) server.getAttribute(connectionFactoryOName, "ManagedConnectionFactoryProperties");
if (elm != null) {
NodeList nl = elm.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node n = nl.item(i);
Node na = n.getAttributes().getNamedItem("name");
if (na != null) {
if ("ConnectionURL".equals(na.getNodeValue())) {
dsInfo.setJdbcURL(n.getFirstChild().getNodeValue());
}
if ("UserName".equals(na.getNodeValue())) {
dsInfo.setUsername(n.getFirstChild().getNodeValue());
}
//
// JMS datasource
//
if ("JmsProviderAdapterJNDI".equals(na.getNodeValue())) {
dsInfo.setJdbcURL(n.getFirstChild().getNodeValue());
resource.setType("jms");
}
}
}
}
dsInfo.setResettable(true);
resource.setDataSourceInfo(dsInfo);
resources.add(resource);
}
} catch (Exception e) {
//
logger.fatal("There was an error querying JBoss JMX server:", e);