01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.org
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package example.jmx.timer;
09:
10: import java.util.Date;
11: import javax.management.timer.Timer;
12: import javax.management.MBeanServer;
13: import javax.management.MBeanServerFactory;
14: import javax.management.ObjectName;
15:
16: import org.huihoo.jfox.jmx.adaptor.http.HtmlAdaptorServer;
17:
18: /**
19: *
20: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
21: */
22:
23: public class SimpleTimerAgent {
24:
25: public static void main(String[] args) throws Exception {
26:
27: MBeanServer server = MBeanServerFactory.createMBeanServer();
28: Timer timer = new Timer();
29: ObjectName timerObjectName = new ObjectName(":Server=Timer");
30: server.registerMBean(timer, timerObjectName);
31:
32: SimpleTimerListener timerListener = new SimpleTimerListener();
33: timer.addNotificationListener(timerListener, null, null);
34:
35: timer.setSendPastNotifications(false);
36: timer.addNotification("testType", "testMessage", null,
37: new Date(System.currentTimeMillis() + 1000L));
38: timer.addNotification("testType2", "testMessage2", null,
39: new Date(System.currentTimeMillis() + 2000L), 2000L);
40: timer.addNotification("testType3", "testMessage3", null,
41: new Date(System.currentTimeMillis() + 500L), 500L, 2);
42:
43: // timer.doStart();
44:
45: HtmlAdaptorServer has = new HtmlAdaptorServer();
46: server
47: .registerMBean(has, new ObjectName(
48: ":Server=HtmlAdaptor"));
49: has.start();
50:
51: }
52:
53: }
|