if (connectionSettings.getAdvancedProperties() == null) {
connectionSettings.setAdvancedProperties(new Properties());
}
ConnectionFactory connectionFactory = new ConnectionFactory();
// EMS can connect to a Tomcat Server without using version-compatible jars from a local TC install. So,
// If we are connecting to a remote TC Server and the install path is not valid on the local host, don't
// configure to use the local jars. But, to be safe, if for some overlooked or future reason we require
// the jars then use them if they are available. Note, for a remote TC Server that would mean you'd have
// to have a version compatible local install and set the install path to the local path, even though
// the server url was remote.
String catalinaHome = pluginConfig.getSimpleValue(PLUGIN_CONFIG_CATALINA_HOME_PATH, null);
File libDir = getLibDir(catalinaHome);
if (libDir != null) {
connectionSettings.setLibraryURI(libDir.getAbsolutePath());
connectionFactory.discoverServerClasses(connectionSettings);
// Tell EMS to make copies of jar files so that the ems classloader doesn't lock
// application files (making us unable to update them) Bug: JBNADM-670
// TODO (ips): Turn this off in the embedded case.
connectionSettings.getControlProperties().setProperty(ConnectionFactory.COPY_JARS_TO_TEMP,
String.valueOf(Boolean.TRUE));
// But tell it to put them in a place that we clean up when shutting down the agent (make sure tmp dir exists)
File tempDir = resourceContext.getTemporaryDirectory();
if (!tempDir.exists()) {
tempDir.mkdirs();
}
connectionSettings.getControlProperties().setProperty(ConnectionFactory.JAR_TEMP_DIR,
tempDir.getAbsolutePath());
if (log.isDebugEnabled()) {
log.debug("Loading connection [" + connectionSettings.getServerUrl() + "] with install path ["
+ connectionSettings.getLibraryURI() + "] and temp directory [" + tempDir.getAbsolutePath()
+ "]");
}
} else {
if (log.isDebugEnabled()) {
log.debug("Loading connection [" + connectionSettings.getServerUrl()
+ "] ignoring remote install path [" + catalinaHome + "]");
}
}
ConnectionProvider connectionProvider = connectionFactory.getConnectionProvider(connectionSettings);
this.connection = connectionProvider.connect();
this.connection.loadSynchronous(false); // this loads all the MBeans
this.consecutiveConnectionErrors = 0;