/[projects]/CircuitBreaker/src/dk/thoerup/circuitbreaker/notification/MailNotifier.java
ViewVC logotype

Contents of /CircuitBreaker/src/dk/thoerup/circuitbreaker/notification/MailNotifier.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1155 - (show annotations) (download)
Sun Oct 3 17:17:38 2010 UTC (13 years, 7 months ago) by torben
File size: 1513 byte(s)
don't send mial on all events
1 package dk.thoerup.circuitbreaker.notification;
2
3 import java.util.Properties;
4
5 import javax.mail.Message;
6 import javax.mail.Session;
7 import javax.mail.Transport;
8 import javax.mail.internet.InternetAddress;
9 import javax.mail.internet.MimeMessage;
10
11 import java.util.logging.*;
12
13 import dk.thoerup.circuitbreaker.CircuitBreaker;
14
15 public class MailNotifier extends AsyncNotifier {
16
17
18 Logger logger = Logger.getLogger(MailNotifier.class.getName());
19
20 private String recipient;
21 private String from;
22
23 Properties props;
24
25 public MailNotifier(CircuitBreaker cb, String from, String recipient, String mailhost) {
26 super(cb);
27
28 this.from = from;
29 this.recipient = recipient;
30
31 props = new Properties();
32 props.put("mail.smtp.host", mailhost);
33 }
34
35
36 @Override
37 public void sendAsync(String breakerName, Event evnt) {
38 try {
39 if (evnt == Event.BreakerTripped || evnt == Event.BreakerReset) {
40 // create some properties and get the default Session
41 Session session = Session.getDefaultInstance(props, null);
42 session.setDebug(true);
43
44
45 // create a message
46
47 MimeMessage msg = new MimeMessage(session);
48 msg.setFrom( new InternetAddress(from) );
49
50 msg.setRecipient(Message.RecipientType.TO, new InternetAddress(recipient) );
51 msg.setSubject("Circuitbreaker " + breakerName + " : " + evnt.toString());
52 msg.setText("--");
53
54 Transport.send(msg);
55 }
56 } catch (Exception e) {
57 logger.warning("Unable to send CircuitBreaker notification mail " + e );
58 }
59
60
61 }
62
63 }

  ViewVC Help
Powered by ViewVC 1.1.20