[jboss-user] [JCA/JBoss] - Re: Database Connection Failover Question

vickyk do-not-reply at jboss.com
Sat Apr 26 12:54:38 EDT 2008


"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 here 
 public 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

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4147020#4147020

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4147020



More information about the jboss-user mailing list