HI,
here it is.
UNFORTUNATELY (and i repeat, unfortunately) the class extends the ServiceMBeanSupport
because i have deployed it as standalone MBean.
the bean is a Dynamic MBean, if u r just starting maybe it's not a good idea, but
it's anyway the same.
my MBean is actually wrapping the timer service in jboss, it is not extending it.
What it does is to:
1 - in the init() mehtod it initializes all the JMS Administrative objects (my MBean
sends a
message to a JMS Destination,w here a MessageDrivenBean sends an email. it's an email
bomber :-)
2 - in the preRegister i get a reference to teh timer service and register my MBean as
a listener
of generated event. every n seconds, i will send an email depending.
3 - i have 3 methods
- Add Notification - adds a notification that will be emitted every n seconds for
n times
- Add NotificationBomb - adds a notification that will be emitted every n seconds
forever :-)
- Add SMSNotificatin - like AddNotification, but when this notification will be
emitted i'll send an SMS
Now, it's a dynamic bean, so you can ignore all the methods from the start until
getName(). those methods are
for building the DynamicMBean interface (i have played around this MBean a lot, that's
why it is 600 lines long,
sorry 4 that).
A drawback is that if u deploy in JBoss as a 'standalone MBean' (meaning, you want it
to be registered automatically and
deploy it as a .sar) u have to extend the ServiceMBeanSupport.
if instead you instantiate it in your webapp, then you can write your normal class.
there's an example in JBoss Hands On guide about what you want to do.
last, but not least, if you want to use it in jboss, you have to register the
timerservice yourself in order
to start the timer.
you can do it with following lines to the jboss-service.xml file in the
server\default\conf
<mbean code="javax.management.timer.Timer" name="DefaultDomain:service=timer"/>
don't forget to put them AFTER following mbean registration
<mbean code="org.jboss.invocation.pooled.server.PooledInvoker"
name="jboss:service=invoker,type=pooled">
<attribute name="NumAcceptThreads">1</attribute>
<attribute name="MaxPoolSize">300</attribute>
<attribute name="ClientMaxPoolSize">300</attribute>
<attribute name="SocketTimeout">60000</attribute>
<attribute name="ServerBindAddress"></attribute>
<attribute name="ServerBindPort">0</attribute>
<attribute name="ClientConnectAddress"></attribute>
<attribute name="ClientConnectPort">0</attribute>
<attribute name="EnableTcpNoDelay">false</attribute>
<depends
optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager</depends>
</mbean>
and now, the code.,
hope it can help you. at least it can be a start point when u will tackle Dynamic
MBean.
as i said, in the JBoss Hands on guide there's an example on how to implement ur timer
service.
don't hesitate to send me an email if u need clarifications etc...but i m sure jboss
list has lot
of jmx gurus :-)
regards
marco
> -----Original Message-----
> From: ext [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> Sent: 18 August, 2003 15:50
> To: [EMAIL PROTECTED]
> Subject: AW: [JBoss-user] JMX Timer
>
>
> Hi Marco,
>
> I am new to JMX but I assume a pure JMX implementation should
> be portable to other servers. I have developed a MBean which
> can be started. If this MBean is started, the configuration
> will be loaded and the Listener added. Thats all I want to do.
>
> I would be interested in your code.
>
> Juraj
>
> -----Urspr�ngliche Nachricht-----
> Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Gesendet: Montag, 18. August 2003 14:37
> An: [EMAIL PROTECTED]
> Betreff: RE: [JBoss-user] JMX Timer
>
>
> Hi,
> i have implemented a similar case using Timer service and
> a MessageDriven bean, but in jboss. will it help? i guess how
> i am retrieving
> the Timer service is independent from the JMX implementation anyway
> can u tell me how your application is working?
> i can attach (via private email) the sourcecode of my sample
> if u want...
>
> regards
> marco
>
> > -----Original Message-----
> > From: ext [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]
> > Sent: 18 August, 2003 15:16
> > To: [EMAIL PROTECTED]
> > Subject: [JBoss-user] JMX Timer
> >
> >
> > Hi,
> >
> > I am trying to implement a Timer-service which invokes an EJB
> > workflow. This MBean has to be independent from the running
> > container. So I dont want to use the Jboss packeges, only the
> > JMX. I am able to deploy and install the MBean, but I get no
> > notification. Also the available examples from web are not
> > running. Has someone an idea? I am using jboss 3.2.1
> >
> > Thank you,
> > Juraj
> >
> > This is the MBean interface, which I want to use:
> >
> > public interface DPESAPSynchServiceMBean extends TimerMBean {
> >
> > public String getDesc();
> >
> > public void setPeriod(Integer period);
> > public Integer getPeriod();
> >
> > public void start();
> > public void stop();
> >
> > // public Integer addNotification(String type, String
> > message, Object userData, Date date);
> > }
> >
> > And this is the implementing bean:
> >
> > public class DPESAPSynchService extends Timer implements
> > DPESAPSynchServiceMBean,
> >
> > NotificationListener{
> >
> >
> > private MBeanServer lserver;
> >
> > public DPESAPSynchService(){
> > super();
> > System.out.println("starting Constructor");
> > lserver = (MBeanServer)
> > MBeanServerFactory.findMBeanServer(null).get(0);
> > System.out.println("mbeanserver: "+lserver);
> > }
> >
> > .....
> >
> > public synchronized void start(){
> > System.out.println("starting DPESAPSynchService");
> > try{
> > Set lBeans = lserver.queryMBeans(new
> > ObjectName("IKServices","service","DPESAPSynchService"),null);
> > if(lBeans.isEmpty()){
> > System.out.println("lbeans are empty: "+lBeans);
> > }else{
> > System.out.println("lbeans are not empty:
> > "+lBeans.size());
> > ObjectInstance lTimer = (ObjectInstance)
> > lBeans.iterator().next();
> > System.out.println("objectinstance timer: "+lTimer);
> > lserver.addNotificationListener(
> > lTimer.getObjectName(),
> > //new DPESAPSynchNotificationListener(),
> > this,
> > null,
> > null
> > );
> > System.out.println("listener registered");
> > System.out.println("object:
> "+lTimer.getObjectName());
> > System.out.println("object: "+lTimer.getClass());
> > Date lNext = new Date(new Date().getTime() +
> > Timer.ONE_MINUTE);
> > System.out.println("will call listener at "+lNext);
> >
> > Integer lOneMinuteTimer = (Integer) lserver.invoke(
> > lTimer.getObjectName(),
> > "addNotification",
> > new Object[]{
> > "IDoNotKnowWhatTypeIs",
> > "I call you with this timer",
> > null,
> > lNext,
> > },
> > new String[]{
> > "".getClass().getName(),
> > "".getClass().getName(),
> > "java.lang.Object",
> > Date.class.getName(),
> > }
> > );
> > System.out.println("return from add:
> > "+lOneMinuteTimer);
> > }
> > }catch(MalformedObjectNameException e){
> > System.out.println("Error: "+e);
> > }catch(InstanceNotFoundException e){
> > System.out.println("Error: "+e);
> > }catch(ReflectionException e){
> > System.out.println("Error: "+e);
> > }catch(MBeanException e){
> > System.out.println("Error: "+e);
> > }
> > }
> >
> >
> >
> > public Integer addNotification(String type, String
> > message, Object userData, Date date) {
> > Integer i = super.addNotification(type, message,
> > userData, date);
> > System.out.println("running addNotification in service");
> > System.out.println(type);
> > System.out.println(message);
> > System.out.println(userData);
> > System.out.println(date);
> > return i;
> > }
> > }
> >
> >
> > This is my configuration entry in my SAR file:
> >
> > <mbean code="com.tsystems.ik.ejb.wf.invest.DPESAPSynchService"
> > name="IKServices:service=DPESAPSynchService" >
> > </mbean>
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.Net email sponsored by: Free pre-built ASP.NET
> sites including
> > Data Reports, E-commerce, Portals, and Forums are available now.
> > Download today and enter to win an XBOX or Visual Studio .NET.
> > http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet
> _072303_01/01
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-user
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet
> _072303_01/01
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-user
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet
> _072303_01/01
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-user
>
MyTimerTrial.java
Description: MyTimerTrial.java
