ServiceLoader<NotificationConsumerStrategy> consumerLoader = ServiceLoader.load(NotificationConsumerStrategy.class);
Iterator<NotificationConsumerStrategy> consumerIterator = consumerLoader.iterator();
strategyMap = new HashMap<String, NotificationConsumerStrategy>();
while (consumerIterator.hasNext()) {
NotificationConsumerStrategy p = consumerIterator.next();
if (!strategyMap.containsKey(p.getName())) {
strategyMap.put(p.getName(), p);
}
else {
if (strategyMap.get(p.getName()) != p) {
String msg = "Multiple different NotificationConsumerStrategies with the same strategy name " +
"('" + p.getName() + "') are present on the classpath. Strategy names must be unique.";
log.error(msg);
throw new ServiceConfigurationError(msg);
}
}
}