use of org.opennms.plugins.dbnotifier.DbNotificationClientQueueImpl in project opennms by OpenNMS.
the class DbChangeNotifierTest method test1.
@Test
public void test1() {
System.out.println("Starting DbChangeNotifierTest test1");
DbNotifierDataSourceFactory dsFactory = new DbNotifierDataSourceFactory();
dsFactory.setDataBaseName("opennms");
dsFactory.setUserName("opennms");
dsFactory.setPassWord("opennms");
dsFactory.setHostname("localhost");
dsFactory.setPort("5432");
// TODO remove
// PGDataSource pgDataSource = new PGDataSource();
//
// pgDataSource.setHost("localhost");
// pgDataSource.setPort(5432);
// pgDataSource.setDatabase("opennms");
// pgDataSource.setUser("opennms");
// pgDataSource.setPassword("opennms");
DatabaseChangeNotifier dbChangeNotifier = null;
try {
System.out.println("DbChangeNotifierTest creating connection - this is quite slow");
List<String> paramList = new ArrayList<>();
paramList.add(DatabaseChangeNotifier.NOTIFY_EVENT_CHANGES);
paramList.add(DatabaseChangeNotifier.NOTIFY_ALARM_CHANGES);
dbChangeNotifier = new DatabaseChangeNotifier(dsFactory, paramList);
DbNotificationClientQueueImpl dbNotificationQueueClient = new DbNotificationClientQueueImpl();
Map<String, NotificationClient> channelHandlingClients = new HashMap<String, NotificationClient>();
// channelHandlingClients.put("opennms_alarm_changes", new VerySimpleNotificationClient());
AlarmChangeNotificationClient alarmChangeNotificationClient = new AlarmChangeNotificationClient();
channelHandlingClients.put("opennms_alarm_changes", alarmChangeNotificationClient);
dbNotificationQueueClient.setChannelHandlingClients(channelHandlingClients);
dbNotificationQueueClient.setDatabaseChangeNotifier(dbChangeNotifier);
dbNotificationQueueClient.init();
System.out.println("DbChangeNotifierTest initialising connection");
dbChangeNotifier.init();
System.out.println("DbChangeNotifierTest waiting for messages or until timeout");
try {
// wait for interrupt or time out
Thread.sleep(50000);
} catch (InterruptedException e) {
}
System.out.println("DbChangeNotifierTest shutting down");
} catch (Throwable e) {
e.printStackTrace();
} finally {
System.out.println("DbChangeNotifierTest destroying connection");
try {
if (dbChangeNotifier != null) {
dbChangeNotifier.destroy();
}
} catch (Throwable e) {
e.printStackTrace();
}
}
System.out.println("End of DbChangeNotifierTest test1");
}
Aggregations