KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > varia > scheduler > example > SchedulableMBeanExample


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.varia.scheduler.example;
23
24 import java.security.InvalidParameterException JavaDoc;
25 import java.util.Date JavaDoc;
26
27 import javax.management.MalformedObjectNameException JavaDoc;
28 import javax.management.MBeanServer JavaDoc;
29 import javax.management.Notification JavaDoc;
30 import javax.management.timer.TimerNotification JavaDoc;
31 import javax.management.NotificationFilter JavaDoc;
32 import javax.management.NotificationListener JavaDoc;
33 import javax.management.ObjectName JavaDoc;
34
35 import org.jboss.logging.Logger;
36 import org.jboss.system.ServiceMBeanSupport;
37
38 import org.jboss.varia.scheduler.Schedulable;
39
40 /**
41  * A sample SchedulableMBean that records when an event is received.
42  *
43  * @jmx:mbean extends="org.jboss.system.ServiceMBean"
44  *
45  * @author <a HREF="mailto:andreas@jboss.org">Andreas Schaefer</a>
46  * @author Cameron (camtabor)
47  * @version $Revision: 58158 $
48  *
49  **/

50 public class SchedulableMBeanExample
51    extends ServiceMBeanSupport
52    implements SchedulableMBeanExampleMBean
53 {
54
55    private Notification JavaDoc notification;
56    private Date JavaDoc date;
57    private long repetitions;
58    private ObjectName JavaDoc name;
59    private String JavaDoc test;
60    private int hitCount;
61    
62    // -------------------------------------------------------------------------
63
// SchedulableExampleMBean Methods
64
// -------------------------------------------------------------------------
65

66    /**
67     * Called by ScheduleManager.
68     * @jmx:managed-operation
69     */

70    public void hit(Notification JavaDoc notification, Date JavaDoc date, long repetitions, ObjectName JavaDoc name, String JavaDoc test)
71    {
72       log.info("got hit");
73       this.notification = notification;
74       this.date = date;
75       this.repetitions = repetitions;
76       this.name = name;
77       this.test = test;
78       hitCount++;
79       log.info(this.toString());
80    }
81
82   /**
83    * Returns the number of hits.
84    * @jmx:managed-attribute
85    */

86    public int getHitCount()
87    {
88      return hitCount;
89    }
90    
91   /**
92    * Returns the last hit date.
93    * @jmx:managed-attribute
94    */

95    public Date JavaDoc getHitDate()
96    {
97      return date;
98    }
99    
100   /**
101    * Returns the last hit notification.
102    * @jmx:managed-attribute
103    */

104    public Notification JavaDoc getHitNotification()
105    {
106      return notification;
107    }
108    
109   /**
110    * Returns the last hit date.
111    * @jmx:managed-attribute
112    */

113    public long getRemainingRepetitions()
114    {
115      return repetitions;
116    }
117    
118   /**
119    * Returns the object name.
120    * @jmx:managed-attribute
121    */

122    public ObjectName JavaDoc getSchedulerName()
123    {
124      return name;
125    }
126    
127   /**
128    * Returns the test string.
129    * @jmx:managed-attribute
130    */

131    public String JavaDoc getTestString()
132    {
133      return test;
134    }
135    
136    /**
137     * Returns a debug string.
138     */

139    public String JavaDoc toString() {
140       return super.toString()
141          + " name=" + getName()
142          + " hitCount=" + hitCount
143          + " notification=" + notification
144          + " date=" + date
145          + " repetitions=" + repetitions
146          + " name=" + name
147          + " test string=" + test;
148    }
149 }
150
Popular Tags