Here's an example that works for me. YMMV. I've tried to remove all
application specific code, but still leave relavent timer MBean code. I
reset the timer on each timer call. You can probably set the timer up to
send periodically. The timerInterval is in seconds in this example (default
10 seconds). Blame formatting stuff on VisualAge :).
Good luck!
import java.util.*;
import javax.naming.*;
import javax.jms.*;
import javax.management.*;
import javax.management.timer.*;
public class YourMBean extends org.jboss.util.ServiceMBeanSupport implements
YourMBeanInterface {
protected javax.management.MBeanServer mbeanServer = null;
protected javax.management.ObjectInstance timerRef = null;
protected long timeInterval = 10 * javax.management.timer.Timer.ONE_SECOND;
public class Listener implements NotificationListener {
public void handleNotification(Notification pNotification, Object
pHandback) {
try {
YourMBean.this.setTimer();
/*
Other Stuff Here
*/
} catch (Exception e) {
System.out.println(
"Exception in YourMBean inner class Listener: " +
e.toString());
}
}
}
public String getName() {
return "YourNameHere";
}
public long getTimeInterval() {
return timeInterval;
}
public javax.management.ObjectName preRegister(javax.management.MBeanServer
param1, javax.management.ObjectName param2) throws java.lang.Exception {
mbeanServer = param1;
return super.preRegister( param1, param2 );
}
public void setTimeInterval(long newTimeInterval) {
timeInterval = newTimeInterval * javax.management.timer.Timer.ONE_SECOND;
}
public void setTimer() throws java.lang.Exception {
try {
Date timerDate = new Date( new Date().getTime() + getTimeInterval() );
Integer theTimer = (Integer) mbeanServer.invoke(
timerRef.getObjectName(),
"addNotification",
new Object [] { "Your name here", "One Time Timer", null,
timerDate },
new String [] { "".getClass().getName(),
"".getClass().getName(),
"java.lang.Object", timerDate.getClass().getName() } );
} catch (Exception e) {
log.log( "YourMBean.setTimer() exception: " + e.getMessage() );
throw e;
}
}
public void setupTimer() throws Exception {
try {
Set beanList =
mbeanServer.queryMBeans(
new ObjectName("DefaultDomain", "service", "timer"),
null);
if (!beanList.isEmpty()) {
timerRef = (ObjectInstance) beanList.iterator().next();
}
mbeanServer.addNotificationListener( timerRef.getObjectName(), new
Listener(), null, null );
} catch (Exception e) {
log.log("Exception in YourMBean.setupTimer(): " + e.toString());
throw e;
}
setTimer();
}
public void start() throws java.lang.Exception {
super.start();
/*
Some Stuff here
*/
setupTimer();
}
}
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Keerthi
> Panneer
> Sent: Monday, June 11, 2001 9:04 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [JBoss-user] Timer MBan Problem
>
>
> Hi,
> I tried the example described at
> http://www.jboss.org/documentation/HTML/ch11s74.html
> but i could not get it work... please let me know if someone gives you a
> working source code
>
> thanks
> keerthi
>
>
> >From: "David Crecente" <[EMAIL PROTECTED]>
> >Reply-To: [EMAIL PROTECTED]
> >To: "Lista Jboss" <[EMAIL PROTECTED]>
> >Subject: [JBoss-user] Timer MBan Problem
> >Date: Mon, 11 Jun 2001 18:40:37 +0200
> >
> > Hi all,
> > Could someone send me a Timer MBean sample?
> >
> > Thank you in advance.
> >
> >_______________________________________________
> >JBoss-user mailing list
> >[EMAIL PROTECTED]
> >http://lists.sourceforge.net/lists/listinfo/jboss-user
>
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user