[jboss-user] [Clustering/JBoss] - Running a task in ony one node in cluster
tpawankumar
do-not-reply at jboss.com
Fri Apr 4 08:54:32 EDT 2008
Hi All,
I have deployed an application in cluster environment.I want only one node to execute this task.If this node goes down i want another node to execute the task.I have read in jboss docs there were HASingletons for this.
I have implemented it but could not succeed.I have used Jboss AS 4.2.1 GA.
I have modified run.bat with following system property
"-Djboss.partition.name=DefaultPartition".After that i have started two nodes(no port conflict different machines).
I have created java files with the following code:
<jboss>
|
| <enterprise-beans>
|
| <session>
|
| <ejb-name>ConfigServiceBean</ejb-name>
|
| <jndi-name>ConfigServiceBean</jndi-name>
|
| <clustered>True</clustered>
|
| <cluster-config>
|
| <partition-name>DefaultPartition</partition-name>
|
| <home-load-balance-policy>org.jboss.ha.framework.interfaces.RoundRobin</home-load-balance-policy>
|
| <bean-load-balance-policy>org.jboss.ha.framework.interfaces.RoundRobin</bean-load-balance-policy>
|
| </cluster-config>
|
| </session>
|
| </enterprise-beans>
|
| </jboss>
|
|
| package com.covad.scheduler;
|
|
| import java.util.Date;
| import org.jboss.varia.scheduler.Schedulable;
| import org.jboss.system.ServiceMBeanSupport;
|
|
| import org.apache.log4j.Logger;
|
| public class HeartBeat extends ServiceMBeanSupport implements HeartBeatMBean
| {
| private static final Logger log = Logger.getLogger(HeartBeat.class);
|
| private String name;
| private long value;
|
| public HeartBeat()
| {
| this.name = "pavan";
| this.value = 5;
| log.info("actor, name: " + name + ", value: " + value);
| }
|
| public void perform()
| {
| log.info("pavan in perform method");
| }
|
| }
This is my management interface:
package com.covad.scheduler;
|
| import org.jboss.system.ServiceMBean;
|
|
| public interface HeartBeatMBean extends ServiceMBean
| {
|
| public void perform();
|
|
| }
and this is my jboss-service.xml:
<?xml version="1.0" encoding="UTF-8"?>
| <server>
|
| <mbean code="org.jboss.varia.scheduler.ScheduleManager"
| name="jboss:service=ScheduleManager">
| <attribute name="StartAtStartup">true</attribute>
| <attribute name="FixedRate">true</attribute>
| </mbean>
|
| <mbean code="com.covad.scheduler.HeartBeat"
| name="com.covad:service=HeartBeat">
| </mbean>
| <mbean code="org.jboss.varia.scheduler.SingleScheduleProvider"
| name="jboss:service=SingleScheduleProvider">
| <depends>jboss.ha:service=HASingletonDeployer,type=Barrier</depends>
| <depends optional-attribute-name="ScheduleManagerName">jboss:service=ScheduleManager</depends>
| <depends optional-attribute-name="TargetName">com.covad:service=HeartBeat</depends>
| <attribute name="TargetMethod">perform()</attribute>
| <attribute name="DateFormat"></attribute>
| <attribute name="StartDate">NOW</attribute>
| <attribute name="Period">10000</attribute>
| <attribute name="Repetitions">-1</attribute>
| </mbean>
| </server>
|
|
and depoyed the sar with jar having ejb i.e stateless session bean and i have jboss.xml with following contents
<jboss>
|
| <enterprise-beans>
|
| <session>
|
| <ejb-name>ConfigServiceBean</ejb-name>
|
| <jndi-name>ConfigServiceBean</jndi-name>
|
| <clustered>True</clustered>
|
| <cluster-config>
|
| <partition-name>DefaultPartition</partition-name>
|
| <home-load-balance-policy>org.jboss.ha.framework.interfaces.RoundRobin</home-load-balance-policy>
|
| <bean-load-balance-policy>org.jboss.ha.framework.interfaces.RoundRobin</bean-load-balance-policy>
|
| </cluster-config>
|
| </session>
|
| </enterprise-beans>
|
| </jboss>
|
and i have dployed the sar in node1 in all/deploy and node2 in all/deploy.
But the perform() method is getting executed in both the nodes.I want only one node to get executed and if that node goes down another node should get executed.
I have tried with 'HASingleton' attribute also.
following are the contents of jboss-service.xml
| <?xml version="1.0" encoding="UTF-8"?>
| <server>
| <mbean code="org.jboss.varia.scheduler.ScheduleManager"
| name="jboss:service=ScheduleManager">
| <attribute name="StartAtStartup">true</attribute>
| <attribute name="FixedRate">true</attribute>
| </mbean>
|
| <mbean code="com.covad.scheduler.HeartBeat"
| name="com.covad:service=HeartBeat">
| </mbean>
| <mbean code="org.jboss.varia.scheduler.SingleScheduleProvider"
| name="jboss:service=HASingleScheduleProvider">
| <depends>jboss:service=DefaultPartition</depends>
| <depends>jboss:service=ScheduleManager</depends>
| <depends>com.covad:service=HeartBeat</depends>
| <attribute name="HASingleton">true</attribute>
| <attribute name="ScheduleManagerName">jboss:service=ScheduleManager</attribute>
| <attribute name="TargetName">com.covad:service=HeartBeat</attribute>
| <attribute name="TargetMethod">perform()</attribute>
| <attribute name="DateFormat"></attribute>
| <attribute name="StartDate">NOW</attribute>
| <attribute name="Period">10000</attribute>
| <attribute name="Repetitions">-1</attribute>
| </mbean>
| </server>
|
It is throwing the following exception
| 18:18:30,755 INFO [HeartBeat] actor, name: pavan, value: 5
| 18:18:30,755 INFO [ServiceConfigurator] Problem configuring service jboss:servi
| ce=HASingleScheduleProvider
| org.jboss.deployment.DeploymentException: No Attribute found with name: HASingle
| ton
| at org.jboss.system.ServiceConfigurator.configure(ServiceConfigurator.ja
| va:318)
| at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigura
| tor.java:460)
| at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java
| :171)
| at org.jboss.system.ServiceController.install(ServiceController.java:226
| )
| at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
| sorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatch
| er.java:155)
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
| at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.
| java:264)
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
| at $Proxy4.install(Unknown Source)
| at org.jboss.deployment.SARDeployer.create(SARDeployer.java:249)
| at org.jboss.deployment.MainDeployer.create(MainDeployer.java:969)
| at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:818)
| at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
| at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
| sorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatch
| er.java:155)
| at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
| at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractIntercept
| or.java:133)
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
| at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelM
| BeanOperationInterceptor.java:142)
| at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
| at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.
| java:264)
| at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
| at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
| at $Proxy9.deploy(Unknown Source)
| at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymen
| tScanner.java:421)
| at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentS
| canner.java:634)
| at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.
| doScan(AbstractDeploymentScanner.java:263)
| at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.
| loop(AbstractDeploymentScanner.java:274)
| at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.
| run(AbstractDeploymentScanner.java:225)
|
Please let me know if i am missing something.
Please help me.
Thanks,
Pavan.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4141636#4141636
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4141636
More information about the jboss-user
mailing list