I've been doing some research on how to get my Timer Mbean set up. I think
I'm almost there, I've got the code written and the Timer Mbean running, but
I don't know how to make sure that my class is registered with the service
to make sure that it gets the notifications.

anybody know how to register this code with the mbean? also, I copied this
code from
http://www.mail-archive.com/[email protected]/msg06591.html,
and I got rid of the interface the outer class was implementing if that
helps....

TIA,

Dave

here's the code that i'm using:

/*
* TimerListener.java
*
* Created on July 27, 2001, 11:06 AM
*/

package com.incentivation.eval.util;


import java.util.*;
import javax.naming.*;
import javax.jms.*;
import javax.management.*;
import javax.management.timer.*;

public class TimerListener extends org.jboss.util.ServiceMBeanSupport
{
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
{
TimerListener.this.setTimer();
System.out.println("You got a notification.");
}
catch (Exception e)
{

}
}
}

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();
}
}


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to