How call EJB 3.0 in scheduler ?
fxmichaud Jan 16, 2007 3:40 AMHi,
I'm developping web application and I would like run a scheduling service at JBoss startup.
I'm using JBoss 4.0.5 + Seam 1.1. My Eclipse project has been generated by using Seam-Gen tools.
[resources/META-INF/scheduler-service.xml] file :
<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="org.jboss.varia.scheduler.Scheduler" name="task:service=Scheduler"> <attribute name="StartAtStartup">true</attribute> <attribute name="SchedulableClass">com.application.intranet.tasks.Task</attribute> <attribute name="SchedulableArguments">aa,123456789</attribute> <attribute name="SchedulableArgumentTypes">java.lang.String,long</attribute> <attribute name="InitialStartDate">NOW</attribute> <attribute name="SchedulePeriod">6000</attribute> <attribute name="InitialRepetitions">-1</attribute> <depends>jboss.j2ee:module=fmichaud.jar,service=EJB3</depends> </mbean> </server>
[resources/META-INF/jboss-app.xml] file :
<jboss-app> <loader-repository> seam.jboss.org:loader=fmichaud </loader-repository> <module> <service>META-INF/scheduler-service.xml</service> </module> </jboss-app>
My scheduled task class :
public class Task implements Schedulable { private final zLogger log = zLogger.getLogger(getClass()); private String name; private long value; /** Accounts business service EJB. */ @EJB private AccountsServiceImpl accountsService; public Task(String name, long value) { this.name = name; this.value = value; log.logBusinessEvent(LogLevel.INFO, "ctor, name: " + name + ", value: " + value); } public void perform(Date now, long remainingRepetitions) { Collection<Account> accountsList = accountsService.getEntries(); } }
I obtain next exception at JBoss startup :
09:35:53,066 ERROR [Scheduler$Listener] Handling a Scheduler call failed java.lang.NullPointerException at com.application.intranet.tasks.Task.perform(Task.java:72) at org.jboss.varia.scheduler.Scheduler$Listener.handleNotification(Scheduler.java:1251) at sun.reflect.GeneratedMethodAccessor57.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.jboss.mx.notification.NotificationListenerProxy.invoke(NotificationListenerProxy.java:153) at $Proxy46.handleNotification(Unknown Source) at javax.management.NotificationBroadcasterSupport.handleNotification(NotificationBroadcasterSupport.java:221) at javax.management.NotificationBroadcasterSupport.sendNotification(NotificationBroadcasterSupport.java:184) at javax.management.timer.Timer.sendNotification(Timer.java:1295) at javax.management.timer.Timer.notifyAlarmClock(Timer.java:1264) at javax.management.timer.TimerAlarmClock.run(Timer.java:1347) at java.util.TimerThread.mainLoop(Timer.java:512) at java.util.TimerThread.run(Timer.java:462)
In web application or with TestNG, EJB is running.
I tried to lookup jNDI EJB but nothing seems valid.
How to instantiate EJB 3.0 for calling from JBoss scheduler service ?
Thanks for any help.
Regards.