ResourceDiscoveryContext discoveryContext)
throws InvalidPluginConfigurationException {
String type = pluginConfig.getSimple(JMXDiscoveryComponent.CONNECTION_TYPE).getStringValue();
if (type.equals(PARENT_TYPE)) {
throw new InvalidPluginConfigurationException("'" + PARENT_TYPE + "' is not a valid type for a manually added JVM.");
}
String connectorAddress = pluginConfig.getSimpleValue(CONNECTOR_ADDRESS_CONFIG_PROPERTY, null);
if (connectorAddress == null) {
throw new InvalidPluginConfigurationException("A connector address must be specified when manually adding a JVM.");
}
ConnectionProvider connectionProvider;
EmsConnection connection;
try {
connectionProvider = ConnectionProviderFactory.createConnectionProvider(pluginConfig, null,
discoveryContext.getParentResourceContext().getTemporaryDirectory());
connection = connectionProvider.connect();
connection.loadSynchronous(false);
} catch (Exception e) {
if (e.getCause() instanceof SecurityException) {
throw new InvalidPluginConfigurationException("Failed to authenticate to JVM with connector address ["
+ connectorAddress + "] - principal and/or credentials connection properties are not set correctly.");
}
throw new RuntimeException("Failed to connect to JVM with connector address [" + connectorAddress + "].", e);
}