package com.dianping.cat.report.task.alert.sender.sender;

import java.util.HashMap;
import java.util.Map;

import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.unidal.lookup.ContainerHolder;

import com.dianping.cat.Cat;
import com.dianping.cat.message.Event;
import com.dianping.cat.report.task.alert.sender.AlertChannel;
import com.dianping.cat.report.task.alert.sender.AlertMessageEntity;

public class SenderManager extends ContainerHolder implements Initializable, LogEnabled {

	private Map<String, Sender> m_senders = new HashMap<String, Sender>();

	private Logger m_logger;

	@Override
	public void initialize() throws InitializationException {
		m_senders = lookupMap(Sender.class);
	}

	public boolean sendAlert(AlertChannel channel, AlertMessageEntity message) {
		String channelName = channel.getName();

		try {
			Sender sender = m_senders.get(channelName);
			boolean result = sender.send(message);
			String type = message.getType();

			if (result) {
				Cat.logEvent("Channel:" + channelName, type + ":success", Event.SUCCESS, null);
			} else {
				Cat.logEvent("Channel:" + channelName, type + ":fail", Event.SUCCESS, null);
			}
			m_logger.info("Alert Channel " + channelName + ",content" + message.toString());
			return result;
		} catch (Exception e) {
			Cat.logError(e);
			return false;
		}
	}

	@Override
	public void enableLogging(Logger logger) {
		m_logger = logger;
	}

}

@@ -105,98 +105,8 @@
 p;%0A%0A
-import org.codehaus.plexus.logging.LogEnabled;%0Aimport org.codehaus.plexus.logging.Logger;%0A
 impo
@@ -588,20 +588,8 @@
 able
-, LogEnabled
  %7B%0A%0A
@@ -665,35 +665,8 @@
 );%0A%0A
-%09private Logger m_logger;%0A%0A
 %09@Ov
@@ -1232,92 +1232,8 @@
 %09%09%7D%0A
-%09%09%09m_logger.info(%22Alert Channel %22 + channelName + %22,content%22 + message.toString());%0A
 %09%09%09r
@@ -1321,86 +1321,6 @@
 %09%7D%0A%0A
-%09@Override%0A%09public void enableLogging(Logger logger) %7B%0A%09%09m_logger = logger;%0A%09%7D%0A%0A
 %7D%0A

remove logs about sending alert message