package eu.dnetlib.enabling.tools.blackboard;

import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Invokes a chain of notification handlers for each incoming notification. Normally an instance of this class is
 * registered as the notification handler for a given service.
 *
 * @author marko
 *
 */
public class NotificationHandlerChain implements NotificationHandler {

	/**
	 * logger.
	 */
	private static final Log log = LogFactory.getLog(NotificationHandlerChain.class); // NOPMD by marko on 11/24/08 5:02 PM

	/**
	 * notification handler chain.
	 */
	private Collection<NotificationHandler> handlers;

	/**
	 * {@inheritDoc}
	 *
	 * @see eu.dnetlib.enabling.tools.blackboard.NotificationHandler#notified(java.lang.String, java.lang.String,
	 *      java.lang.String, java.lang.String)
	 */
	public void notified(final String subscrId, final String topic, final String rsId, final String profile) {
		for (final NotificationHandler handler : handlers) {
			try {
				handler.notified(subscrId, topic, rsId, profile);
			} catch (final RuntimeException e) {
				log.fatal("error processing notification handler " + handler, e);
			}
		}
	}

	public Collection<NotificationHandler> getHandlers() {
		return handlers;
	}

	public void setHandlers(final Collection<NotificationHandler> handlers) {
		this.handlers = handlers;
	}

}
