Search in sources :

Example 1 with NotifierConfigurations

use of org.wso2.carbon.apimgt.core.configuration.models.NotifierConfigurations in project carbon-apimgt by wso2.

the class NotificationExecutor method sendAsyncNotifications.

/**
 * Executes the notifer classes in separtate threads.
 *
 * @param notificationDTO
 * @throws org.wso2.carbon.apimgt.core.exception.NotificationException
 */
public void sendAsyncNotifications(NotificationDTO notificationDTO) throws NotificationException {
    List<NotifierConfigurations> notifierConfigurations = new APIMConfigurations().getNotificationConfigurations().getNewVersionNotifierConfiguration().getNotifierConfigurations();
    if (notificationDTO.getType().equalsIgnoreCase(NotifierConstants.NOTIFICATION_TYPE_NEW_VERSION)) {
        for (NotifierConfigurations listItem : notifierConfigurations) {
            String executorClass = listItem.getExecutorClass();
            Map property = listItem.getPropertyList();
            Properties prop = notificationDTO.getProperties();
            prop.putAll(property);
            notificationDTO.setProperties(prop);
            // starting Notifier threads
            if (executorClass != null && !executorClass.isEmpty()) {
                Notifier notifier;
                try {
                    notifier = (Notifier) APIUtils.getClassForName(executorClass).newInstance();
                } catch (InstantiationException e) {
                    throw new NotificationException("Instantiation Error while Initializing the notifier class", e);
                } catch (IllegalAccessException e) {
                    throw new NotificationException("IllegalAccess Error while Initializing the notifier class", e);
                } catch (ClassNotFoundException e) {
                    throw new NotificationException("ClassNotFound Error while Initializing the notifier class", e);
                }
                notifier.setNotificationDTO(notificationDTO);
                executor.execute(notifier);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Class " + executorClass + " Empty Or Null");
                }
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Notification Type Does Not match with " + NotifierConstants.NOTIFICATION_TYPE_NEW_VERSION);
        }
    }
    executor.shutdown();
    while (!executor.isTerminated()) {
    }
}
Also used : APIMConfigurations(org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations) NotificationException(org.wso2.carbon.apimgt.core.exception.NotificationException) NotifierConfigurations(org.wso2.carbon.apimgt.core.configuration.models.NotifierConfigurations) Properties(java.util.Properties) Map(java.util.Map) Notifier(org.wso2.carbon.apimgt.core.impl.Notifier)

Aggregations

Map (java.util.Map)1 Properties (java.util.Properties)1 APIMConfigurations (org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations)1 NotifierConfigurations (org.wso2.carbon.apimgt.core.configuration.models.NotifierConfigurations)1 NotificationException (org.wso2.carbon.apimgt.core.exception.NotificationException)1 Notifier (org.wso2.carbon.apimgt.core.impl.Notifier)1