1 8 package mx4j.examples.tools.mail; 9 10 import javax.management.Attribute ; 11 import javax.management.JMException ; 12 import javax.management.MBeanServer ; 13 import javax.management.MBeanServerFactory ; 14 import javax.management.ObjectName ; 15 16 25 public class MailExample 26 { 27 28 private static interface TestClassMBean 29 { 30 public String getStr(); 31 32 public void setStr(String str); 33 } 34 35 public static class TestClass implements TestClassMBean 36 { 37 private String str; 38 39 public TestClass(String str) 40 { 41 this.str = str; 42 } 43 44 public String getStr() 45 { 46 return str; 47 } 48 49 public void setStr(String str) 50 { 51 this.str = str; 52 } 53 } 54 55 public MailExample() 56 { 57 } 58 59 62 public void start() throws JMException  63 { 64 MBeanServer server = MBeanServerFactory.createMBeanServer("Mail"); 66 ObjectName beanName = new ObjectName ("Test:name=test"); 67 server.registerMBean(new TestClass("original"), beanName); 68 69 ObjectName monitorName = new ObjectName ("Test:name=monitor"); 70 server.createMBean("javax.management.monitor.StringMonitor", monitorName, null); 71 72 server.setAttribute(monitorName, new Attribute ("ObservedObject", beanName)); 73 server.setAttribute(monitorName, new Attribute ("ObservedAttribute", "Str")); 74 server.setAttribute(monitorName, new Attribute ("StringToCompare", "original")); 75 server.setAttribute(monitorName, new Attribute ("GranularityPeriod", new Integer (100))); 76 server.setAttribute(monitorName, new Attribute ("NotifyDiffer", Boolean.TRUE)); 77 78 server.invoke(monitorName, "start", null, null); 79 80 ObjectName mailerName = new ObjectName ("Test:name=mailer"); 81 server.createMBean("mx4j.tools.mail.SMTP", mailerName, null); 82 83 server.setAttribute(mailerName, new Attribute ("ObservedObject", monitorName)); 85 server.setAttribute(mailerName, new Attribute ("NotificationName", "jmx.monitor.string.differs")); 86 server.setAttribute(mailerName, new Attribute ("FromAddress", "monitor@someserver")); 87 server.setAttribute(mailerName, new Attribute ("FromName", "MX4J")); 88 server.setAttribute(mailerName, new Attribute ("ServerHost", "smpt-server")); 89 server.setAttribute(mailerName, new Attribute ("To", "nobody@nobody")); 90 server.setAttribute(mailerName, new Attribute ("Subject", "Notification on $date$ at $time$")); 91 server.setAttribute(mailerName, new Attribute ("Content", "Notification on $datetime$ sent by $objectname$ on $observed$ monitor and a notification $notification$\nNotice how $$$$ gets expanded to $$")); 92 93 server.setAttribute(beanName, new Attribute ("Str", "something-else")); 95 96 } 97 98 public static void main(String [] str) throws JMException  99 { 100 MailExample example = new MailExample(); 101 example.start(); 102 } 103 } 104 105 | Popular Tags |