This content has been marked as final.
Show 4 replies
-
1. Re: Database Connection Failover Question
vickyk Apr 26, 2008 12:54 PM (in response to emmitt1219)"emmitt1219" wrote:
Now, my question is. When our primary db comes back up, is there a way for me to force the data source point back to the primary db?
You got to write the custom URLSelector which is possible only with jboss5 , here is the sample -ds.xml file which contains it
http://anonsvn.jboss.org/repos/jbossas/trunk/testsuite/src/resources/jca/ha/test-ha-xa-ds.xml
Have a look at this
http://anonsvn.jboss.org/repos/jbossas/trunk/connector/src/main/org/jboss/resource/adapter/jdbc/URLSelectorStrategy.java
You got to implement the algorithm which you want in custom implementation of URLSelectorStrategy class .
Have a look at the default implementation herepublic static class XADataSelector implements URLSelectorStrategy { private final List xaDataList; private int xaDataIndex; private XAData xaData; public XADataSelector(List xaDataList) { if(xaDataList == null || xaDataList.size() == 0) { throw new IllegalStateException("Expected non-empty list of XADataSource/URL pairs but got: " + xaDataList); } this.xaDataList = xaDataList; } public synchronized XAData getXAData() { if(xaData == null) { if(xaDataIndex == xaDataList.size()) { xaDataIndex = 0; } xaData = (XAData)xaDataList.get(xaDataIndex++); } return xaData; } public synchronized void failedXAData(XAData xads) { if(xads.equals(this.xaData)) { this.xaData = null; } } /* URLSelectorStrategy Implementation goes here*/ public List getCustomSortedUrls() { return xaDataList; } public void failedUrlObject(Object urlObject) { failedXAData((XAData)urlObject); } public List getAllUrlObjects() { return xaDataList; } public Object getUrlObject() { return getXAData(); } }
http://anonsvn.jboss.org/repos/jbossas/trunk/connector/src/main/org/jboss/resource/adapter/jdbc/xa/XAManagedConnectionFactory.java -
2. Re: Database Connection Failover Question
emmitt1219 Apr 26, 2008 2:49 PM (in response to emmitt1219)Thanks for the help!
How about JBoss 4? Is there any way to accomplish this on 4.0.4...? -
3. Re: Database Connection Failover Question
vickyk Apr 27, 2008 12:27 AM (in response to emmitt1219)"emmitt1219" wrote:
Thanks for the help!
How about JBoss 4? Is there any way to accomplish this on 4.0.4...?
Not without the code change it is not possible with 4.0.4 , you got to modify
http://anonsvn.jboss.org/repos/jbossas/tags/JBoss_4_0_4_GA/connector/src/main/org/jboss/resource/adapter/jdbc/xa/HAXAManagedConnectionFactory.java
Logically you can create a new resource adapter which would be similar to jboss-ha-local-jdbc.rar but with modified HAXAManagedConectionFactory implementation . But make sure that the changes you made are proper , it is risky unless you know what you are doing ;)
HA jdbc RA's were never designed for load balancing they are there for fail over . -
4. Re: Database Connection Failover Question
emmitt1219 Apr 27, 2008 1:56 AM (in response to emmitt1219)Got it. Thank you for your help!