use of org.opennms.netmgt.telemetry.adapters.api.Adapter in project opennms by OpenNMS.
the class TelemetryAdapterRegistryImpl method getAdapter.
@Override
public Adapter getAdapter(String className, Protocol protocol, Map<String, String> properties) {
AdapterFactory adapterFactory = m_adapterFactoryByClassName.get(className);
while ((adapterFactory == null) && ManagementFactory.getRuntimeMXBean().getUptime() < GRACE_PERIOD_MS) {
try {
Thread.sleep(LOOKUP_DELAY_MS);
} catch (InterruptedException e) {
LOG.error("Interrupted while waiting for adapter factory to become available in the service registry. Aborting.");
return null;
}
adapterFactory = m_adapterFactoryByClassName.get(className);
}
Adapter adapter = null;
if (adapterFactory != null) {
adapter = adapterFactory.createAdapter(protocol, properties);
}
return adapter;
}
use of org.opennms.netmgt.telemetry.adapters.api.Adapter in project opennms by OpenNMS.
the class TelemetryMessageConsumer method buildAdapter.
private Adapter buildAdapter(org.opennms.netmgt.telemetry.config.model.Adapter adapterDef) throws Exception {
Adapter adapter = adapterRegistry.getAdapter(adapterDef.getClassName(), protocolDef, adapterDef.getParameterMap());
if (adapter == null) {
final Object adapterInstance;
try {
final Class<?> clazz = Class.forName(adapterDef.getClassName());
final Constructor<?> ctor = clazz.getConstructor();
adapterInstance = ctor.newInstance();
} catch (Exception e) {
throw new RuntimeException(String.format("Failed to instantiate adapter with class name '%s'.", adapterDef.getClassName(), e));
}
// Cast
if (!(adapterInstance instanceof Adapter)) {
throw new IllegalArgumentException(String.format("%s must implement %s", adapterDef.getClassName(), Adapter.class.getCanonicalName()));
}
adapter = (Adapter) adapterInstance;
// Apply the parameters
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(adapter);
wrapper.setPropertyValues(adapterDef.getParameterMap());
// Autowire!
final AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
beanFactory.autowireBean(adapter);
beanFactory.initializeBean(adapter, "adapter");
// Set the protocol reference
adapter.setProtocol(protocolDef);
}
return adapter;
}
Aggregations