Restauration du Timer avant deploiement d'un EJB
Bonjour à tous,
Je déclare un Timer dans une méthode et j'attend l'exécution du Timer dans une autre méthode annoté @Timeout. Tout fonctionne sauf la restauration de mon Timer lors d'un reboot de mon AS.
Le problème est que lorsque le Stateless est redéployé, le Timer est expiré et il est donc automatiquement déclenché or le Stateless inject un EJB qui à ce moment n'a pas encore été déployé. J'ai donc une erreur et mon Timer n'est pas restauré...
Quelqu'un aurait-il une solution ?
Voici ma classe qui créer et gère le Timer :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
@Stateless
@WebService(name = "MyWebService_001", serviceName = "MyWebService_001")
public class MyWebService {
private static final Logger logger = Logger
.getLogger(MyWebService.class);
@EJB
private MyManagerRemote myManagerRemote;
@Resource
private TimerService timerService;
@Timeout
@WebMethod(exclude = true)
public void processTimer(Timer timer) {
if(logger.isTraceEnabled())
logger.trace("Blabla");
}
public Boolean processSync(
@WebParam(name = "externalId") Long externalId,
@WebParam(name = "control") ControlDTO controlDTO) {
try {
myManagerRemote.processSync(externalId, controlDTO);
if(logger.isTraceEnabled())
logger.trace("Création du timer");
timerService.createTimer(30000, null);
return Boolean.TRUE;
} catch (Exception e) {
logger.error("Erreur", e);
return Boolean.FALSE;
}
} |
Voici ici mon erreur plutot clair :
Code:
1 2 3
| 2012-01-26 16:32:16,627 INFO [org.jboss.ejb3.timerservice.mk2.task.TimerTask] (pool-21-thread-1) Timer: [id=0dbdfc03-fb0e-4326-a7cc-b9e46768fb37 timedObjectId=jboss.j2ee:ear=bss.deployment.banking.ear-0.0.1-SNAPSHOT.ear,jar=bss.module.banking.service.impl-0.0.1-SNAPSHOT.jar,name=MyWebService,service=EJB3 auto-timer?:false persistent?:true timerService=org.jboss.ejb3.timerservice.mk2.TimerServiceImpl@37fb87e4 initialExpiration=2012-01-26 16:31:39.663 intervalDuration(in milli sec)=0 nextExpiration=null timerState=IN_TIMEOUT will be retried
2012-01-26 16:32:16,627 INFO [org.jboss.ejb3.timerservice.mk2.task.TimerTask] (pool-21-thread-1) Retrying timeout for timer: [id=0dbdfc03-fb0e-4326-a7cc-b9e46768fb37 timedObjectId=jboss.j2ee:ear=bss.deployment.banking.ear-0.0.1-SNAPSHOT.ear,jar=bss.module.banking.service.impl-0.0.1-SNAPSHOT.jar,name=MyWebService,service=EJB3 auto-timer?:false persistent?:true timerService=org.jboss.ejb3.timerservice.mk2.TimerServiceImpl@37fb87e4 initialExpiration=2012-01-26 16:31:39.663 intervalDuration(in milli sec)=0 nextExpiration=null timerState=IN_TIMEOUT
2012-01-26 16:32:16,632 ERROR [org.jboss.ejb3.timerservice.mk2.task.TimerTask] (pool-21-thread-1) Error during retyring timeout for timer: [id=0dbdfc03-fb0e-4326-a7cc-b9e46768fb37 timedObjectId=jboss.j2ee:ear=bss.deployment.banking.ear-0.0.1-SNAPSHOT.ear,jar=bss.module.banking.service.impl-0.0.1-SNAPSHOT.jar,name=MyWebService,service=EJB3 auto-timer?:false persistent?:true timerService=org.jboss.ejb3.timerservice.mk2.TimerServiceImpl@37fb87e4 initialExpiration=2012-01-26 16:31:39.663 intervalDuration(in milli sec)=0 nextExpiration=null timerState=RETRY_TIMEOUT: javax.ejb.EJBException: org.jboss.injection.manager.spi.InjectionException: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: MyManager not bound]] |
Autre idée : changer d'architecture
Peut-être que les MDB correspondraient à ton besoin : tu envoies un message qui sera timestampé et pourra être interprété seulement après un délai fixé d'expiration "interne" contrôlé par le récepteur.
Si le MOM garantit que le message ne se perde pas (mode persistant), c'est bon.