I have one clustered-application with 2 nodes running in jboss 6.1.0.Final.
I have some stateless beans that need to execute some tasks at scheduled times. It is using EJB 3.1 timer service. Here is one of them:
@Stateless
public class MyBean implements MyBeanLocal,
MyBeanRemote {
@Schedule(hour = "1", persistent = false)
public void doStuff() { //my code }
}
Until here, this works perfectly.
But since i have 2 nodes i need the doStuff method to be executed only in one of them, so here is my META-INF/jboss.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss>
<enterprise-beans>
<session>
<ejb-name>MyBean</ejb-name>
<depends>jboss.ha:service=HASingletonDeployer,type=Barrier</depends>
</session>
</enterprise-beans>
</jboss>
When the server starts, i see that MyBean is created in ONLY one of the nodes.
installing bean: jboss.j2ee:ear=my-ear.ear,jar=my-jar-0.0.1-SNAPSHOT.jar,name=MyBean,service=EJB3
with dependencies:
and demands:
jboss-switchboard:appName=my-ear,module=my-module-0.0.1-SNAPSHOT,name=MyBean; Required: Create
jboss.ejb:service=EJBTimerService; Required: Described
jboss-injector:topLevelUnit=my-ear.ear,unit=my-jar-0.0.1-SNAPSHOT.jar,bean=MyBean; Required: Described
jboss.ha:service=HASingletonDeployer,type=Barrier; Required: Described
persistence.unit:unitName=my-ear.ear/another-jar-dao-0.0.1-SNAPSHOT.jar#my-entitymanager; Required: Described
and supplies:
...
Added bean(jboss.j2ee:ear=my-ear.ear,jar=my-jar-0.0.1-SNAPSHOT.jar,name=MyBean,service=EJB3) to KernelDeployment of: my-jar-0.0.1-SNAPSHOT.jar
But, with the dependency declared on META-INF/jboss.xml, the doStuff method is never executed. I tested removing the dependency from META-INF/jboss.xml and the method executes on the scheduled time, but it runs in the two nodes. My need is to create a scheduled method that runs in only one node of the cluster.
Update: If i do this on META-INF/jboss.xml:
<session>
<ejb-name>MyBean</ejb-name>
<!-- <depends>jboss.ha:service=HASingletonDeployer,type=Barrier</depends> -->
</session>
The scheduled method still dont run in any of the nodes.
But if i do this:
<!-- <session>
<ejb-name>MyBean</ejb-name>
<depends>jboss.ha:service=HASingletonDeployer,type=Barrier</depends>
</session> -->
The method run in the two nodes.
Anyone can help me? Thanks.