i wrote a TimerHelper class which can receive Callables from other classes and tries to execute them. If an exception occurs, it waits some time and tries again. So other classes can export tasks that have to be done, but not exactly at the moment.
@Startup
@Singleton
public class TimerHelper{
private static final Logger LOGGER = Logger.getLogger(TimerHelper.class.getName());
private Callable<Void> task;
private int failureCounter = 0;
public TimerHelper(){
}
@Resource
private ManagedExecutorService executorService;
@Resource
private TimerService timerService;
public void setNewTimer(Callable<Void> task){
this.task = task;
timerService.createIntervalTimer(0, 5000, new TimerConfig());
}
@Timeout
public void timerMethod(Timer timer) {
if(failureCounter <10){
try{
Future<Void> future = executorService.submit(task);
future.get();
LOGGER.log(Level.INFO, "Did something");
failureCounter =0;
timer.cancel();
}catch(Exception e){
failureCounter++;
LOGGER.log(Level.WARNING, "Errored while doing something, will try again");
}
}else{
timer.cancel();
LOGGER.log(Level.SEVERE, "Tried to add something to Database several times, but failed. Please check the OpenRDF-Database");
}
}
}
This TimerHelper-class is in a API package to which a lot of other packages have a dependency in their POM.xml. Everything works fine except for one module "Usermanagement". I get allways this Exception when i try to deploy it to Wildfly 9:
14:56:19,125 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.deployment.unit."usermanagement.war".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."usermanagement.war".PARSE: WFLYSRV0153: Failed to process phase PARSE of deployment "usermanagement.war" at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:163) at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalArgumentException: WFLYEE0040: A component named 'TimerHelper' is already defined in this module at org.jboss.as.ee.component.EEModuleDescription.addComponent(EEModuleDescription.java:162) at org.jboss.as.ejb3.deployment.processors.EJBComponentDescriptionFactory.addComponent(EJBComponentDescriptionFactory.java:58) at org.jboss.as.ejb3.deployment.processors.SessionBeanComponentDescriptionFactory.processSessionBeans(SessionBeanComponentDescriptionFactory.java:169) at org.jboss.as.ejb3.deployment.processors.SessionBeanComponentDescriptionFactory.processAnnotations(SessionBeanComponentDescriptionFactory.java:98) at org.jboss.as.ejb3.deployment.processors.AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.processAnnotations(AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.java:57) at org.jboss.as.ejb3.deployment.processors.AbstractDeploymentUnitProcessor.deploy(AbstractDeploymentUnitProcessor.java:81) at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:156) ... 5 more
14:56:19,126 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 38) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "usermanagement.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"usermanagement.war\".PARSE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"usermanagement.war\".PARSE: WFLYSRV0153: Failed to process phase PARSE of deployment \"usermanagement.war\" Caused by: java.lang.IllegalArgumentException: WFLYEE0040: A component named 'TimerHelper' is already defined in this module"}} 14:56:19,126 ERROR [org.jboss.as.server] (management-handler-thread - 38) WFLYSRV0021: Deploy of deployment "usermanagement.war" was rolled back with the following failure message: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"usermanagement.war\".PARSE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"usermanagement.war\".PARSE: WFLYSRV0153: Failed to process phase PARSE of deployment \"usermanagement.war\" Caused by: java.lang.IllegalArgumentException: WFLYEE0040: A component named 'TimerHelper' is already defined in this module"}}
I'm pretty sure it's because of the "@Singleton" annotation, but i can't figure out how to solve this problem. Maybe its also because usermanagement has a dependency to "api" and "aaa", and "aaa" also have a dependency to "api" ?!