1 package org.opendaylight.mwtn.dcaeConnector.impl;
 
   3 import java.util.concurrent.Executors;
 
   4 import java.util.concurrent.ScheduledExecutorService;
 
   5 import java.util.concurrent.TimeUnit;
 
   7 import org.opendaylight.mwtn.config.impl.DcaeConfig;
 
   8 import org.opendaylight.mwtn.config.impl.HtDevicemanagerConfiguration;
 
   9 import org.opendaylight.mwtn.config.impl.HtDevicemanagerConfiguration.IConfigChangedListener;
 
  10 import org.opendaylight.mwtn.devicemanager.impl.DeviceManagerImpl;
 
  11 import org.opendaylight.mwtn.devicemanager.impl.ProviderClient;
 
  12 import org.opendaylight.mwtn.devicemanager.impl.xml.ProblemNotificationXml;
 
  13 import org.slf4j.Logger;
 
  14 import org.slf4j.LoggerFactory;
 
  17 public class DcaeProviderClient implements AutoCloseable, ProviderClient {
 
  19     private static final Logger LOG = LoggerFactory.getLogger(DcaeProviderClient.class);
 
  21     private static final int MIN_HEARTBEAT_TIME_SECONDS = 30;
 
  23         private final HtDevicemanagerConfiguration htConfig;
 
  24         private final String entityName;
 
  25         private final DeviceManagerImpl deviceManager;
 
  27         private DcaeProviderWorker worker;
 
  29     public DcaeProviderClient(HtDevicemanagerConfiguration cfg, String entityName, DeviceManagerImpl deviceManager) {
 
  31         this.entityName = entityName;
 
  32         this.deviceManager = deviceManager;
 
  34                 this.htConfig.registerConfigChangedListener(configChangedListener );
 
  36                 worker = new DcaeProviderWorker(this.htConfig.getDcae(), entityName, deviceManager);
 
  40     public void sendProblemNotification(String mountPointName, ProblemNotificationXml notification) {
 
  41         synchronized(worker) {
 
  42                 worker.sendProblemNotification(mountPointName, notification);
 
  47         public void sendProblemNotification(String mountPointName, ProblemNotificationXml notification, boolean neDeviceAlarm) {
 
  48                 sendProblemNotification(mountPointName, notification);
 
  53                 this.htConfig.unregisterConfigChangedListener(configChangedListener);
 
  54         synchronized(worker) {
 
  59     /* ---------------------------------------------------------
 
  64         private IConfigChangedListener configChangedListener = new IConfigChangedListener() {
 
  67                 public void onConfigChanged() {
 
  68                         synchronized(worker) {
 
  70                                 worker = new DcaeProviderWorker(DcaeConfig.reload(), entityName, deviceManager);
 
  75         private static class DcaeProviderWorker implements AutoCloseable {
 
  78             private final ScheduledExecutorService scheduler;
 
  79             private final DcaeSenderImpl dcaepClient;
 
  80             private final DcaeMessages dcaeMessages;
 
  82             public DcaeProviderWorker(DcaeConfig configuration, String entityName, DeviceManagerImpl deviceManager) {
 
  86                 LOG.info("Configuration: "+configuration);
 
  87                 int heartbeatSeconds = configuration.getTimerPeriodSeconds();
 
  88                 if ( heartbeatSeconds < MIN_HEARTBEAT_TIME_SECONDS ) {
 
  89                         heartbeatSeconds = MIN_HEARTBEAT_TIME_SECONDS;
 
  90                         LOG.info("Adjust heartbeat intervall to minimum of { } seconds.",heartbeatSeconds);
 
  93                 dcaepClient = new DcaeSenderImpl(configuration.getEventReveicerUrl(), configuration.getUserCredentials());
 
  94                 dcaeMessages = new DcaeMessages(dcaepClient, entityName, heartbeatSeconds, deviceManager);
 
  97                 LOG.info("Create Fault manager client Task");
 
  98                 this.scheduler = Executors.newSingleThreadScheduledExecutor();
 
  99                 Runnable task = new DcaeProviderTask(dcaeMessages);
 
 101                 LOG.info("Fault task created with "+heartbeatSeconds+" Seconds");
 
 103                 this.scheduler.scheduleAtFixedRate(task, 0, heartbeatSeconds, TimeUnit.SECONDS);
 
 104                 LOG.info("Fault task scheduled");
 
 107             public void sendProblemNotification(String mountPointName, ProblemNotificationXml notification) {
 
 108                 LOG.debug("Notification answer: {}", dcaeMessages.postNotification(mountPointName, notification));
 
 112                 public void close() {
 
 114                                 this.scheduler.awaitTermination(5, TimeUnit.SECONDS);
 
 115                         } catch (InterruptedException e) {