Hello,
I've written my first session bean that is
automatically called by the timer service
of JBoss. My question is:
How can I do to start the session bean
initialization just after the deployment of my
ear?

For now: I have to call a specific url (jsp) that
call a method of my session bean runAtlas():
<code-extract>
    public void runAtlas()
    throws RemoteException
    {
                if( listener == null )
                {
                    System.out.println( "### Launch the timer ###" );

                    // obtain the MBeanServer
                    lServer =
MBeanServer)MBeanServerFactory.findMBeanServer( null ).get( 0 );

            try
            {
                Set lBeans = lServer.queryMBeans(  new
bjectName( "DefaultDomain",
                                                               "service",
                                                               "timer"
                                                             ),
                                               null
                                            );

                if( !lBeans.isEmpty() )
                {
                    // Should be the first and only element
                    System.out.println( "### Timer service present! ###" +
Timer.ONE_MINUTE );
                    lTimer = (ObjectInstance)lBeans.iterator().next();

                    listener = new Listener();
                    lServer.addNotificationListener( lTimer.getObjectName(),
                                                     listener,
                                                     null, // No filter
                                                     null // No object
handback necessary
                                                   );

                    Date lNext = new Date( new Date().getTime() + 5000);
                    //Date lNext = new Date( new Date().getTime() +
Timer.ONE_HOUR );
                    atlasTimerRef = (Integer)lServer.invoke(
                        lTimer.getObjectName(),
                        "addNotification",
                        new Object[] { "IDoNotKnowWhatTypeIs",
                                       "I call you with this timer once",
                                       null, // No user object
                                       lNext, // In one minute from now
                                       new Long( 10000 )
                                       // , new Long( 10 )
                                     },
                        new String[]
                        {
                            "".getClass().getName(),
                            "".getClass().getName(),
                            "java.lang.Object",
                            Date.class.getName(),
                            Long.TYPE.getName()
                            // , Long.TYPE.getName()
                        }
                    );
                }
                else
                    System.out.println( "### Could not launch the timer,
service DefaultDomain:timer not installed! ###" );
            }
            catch( MalformedObjectNameException mone )
            {
                System.out.println( mone.getMessage() );
            }
            catch( InstanceNotFoundException infe )
            {
                System.out.println( infe.getMessage() );
            }
            catch( MBeanException mbe )
            {
                System.out.println( mbe.getMessage() );
            }
            catch( ReflectionException re )
            {
                System.out.println( re.getMessage() );
            }
        }
    }
</code-extract>

TIA
Loic


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to