0
votes

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" ?!

1
"A component named 'TimerHelper' is already defined in this module" - what makes you think this has to do with the Singleton annotation? It looks more like a problem of a particular class appearing on the classpath multiple times. What is inside the deployed war? Do you maybe have the class inside the war and inside a jar at the same time? - Gimby
there is actually no other class at all with the name "TimerHelper". I also changed the original-class to an other name to test that case, but still same problem, just the new name in the Exceptions. I think its the singleton annotation because usermanagement somehow tries to start a second instance of TimerHelper, but there is allready one existing. - Error 404
It's not Singleton that is causing it. Are you sure you don't have a Named class called TimerHelper, or a class in a different package with the same name? Did you do a clean build? If you moved the class from one package to another you could have the old one lingering in your deployment. - teacurran
In fact i really moved it once, but how can i solve this problem?Because i deleted the old class and also all other war files have no problem with that. - Error 404
By the way: If i do a File-Search in Eclipse for "TimerHelper" i really just can find this one class. And no other. And how i said: I tried to rename the TimerHelper class but still the same problem. - Error 404

1 Answers

1
votes

Did you solve this? In my case it seems that doing a server cleanup helped (in eclipse, right button on the server and push "clean") then choose a Full Publish.

Cheers Nekos