I setup 2 cq instances and cluster them. In my global.jsp file which is included at the beginning of my page, a DataSourcePool object is created, for the sake of getting RDBMS connection from JDBC connection pool in OSGI console:
// get DataSourcePool
DataSourcePool dataSourcePool = sling.getService(DataSourcePool.class);
if(null == DBUtils.getDataSourcePool())
Here comes codes in DBUtils:
public class DBUtils
private static DataSourcePool DSP_SERVICE;
private static final Logger log = LoggerFactory.getLogger(DBUtils.class);
private static final String _DATA_SROUCE_STRING = "datasourceName";
public static Connection getDBConnection() throws DataSourceNotFoundException,
DataSource ds = null;
if (DSP_SERVICE !=null)
log.info("DSP_SERVICE is not null");
log.info("DSP_SERVICE is null");
ds = (DataSource) DSP_SERVICE
connection = ds.getConnection();
catch (Exception e)
public static DataSourcePool getDataSourcePool()
public static void setDataSourcePool(DataSourcePool dsp)
DSP_SERVICE = dsp;
Everything works fine if CQ cluster failover doesn't happen. The case is, when CQ cluster failover, exception is caught and after debugging I found the DSP_SERVICE is null:
1. User browse the page, the global.jsp is executed when page is rendering, DSP_SERVICE value is set (which is not null at this point);
2. After the page rendered, CQ Master is down, the orignal CQ slave will become master and continue provide service to requests.
3. Then user trigger an event on the page (clicking a form submit button), which will call DBUtils.getDBConnection().
4. Exception is caught, DSP_SERVICE is null. Error on page.
5. User refresh the page, the global.jsp is executed again and DSP_SERVICE gets it value. All things go fine.
For system persistency I have to make the CQ cluster failover transparent to user. Is it a cq cluster bug or there is something i miss? Would you provide solution or ideas to solve this problem?