Set<DiscoveredResourceDetails> resourceDetails = super.discoverResources(context, false);
// we depend on the GlobalRequestProcessor MBeans (1 for each connector) to fully define the resources, so the connector and
// GlobalRequestProcessor MBeans must be fully deployed. If the mbeans aren't fully deployed then wait for
// the next go around of the PC.
EmsConnection connection = context.getParentResourceComponent().getEmsConnection();
ObjectNameQueryUtility queryUtility = new ObjectNameQueryUtility(
"Catalina:type=GlobalRequestProcessor,name=%name%");
List<EmsBean> grpBeans = connection.queryBeans(queryUtility.getTranslatedQuery());
if (grpBeans.size() != resourceDetails.size()) {
if (log.isDebugEnabled())
log.debug("Connector discovery pending jboss.web:type=GlobalRequestProcessor,name=* deployment...");
return Collections.emptySet();
}
// Map <port, ConfigInfo>
Map<String, ConfigInfo> configMap = new HashMap<String, ConfigInfo>(grpBeans.size());
for (EmsBean bean : grpBeans) {
ConfigInfo configInfo = new ConfigInfo(bean);
if (null != configInfo.getPort()) {
configMap.put(configInfo.port, configInfo);
} else {
log.warn("Failed to parse ObjectName for GlobalRequestProcessor: " + configInfo.getName() + ": "
+ configInfo.getException());
}
}
for (DiscoveredResourceDetails resource : resourceDetails) {
Configuration pluginConfiguration = resource.getPluginConfiguration();
String port = pluginConfiguration.getSimple(TomcatConnectorComponent.PLUGIN_CONFIG_PORT).getStringValue();
ConfigInfo configInfo = configMap.get(port);
// Set handler plugin config and update resource name
String handler = (null != configInfo) ? configInfo.getHandler() : TomcatConnectorComponent.UNKNOWN;
// It is unusual but possible that there is a GlobalRequestProcessor object representing a configured AJP
// connector but with a different port. If the configured AJP connector port is in use, Tomcat increments
// the port number (up to maxPort) looking for a free port. That actual listening port is used on the
// GlobalRequestProcessor object. This behavior seems to be, after some research, considered a bug in
// Tomcat. So, until proven otherwise, we'll treat it as such. To bring this to the attention of the user
// we do still discover the connector, but we'll fail the component start and provide a useful message
// indicating that the Tomcat configuration should change. Handler being set UNKNOWN will signal the problem.
pluginConfiguration.put(new PropertySimple(TomcatConnectorComponent.PLUGIN_CONFIG_HANDLER, handler));
// Set address if it is in use
String address = (null != configInfo) ? configInfo.getAddress() : null;
if ((null != address) && !"".equals(address.trim())) {
pluginConfiguration.put(new PropertySimple(TomcatConnectorComponent.PLUGIN_CONFIG_ADDRESS, address));
}
// Set connector if it is in use
String connector = (null != configInfo) ? configInfo.getConnector() : null;
if ((null != connector) && !"".equals(connector.trim())) {
pluginConfiguration.put(new PropertySimple(TomcatConnectorComponent.PLUGIN_CONFIG_CONNECTOR, connector));
}
// Set the global request processor name (Tomcat 7 added quotes around the name value)
String name = (null != configInfo) ? configInfo.getName() : null;
resource.setResourceName(resource.getResourceName().replace("{name}", name));
pluginConfiguration.put(new PropertySimple(TomcatConnectorComponent.PLUGIN_CONFIG_NAME, name));
// Let's try to auto-discover if this Connector is using a shared executor for its thread pool.
// If it is, let's set the plugin config property automatically so we can collect the proper metrics.
// Note that if the "executorName" attribute on the Connector MBean is "Internal", that means it is NOT shared.
String connectorON = pluginConfiguration.getSimpleValue(TomcatConnectorComponent.OBJECT_NAME_PROP, null);
if (connectorON != null) {
EmsBean connectorBean = connection.getBean(connectorON);
EmsAttribute executorNameAttrib = connectorBean.getAttribute("executorName");
if (executorNameAttrib != null) {
Object executorNameValue = executorNameAttrib.getValue();
if (executorNameValue != null) {
String executorName = executorNameValue.toString();