synapse-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hira...@apache.org
Subject svn commit: r814515 - in /synapse/branches/1.3/modules: core/src/main/java/org/apache/synapse/ core/src/main/java/org/apache/synapse/config/ core/src/main/java/org/apache/synapse/startup/quartz/ tasks/src/main/java/org/apache/synapse/task/
Date Mon, 14 Sep 2009 08:16:41 GMT
Author: hiranya
Date: Mon Sep 14 08:16:40 2009
New Revision: 814515

URL: http://svn.apache.org/viewvc?rev=814515&view=rev
Log:
* Refactored the tasks module (renamed TaskHelper to SynapseTaskManager)
* Fixed a bug in the SimpleQuartz class (bug caused tasks to be not cleaned up properly)
* Removed some unnecessary code in the SynapseConfiguration class (removed the reference to
the task repository and the associated getter method)


Added:
    synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskManager.java
      - copied, changed from r812854, synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java
Removed:
    synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java
Modified:
    synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java
    synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
    synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java

Modified: synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java?rev=814515&r1=814514&r2=814515&view=diff
==============================================================================
--- synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java
(original)
+++ synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/Axis2SynapseController.java
Mon Sep 14 08:16:40 2009
@@ -132,7 +132,7 @@
         
         addDefaultBuildersAndFormatters(configurationContext.getAxisConfiguration());
         deployMediatorExtensions();
-        initTaskHelper(serverContextInformation);
+        initTaskManager(serverContextInformation);
         initDataSourceHelper(serverContextInformation);
         initSharedSecretCallbackHandlerCache(serverContextInformation);
         initialized = true;
@@ -227,7 +227,7 @@
         transportHelper.pauseSenders();
 
         // put tasks on hold
-        TaskHelper.getInstance().pauseAll();
+        SynapseTaskManager.getInstance().pauseAll();
         
         log.info("Entered maintenence mode");
     }
@@ -244,7 +244,7 @@
         transportHelper.resumeSenders();
 
         // resume tasks
-        TaskHelper.getInstance().resumeAll();
+        SynapseTaskManager.getInstance().resumeAll();
 
         log.info("Resumed normal operation from maintenence mode");
     }
@@ -255,8 +255,8 @@
     public void stop() {
         try {
             // stop tasks
-            if (TaskHelper.getInstance().isInitialized()) {
-                TaskHelper.getInstance().cleanup();
+            if (SynapseTaskManager.getInstance().isInitialized()) {
+                SynapseTaskManager.getInstance().cleanup();
             }
 
             // stop the listener manager
@@ -395,7 +395,7 @@
         }
         
         addServerIPAndHostEnrties();
-        
+
         return synapseConfiguration;
     }
 
@@ -448,7 +448,7 @@
                 log.info("Waiting for: " + pendingCallbacks + " callbacks/replies..");
             }
 
-            int runningTasks = TaskHelper.getInstance().getTaskScheduler().getRunningTaskCount();
+            int runningTasks = SynapseTaskManager.getInstance().getTaskScheduler().getRunningTaskCount();
             if (runningTasks > 0) {
                 log.info("Waiting for : " + runningTasks + " tasks to complete..");
             }
@@ -669,16 +669,16 @@
     }
 
     /**
-     *  Initialize TaskHelper - with any existing  TaskDescriptionRepository and TaskScheduler
+     *  Initialize Task Manager - with any existing  TaskDescriptionRepository and TaskScheduler
      *  or without those
      * @param serverContextInformation  ServerContextInformation instance
      */
-    private void initTaskHelper(ServerContextInformation serverContextInformation) {
+    private void initTaskManager(ServerContextInformation serverContextInformation) {
 
-        TaskHelper taskHelper = TaskHelper.getInstance();
-        if (taskHelper.isInitialized()) {
+        SynapseTaskManager synapseTaskManager = SynapseTaskManager.getInstance();
+        if (synapseTaskManager.isInitialized()) {
             if (log.isDebugEnabled()) {
-                log.debug("TaskHelper has been already initialized.");
+                log.debug("SynapseTaskManager has been already initialized.");
             }
             return;
         }
@@ -687,20 +687,15 @@
             serverContextInformation.getProperty(TaskConstants.TASK_DESCRIPTION_REPOSITORY);
         Object taskScheduler = serverContextInformation.getProperty(TaskConstants.TASK_SCHEDULER);
 
-        if (repo instanceof TaskDescriptionRepository && taskScheduler instanceof
TaskScheduler) {
-            taskHelper.init((TaskDescriptionRepository) repo, (TaskScheduler) taskScheduler);
-        } else {
+        if (repo != null && !(repo instanceof TaskDescriptionRepository)) {
+            handleFatal("Invalid property value specified for TaskDescriptionRepository");
+        }
 
-            if (repo == null && taskScheduler == null) {
-                taskHelper.init(
-                        TaskDescriptionRepositoryFactory.getTaskDescriptionRepository(
-                                TaskConstants.TASK_DESCRIPTION_REPOSITORY),
-                        TaskSchedulerFactory.getTaskScheduler(TaskConstants.TASK_SCHEDULER));
-            } else {
-                handleFatal("Invalid property values for " +
-                        "TaskDescriptionRepository or / and TaskScheduler ");
-            }
+        if (taskScheduler != null && !(taskScheduler instanceof TaskScheduler)) {
+            handleFatal("Invalid property value specified for TaskScheduler");
         }
+
+        synapseTaskManager.init((TaskDescriptionRepository) repo, (TaskScheduler) taskScheduler);
     }
 
     private void addDefaultBuildersAndFormatters(AxisConfiguration axisConf) {

Modified: synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?rev=814515&r1=814514&r2=814515&view=diff
==============================================================================
--- synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
(original)
+++ synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
Mon Sep 14 08:16:40 2009
@@ -26,10 +26,7 @@
 import org.apache.synapse.*;
 import org.apache.synapse.eventing.SynapseEventSource;
 import org.apache.synapse.commons.datasource.DataSourceHelper;
-import org.apache.synapse.task.TaskDescriptionRepository;
-import org.apache.synapse.task.TaskDescriptionRepositoryFactory;
-import org.apache.synapse.task.TaskScheduler;
-import org.apache.synapse.task.TaskSchedulerFactory;
+import org.apache.synapse.task.*;
 import org.apache.synapse.config.xml.MediatorFactoryFinder;
 import org.apache.synapse.config.xml.endpoints.XMLToEndpointMapper;
 import org.apache.synapse.core.SynapseEnvironment;
@@ -102,10 +99,6 @@
     /** Hold reference to the Axis2 ConfigurationContext */
     private AxisConfiguration axisConfiguration = null;
     
-    private final TaskDescriptionRepository taskDescriptionRepository = 
-            TaskDescriptionRepositoryFactory.getTaskDescriptionRepository(
-                    SynapseConstants.SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY);     
  
-    
     /**
      * Save the path to the configuration file loaded, to save it later if
      * required
@@ -942,16 +935,12 @@
         for (ManagedLifecycle stp : startups.values()) {
             stp.destroy();
         }
-        
-        TaskScheduler taskScheduler = TaskSchedulerFactory.getTaskScheduler(
-                SynapseConstants.SYNAPSE_STARTUP_TASK_SCHEDULER);
+
+        SynapseTaskManager synapseTaskManager = SynapseTaskManager.getInstance();
+        TaskScheduler taskScheduler = synapseTaskManager.getTaskScheduler();
         if (taskScheduler != null && taskScheduler.isInitialized()) {
             taskScheduler.shutDown();
         }
-
-        if (taskDescriptionRepository != null) {
-            taskDescriptionRepository.clear();
-        }
         
         // clear session information used for SA load balancing
         try {
@@ -1023,10 +1012,6 @@
         throw new SynapseException(msg);
     }
 
-    public TaskDescriptionRepository getTaskDescriptionRepository() {
-        return taskDescriptionRepository;
-    }
-
     /**
      * Add an event source to the configuration. If an event source already exists by the
      * specified name a runtime exception is thrown.

Modified: synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java?rev=814515&r1=814514&r2=814515&view=diff
==============================================================================
--- synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
(original)
+++ synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
Mon Sep 14 08:16:40 2009
@@ -21,7 +21,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.config.SynapseConfigUtils;
 import org.apache.synapse.config.SynapseConfiguration;
@@ -49,7 +48,7 @@
 
     private TaskDescription taskDescription;
 
-    private final TaskHelper taskHelper = TaskHelper.getInstance();
+    private final SynapseTaskManager synapseTaskManager = SynapseTaskManager.getInstance();
 
     public QName getTagQName() {
         return SimpleQuartzFactory.TASK;
@@ -64,15 +63,15 @@
             return;
         }
 
-        if (taskHelper.isInitialized()) {
+        if (synapseTaskManager.isInitialized()) {
 
-            TaskScheduler taskScheduler = taskHelper.getTaskScheduler();
+            TaskScheduler taskScheduler = synapseTaskManager.getTaskScheduler();
 
             if (taskScheduler != null && taskScheduler.isInitialized()) {
                 taskScheduler.deleteTask(taskDescription.getName(), taskDescription.getGroup());
             }
 
-            TaskDescriptionRepository repository = taskHelper.getTaskDescriptionRepository();
+            TaskDescriptionRepository repository = synapseTaskManager.getTaskDescriptionRepository();
             if (repository != null) {
                 repository.removeTaskDescription(taskDescription.getName());
             }
@@ -82,22 +81,19 @@
     public void init(SynapseEnvironment synapseEnvironment) {
 
         if (taskDescription == null) {
-            handleException("TaskDescription is null");
+            handleException("Error while initializing the startup. TaskDescription is null.");
         }
 
         SynapseConfiguration synapseConfiguration = synapseEnvironment.getSynapseConfiguration();
 
-        if (!taskHelper.isInitialized()) {
-            taskHelper.init(
-                    TaskDescriptionRepositoryFactory.getTaskDescriptionRepository(
-                            TaskConstants.TASK_DESCRIPTION_REPOSITORY),
-                    TaskSchedulerFactory.getTaskScheduler(TaskConstants.TASK_SCHEDULER));
+        if (!synapseTaskManager.isInitialized()) {
+            synapseTaskManager.init(null, null);
         }
 
-        TaskDescriptionRepository repository = taskHelper.getTaskDescriptionRepository();
+        TaskDescriptionRepository repository = synapseTaskManager.getTaskDescriptionRepository();
 
         if (repository == null) {
-            handleException("Task Description Repository can not found");
+            handleException("Task Description Repository cannot be found");
         }
 
         repository.addTaskDescription(taskDescription);
@@ -112,7 +108,7 @@
                 thisServerName = addr.getHostName();
 
             } catch (UnknownHostException e) {
-                log.warn("Could not get local host name", e);
+                log.warn("Could not get the host name", e);
             }
 
             if (thisServerName == null || thisServerName.equals("")) {
@@ -138,8 +134,7 @@
 
         try {
 
-            TaskScheduler taskScheduler = TaskSchedulerFactory.getTaskScheduler(
-                    SynapseConstants.SYNAPSE_STARTUP_TASK_SCHEDULER);
+            TaskScheduler taskScheduler = synapseTaskManager.getTaskScheduler();
             if (taskScheduler != null) {
                 if (!taskScheduler.isInitialized()) {
                     taskScheduler.init(synapseConfiguration.getProperties());
@@ -148,7 +143,7 @@
             } else {
                 if (log.isDebugEnabled()) {
                     log.debug("TaskScheduler cannot be found for :" +
-                            SynapseConstants.SYNAPSE_STARTUP_TASK_SCHEDULER + " , " +
+                            TaskConstants.TASK_SCHEDULER + " , " +
                             "therefore ignore scheduling of Task  " + taskDescription);
                 }
             }

Copied: synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskManager.java
(from r812854, synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java)
URL: http://svn.apache.org/viewvc/synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskManager.java?p2=synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskManager.java&p1=synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java&r1=812854&r2=814515&rev=814515&view=diff
==============================================================================
--- synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java
(original)
+++ synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskManager.java
Mon Sep 14 08:16:40 2009
@@ -25,28 +25,33 @@
 import org.apache.synapse.commons.SynapseCommonsException;
 
 /**
- * Helper class to a share Scheduler and  TaskDescriptionRepository with in a single class
space
+ * Helper class to a share Scheduler and  TaskDescriptionRepository within a single class
space
  */
-public class TaskHelper {
+public class SynapseTaskManager {
+
+    private static final Log log = LogFactory.getLog(SynapseTaskManager.class);
+
+    private static SynapseTaskManager INSTANCE = new SynapseTaskManager();
 
-    private static final Log log = LogFactory.getLog(TaskHelper.class);
-    private static TaskHelper ourInstance = new TaskHelper();
     private TaskDescriptionRepository taskDescriptionRepository;
     private TaskScheduler taskScheduler;
     private boolean initialized = false;
 
-    public static TaskHelper getInstance() {
-        return ourInstance;
+    public static SynapseTaskManager getInstance() {
+        return INSTANCE;
     }
 
     /**
-     * Initialize with given TaskDescriptionRepository and TaskScheduler instances .
-     * if these are null , new instances will be created.
+     * Initialize the task manager instance with the given task description repository
+     * and the task scheduler. If any of these arguments are null new instances will
+     * be created. Note that this method does not initialize the actual task scheduler
+     * instance. It is up to the task manager clients to make sure that is initialized.
      *
      * @param taskDescriptionRepository TaskDescriptionRepository  instance
      * @param taskScheduler             TaskScheduler instance
      */
-    public void init(TaskDescriptionRepository taskDescriptionRepository, TaskScheduler taskScheduler)
{
+    public void init(TaskDescriptionRepository taskDescriptionRepository,
+                     TaskScheduler taskScheduler) {
 
         if (taskDescriptionRepository != null) {
             this.taskDescriptionRepository = taskDescriptionRepository;



Mime
View raw message