synapse-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hira...@apache.org
Subject svn commit: r817502 - 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 Tue, 22 Sep 2009 04:45:44 GMT
Author: hiranya
Date: Tue Sep 22 04:45:43 2009
New Revision: 817502

URL: http://svn.apache.org/viewvc?rev=817502&view=rev
Log:
Refactored and improved the code for tasks

* Removed the singleton pattern in the SynapseTaskManager
* SynapseConfiguration is used to store the SynapseTaskManager object and share it among modules
(all modules should look to get the SynapseTaskManager from the SynapseConfiguration. If it
is not there it should be considered an error) - This guarantees proper initialization and
clean up in all environments, including OSGi platforms
* Proper initialization of the task manager at Axis2SynapseController



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
    synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskManager.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=817502&r1=817501&r2=817502&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
Tue Sep 22 04:45:43 2009
@@ -69,6 +69,9 @@
     /** The Axis2 listener Manager */
     private ListenerManager listenerManager;
 
+    /** The Synapse task manager which contains the task scheduler and the task repository
*/
+    private SynapseTaskManager synapseTaskManager;
+
     /** The Axis2 configuration context used by Synapse */
     private ConfigurationContext configurationContext;
 
@@ -227,7 +230,9 @@
         transportHelper.pauseSenders();
 
         // put tasks on hold
-        SynapseTaskManager.getInstance().pauseAll();
+        if (synapseTaskManager != null && synapseTaskManager.isInitialized()) {
+            synapseTaskManager.pauseAll();
+        }
         
         log.info("Entered maintenence mode");
     }
@@ -244,7 +249,9 @@
         transportHelper.resumeSenders();
 
         // resume tasks
-        SynapseTaskManager.getInstance().resumeAll();
+        if (synapseTaskManager != null && synapseTaskManager.isInitialized()) {
+            synapseTaskManager.resumeAll();
+        }
 
         log.info("Resumed normal operation from maintenence mode");
     }
@@ -255,8 +262,8 @@
     public void stop() {
         try {
             // stop tasks
-            if (SynapseTaskManager.getInstance().isInitialized()) {
-                SynapseTaskManager.getInstance().cleanup();
+            if (synapseTaskManager != null && synapseTaskManager.isInitialized())
{
+                synapseTaskManager.cleanup();
             }
 
             // stop the listener manager
@@ -396,6 +403,10 @@
         
         addServerIPAndHostEnrties();
 
+        if (synapseTaskManager != null && synapseTaskManager.isInitialized()) {
+            synapseConfiguration.setTaskManager(synapseTaskManager);
+        }
+
         return synapseConfiguration;
     }
 
@@ -448,9 +459,12 @@
                 log.info("Waiting for: " + pendingCallbacks + " callbacks/replies..");
             }
 
-            int runningTasks = SynapseTaskManager.getInstance().getTaskScheduler().getRunningTaskCount();
-            if (runningTasks > 0) {
-                log.info("Waiting for : " + runningTasks + " tasks to complete..");
+            int runningTasks = 0;
+            if (synapseTaskManager != null && synapseTaskManager.isInitialized())
{
+                runningTasks = synapseTaskManager.getTaskScheduler().getRunningTaskCount();
+                if (runningTasks > 0) {
+                    log.info("Waiting for : " + runningTasks + " tasks to complete..");
+                }
             }
 
             // it is safe to stop if all used listener threads, callbacks and tasks are zero
@@ -675,13 +689,7 @@
      */
     private void initTaskManager(ServerContextInformation serverContextInformation) {
 
-        SynapseTaskManager synapseTaskManager = SynapseTaskManager.getInstance();
-        if (synapseTaskManager.isInitialized()) {
-            if (log.isDebugEnabled()) {
-                log.debug("SynapseTaskManager has been already initialized.");
-            }
-            return;
-        }
+        synapseTaskManager = new SynapseTaskManager();
 
         Object repo = 
             serverContextInformation.getProperty(TaskConstants.TASK_DESCRIPTION_REPOSITORY);

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=817502&r1=817501&r2=817502&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
Tue Sep 22 04:45:43 2009
@@ -117,6 +117,12 @@
     private List<SynapseObserver> observers = new ArrayList<SynapseObserver>();
 
     /**
+     * The singleton task manager instance which contains the task description repository
and the
+     * scheduler
+     */
+    private SynapseTaskManager taskManager;
+
+    /**
      * Add a named sequence into the local registry. If a sequence already exists by the
specified
      * key a runtime exception is thrown.
      *
@@ -936,10 +942,11 @@
             stp.destroy();
         }
 
-        SynapseTaskManager synapseTaskManager = SynapseTaskManager.getInstance();
-        TaskScheduler taskScheduler = synapseTaskManager.getTaskScheduler();
-        if (taskScheduler != null && taskScheduler.isInitialized()) {
-            taskScheduler.shutDown();
+        if (taskManager != null && taskManager.isInitialized()) {
+            TaskScheduler taskScheduler = taskManager.getTaskScheduler();
+            if (taskScheduler != null && taskScheduler.isInitialized()) {
+                taskScheduler.shutDown();
+            }
         }
         
         // clear session information used for SA load balancing
@@ -1072,6 +1079,14 @@
         return Collections.unmodifiableList(observers);
     }
 
+    public SynapseTaskManager getTaskManager() {
+        return taskManager;
+    }
+
+    public void setTaskManager(SynapseTaskManager taskManager) {
+        this.taskManager = taskManager;
+    }
+
     private void assertAlreadyExists(String key, String type) {
 
         if (key == null || "".equals(key)) {

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=817502&r1=817501&r2=817502&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
Tue Sep 22 04:45:43 2009
@@ -48,7 +48,7 @@
 
     private TaskDescription taskDescription;
 
-    private final SynapseTaskManager synapseTaskManager = SynapseTaskManager.getInstance();
+    private SynapseTaskManager synapseTaskManager;
 
     public QName getTagQName() {
         return SimpleQuartzFactory.TASK;
@@ -85,8 +85,14 @@
         }
 
         SynapseConfiguration synapseConfiguration = synapseEnvironment.getSynapseConfiguration();
-
-        if (!synapseTaskManager.isInitialized()) {
+        synapseTaskManager = synapseConfiguration.getTaskManager();
+        if (synapseTaskManager == null) {
+            log.error("SynapseTaskManager is not available in the SynapseConfiguration. Tasks
" +
+                    "cannot be initialized.");
+            return;
+        } else if (!synapseTaskManager.isInitialized()) {
+            log.warn("SynapseTaskManager is not properly initialized. Initializing now with
" +
+                    "default parameters.");
             synapseTaskManager.init(null, null);
         }
 

Modified: synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskManager.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskManager.java?rev=817502&r1=817501&r2=817502&view=diff
==============================================================================
--- synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskManager.java
(original)
+++ synapse/branches/1.3/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskManager.java
Tue Sep 22 04:45:43 2009
@@ -31,14 +31,14 @@
 
     private static final Log log = LogFactory.getLog(SynapseTaskManager.class);
 
-    private static SynapseTaskManager INSTANCE = new SynapseTaskManager();
-
     private TaskDescriptionRepository taskDescriptionRepository;
     private TaskScheduler taskScheduler;
     private boolean initialized = false;
 
-    public static SynapseTaskManager getInstance() {
-        return INSTANCE;
+    public SynapseTaskManager() {
+        if (log.isDebugEnabled()) {
+            log.debug("Created the SynapseTaskManager singleton instance");
+        }
     }
 
     /**
@@ -53,6 +53,13 @@
     public void init(TaskDescriptionRepository taskDescriptionRepository,
                      TaskScheduler taskScheduler) {
 
+        if (initialized) {
+            if (log.isDebugEnabled()) {
+                log.debug("Task manager already initialized. Skipping re-initialization.");
+            }
+            return;
+        }
+
         if (taskDescriptionRepository != null) {
             this.taskDescriptionRepository = taskDescriptionRepository;
         } else {



Mime
View raw message