package com.helpers.notification.manager;

import com.helpers.notification.filters.NotificationFilter;
import com.helpers.notification.handlers.NotificationHandler;
import com.helpers.notification.messages.NotificationMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.concurrent.*;

//General class to manage how notifications are forwarded
public class NotificationManager {

  private static final Logger log = LoggerFactory.getLogger(NotificationManager.class);

  private static Set<NotificationProcessor> notificationProcessors = new HashSet<>();

  public synchronized static void receiveNotification(NotificationMessage message){
    if (message==null) {
      log.error("Null notification message received");
      return;
    }
    for (NotificationProcessor processor: notificationProcessors) {
      processor.addMessage(message);
    }
  }

  public static void addNotificationProcessor(List<NotificationFilter> filters, NotificationHandler handler) {
    NotificationProcessor processor = new NotificationProcessor(handler);
    processor.addFilters(filters);
    notificationProcessors.add(processor);
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.submit(processor);
  }

}

@@ -132,17 +132,156 @@
 ion.
-handlers.
+filters.impl.TypeNotificationFilter;%0Aimport com.helpers.notification.handlers.NotificationHandler;%0Aimport com.helpers.notification.handlers.impl.Log
 Noti
@@ -359,16 +359,75 @@
 essage;%0A
+import com.helpers.notification.messages.NotificationType;%0A
 import o
@@ -1429,16 +1429,16 @@
 utor();%0A
-
     exec
@@ -1466,10 +1466,1203 @@
 );%0A  %7D%0A%0A
+  static %7B%0A    //load notification handlers%0A    List%3CString%3E classNames = new ArrayList%3C%3E();%0A    classNames.add(%22com.helpers.notification.handlers.log.LogNotificationHandler%22);%0A    for (String in: classNames) %7B%0A      Class className = null;%0A      try %7B%0A        className = Class.forName(in);%0A      %7D catch (ClassNotFoundException e) %7B%0A        log.error(%22Could not find instance of Notification Handler class%22, e);%0A      %7D%0A      if (className!=null) %7B%0A        if (!(NotificationHandler.class.isAssignableFrom(className))) %7B%0A          log.error(%22Class %22 + className.getSimpleName() + %22 not an instance of a NotificationHandler%22);%0A        %7D else %7B%0A          try %7B%0A            NotificationHandler hdlr = (NotificationHandler)className.newInstance();%0A            List%3CNotificationFilter%3E filters = new ArrayList%3C%3E();%0A            filters.add(new TypeNotificationFilter(NotificationType.TENotification));%0A            NotificationManager.addNotificationProcessor(filters, hdlr);%0A          %7D catch (InstantiationException %7C IllegalAccessException e) %7B%0A            log.error(%22Could not instantiate class. Please check if default constructor is implemented%22, e);%0A          %7D%0A        %7D%0A      %7D%0A    %7D%0A  %7D%0A%0A
 %7D%0A

initialize Notification Manager from File