Author: sumedha
Date: Thu Jan 17 13:02:27 2008
New Revision: 12435

Log:

Implemented a mechanism to restore data services gone faulty due to database 
connection being not avaible @ the time of deployment.

Added:
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/FaultyServiceRectifier.java
Modified:
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
  (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
  Thu Jan 17 13:02:27 2008
@@ -23,8 +23,11 @@
 import java.io.StringWriter;
 import java.sql.Connection;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Timer;
+import java.util.TimerTask;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
@@ -64,6 +67,7 @@
     private String repoDir = null;
 
     private String extension = null;
+    private Config config; 
 
     private static HashMap conversionType = null;
 
@@ -150,6 +154,11 @@
             if (serviceStatus.startsWith("Error:")) {
                 
axisConfig.getFaultyServices().put(deploymentFileData.getFile().getAbsolutePath(),
                         serviceStatus);
+                //Registering a timer task to re-establish the database 
connection 
+                //& deploy the service again
+                       TimerTask faultyServiceRectifier = new 
FaultyServiceRectifier(deploymentFileData,configCtx,config);
+                       Timer timer = new Timer();
+                       timer.scheduleAtFixedRate(faultyServiceRectifier, new 
Date(),new Long(1000*60).longValue());
             }
         }
     }
@@ -218,7 +227,7 @@
             reqProps.add(DBConstants.DB_CONFIG_ELEMENT);
             
             //load parameters in <config> section 
-            Config config = getConfigProperties(connection);
+            config = getConfigProperties(connection);
             axisService.addParameter(DBConstants.CONNECTION_CONFIG , config);
 
             for (int i = 0; i < reqProps.size(); i++) {

Added: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/FaultyServiceRectifier.java
==============================================================================
--- (empty file)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/FaultyServiceRectifier.java
      Thu Jan 17 13:02:27 2008
@@ -0,0 +1,63 @@
+package org.wso2.ws.dataservice;
+
+import java.sql.Connection;
+import java.util.TimerTask;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.deployment.repository.util.DeploymentFileData;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.ws.dataservice.beans.Config;
+
+public class FaultyServiceRectifier extends TimerTask {
+       private static final Log log = LogFactory
+                       .getLog(FaultyServiceRectifier.class);
+       private ConfigurationContext configurationCtx = null;
+       private Config config = null;
+       private DeploymentFileData deploymentFileData;
+
+       public FaultyServiceRectifier(DeploymentFileData deploymentData,
+                       ConfigurationContext configCtx, Config 
dataServiceConfigSection) {
+               configurationCtx = configCtx;
+               deploymentFileData = deploymentData;
+               config = dataServiceConfigSection;
+       }
+
+       public boolean cancel() {
+               return super.cancel();
+       }
+
+       public void run() {
+               Connection dbConnection;
+               String deploymentFileName = "";
+               try {
+                       deploymentFileName = deploymentFileData.getFile()
+                                       .getAbsolutePath();
+                       log.info("Trying to re-establish fautly database 
connection for data services :"
+                                       +deploymentFileName);
+                       dbConnection = 
DBUtils.createConnection(deploymentFileName, config);
+                       if (dbConnection != null) {
+                               log.info("Database connection successful. 
Removing "
+                                               + deploymentFileName + " from 
Fault Service list.");
+                               
configurationCtx.getAxisConfiguration().getFaultyServices()
+                                               .remove(deploymentFileName);
+                               //cancel the timer task
+                               this.cancel();
+                               //send the dataservice configuration through 
re-deployement
+                               DBDeployer dbDeployer = new DBDeployer();
+                               dbDeployer.init(configurationCtx);
+                               dbDeployer.deploy(deploymentFileData);
+                       } else {
+                               log.error("Database connection re-establishment 
for "
+                                               + deploymentFileName + " 
failed.Retrying...");
+                       }
+               } catch (AxisFault e) {
+                       log     .error("Error occurred while trying to 
re-establish database connection for "
+                                       +deploymentFileName,
+                                       e);
+               }
+
+       }
+
+}

_______________________________________________
Wsas-java-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/wsas-java-dev

Reply via email to