Search in sources :

Example 1 with AlarmChangeNotificationClient

use of org.opennms.plugins.dbnotifier.alarmnotifier.AlarmChangeNotificationClient 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");
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DbNotifierDataSourceFactory(org.opennms.plugins.dbnotifier.DbNotifierDataSourceFactory) DatabaseChangeNotifier(org.opennms.plugins.dbnotifier.DatabaseChangeNotifier) DbNotificationClientQueueImpl(org.opennms.plugins.dbnotifier.DbNotificationClientQueueImpl) NotificationClient(org.opennms.plugins.dbnotifier.NotificationClient) AlarmChangeNotificationClient(org.opennms.plugins.dbnotifier.alarmnotifier.AlarmChangeNotificationClient) AlarmChangeNotificationClient(org.opennms.plugins.dbnotifier.alarmnotifier.AlarmChangeNotificationClient) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 DatabaseChangeNotifier (org.opennms.plugins.dbnotifier.DatabaseChangeNotifier)1 DbNotificationClientQueueImpl (org.opennms.plugins.dbnotifier.DbNotificationClientQueueImpl)1 DbNotifierDataSourceFactory (org.opennms.plugins.dbnotifier.DbNotifierDataSourceFactory)1 NotificationClient (org.opennms.plugins.dbnotifier.NotificationClient)1 AlarmChangeNotificationClient (org.opennms.plugins.dbnotifier.alarmnotifier.AlarmChangeNotificationClient)1