} else {
try {
password = Optional.of(Files.toString(new File(passwordFile),
Charsets.UTF_8).trim());
} catch (IOException e) {
throw new FlumeException(String.format(
"Could not read password file %s", passwordFile), e);
}
}
String converterClassName = context.getString(
JMSSourceConfiguration.CONVERTER_TYPE,
JMSSourceConfiguration.CONVERTER_TYPE_DEFAULT)
.trim();
if(JMSSourceConfiguration.CONVERTER_TYPE_DEFAULT.
equalsIgnoreCase(converterClassName)) {
converterClassName = DefaultJMSMessageConverter.Builder.class.getName();
}
Context converterContext = new Context(context.
getSubProperties(JMSSourceConfiguration.CONVERTER + "."));
try {
@SuppressWarnings("rawtypes")
Class clazz = Class.forName(converterClassName);
boolean isBuilder = JMSMessageConverter.Builder.class
.isAssignableFrom(clazz);
if(isBuilder) {
JMSMessageConverter.Builder builder = (JMSMessageConverter.Builder)
clazz.newInstance();
converter = builder.build(converterContext);
} else {
Preconditions.checkState(JMSMessageConverter.class.
isAssignableFrom(clazz), String.
format("Class %s is not a subclass of JMSMessageConverter",
clazz.getName()));
converter = (JMSMessageConverter)clazz.newInstance();
boolean configured = Configurables.configure(converter,
converterContext);
if(logger.isDebugEnabled()) {
logger.debug(String.
format("Attempted configuration of %s, result = %s",
converterClassName, String.valueOf(configured)));
}
}
} catch(Exception e) {
throw new FlumeException(String.format(
"Unable to create instance of converter %s", converterClassName), e);
}
String connectionFactoryName = context.getString(JMSSourceConfiguration.
CONNECTION_FACTORY, JMSSourceConfiguration.CONNECTION_FACTORY_DEFAULT)
.trim();
assertNotEmpty(initialContextFactoryName, String.format(
"Initial Context Factory is empty. This is specified by %s",
JMSSourceConfiguration.INITIAL_CONTEXT_FACTORY));
assertNotEmpty(providerUrl, String.format(
"Provider URL is empty. This is specified by %s",
JMSSourceConfiguration.PROVIDER_URL));
assertNotEmpty(destinationName, String.format(
"Destination Name is empty. This is specified by %s",
JMSSourceConfiguration.DESTINATION_NAME));
assertNotEmpty(destinationTypeName, String.format(
"Destination Type is empty. This is specified by %s",
JMSSourceConfiguration.DESTINATION_TYPE));
try {
destinationType = JMSDestinationType.valueOf(destinationTypeName);
} catch (IllegalArgumentException e) {
throw new FlumeException(String.format("Destination type '%s' is " +
"invalid.", destinationTypeName), e);
}
try {
destinationLocator = JMSDestinationLocator.valueOf(destinationLocatorName);
} catch (IllegalArgumentException e) {
throw new FlumeException(String.format("Destination locator '%s' is " +
"invalid.", destinationLocatorName), e);
}
Preconditions.checkArgument(batchSize > 0, "Batch size must be greater " +
"than 0");
try {
Properties contextProperties = new Properties();
contextProperties.setProperty(
javax.naming.Context.INITIAL_CONTEXT_FACTORY,
initialContextFactoryName);
contextProperties.setProperty(
javax.naming.Context.PROVIDER_URL, providerUrl);
initialContext = initialContextFactory.create(contextProperties);
} catch (NamingException e) {
throw new FlumeException(String.format(
"Could not create initial context %s provider %s",
initialContextFactoryName, providerUrl), e);
}
try {
connectionFactory = (ConnectionFactory) initialContext.
lookup(connectionFactoryName);
} catch (NamingException e) {
throw new FlumeException("Could not lookup ConnectionFactory", e);
}
}