Should the fragments in the jboss docu be put together this way?
The variable lOneMinuteTimer of course can not be accessed this way. Did
anybody have had luck making it work?
What does best practice for setting up something like a clean up job in a
session bean look like?
Best regards,
Carsten


public void addJob() {
        List lServers = MBeanServerFactory.findMBeanServer(null);
        MBeanServer lServer = (MBeanServer) lServers.get(0);
        ObjectInstance lTimer = null;

        try {
            lTimer = lServer.getObjectInstance(new
ObjectName("DefaultDomain", "service", "timer"));
        } catch (MalformedObjectNameException ex) {
            throw new EJBException("Unable to get TimerMBean: " +
ex.toString());
        } catch (InstanceNotFoundException ex) {
            throw new EJBException("Unable to get TimerMBean: " +
ex.toString());
        }

        java.util.Date lNext = new java.util.Date(new
java.util.Date().getTime() +
                javax.management.timer.Timer.ONE_MINUTE);
        Integer lOneMinuteTimer = null;

        try {
            lOneMinuteTimer = (Integer)
lServer.invoke(lTimer.getObjectName(), "addNotification",
                    new Object[] {
                        "IDoNotKnowWhatTypeIs", "I call you with this timer
once", null, lNext,
                    },
                    new String[] {
                        "".getClass().getName(), "".getClass().getName(),
"java.lang.Object",
                        java.util.Date.class.getName()
                    });
        } catch (InstanceNotFoundException ex) {
            throw new EJBException("Unable to invoke TimerMBean: " +
ex.toString());
        } catch (MBeanException ex) {
            throw new EJBException("Unable to invoke TimerMBean: " +
ex.toString());
        } catch (ReflectionException ex) {
            throw new EJBException("Unable to invoke TimerMBean: " +
ex.toString());
        }

        lServer.addNotificationListener(lTimer.getObjectName(),
            new NotificationListener() {
                public void handleNotification(Notification pNotification,
Object pHandback) {
                    System.out.println("You got a Notification: " +
pNotification);
                }
            },
            new NotificationFilter() {
                public boolean isNotificationEnabled(Notification
pNotification) {
                    if (pNotification instanceof TimerNotification) {
                        TimerNotification lTimerNotification =
(TimerNotification) pNotification;

                        return
lTimerNotification.getNotificationID().equals(lOneMinuteTimer);
                    }

                    return false;
                }
            }, null);
    }





-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to