Author: indika
Date: Wed Oct 29 02:09:40 2008
New Revision: 708841

URL: http://svn.apache.org/viewvc?rev=708841&view=rev
Log:
add remove method

Modified:
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
    
synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepository.java

Modified: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java?rev=708841&r1=708840&r2=708841&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
 (original)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
 Wed Oct 29 02:09:40 2008
@@ -59,20 +59,30 @@
         if (taskScheduler != null && taskScheduler.isInitialized()) {
             taskScheduler.shutDown();
         }
+
+        TaskDescriptionRepository repository = 
TaskDescriptionRepositoryFactory.getTaskDescriptionRepository(
+                SimpleQuartz.SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY);
+        if (repository != null) {
+            repository.removeTaskDescription(taskDescriptionReference);
+        }
     }
 
     public void init(SynapseEnvironment synapseEnvironment) {
 
         if (taskDescriptionReference == null || 
"".equals(taskDescriptionReference)) {
-            throw new NullPointerException("TaskDescriptionRefrence key is 
null or empty");
+            handleException("TaskDescriptionRefrence key is null or empty");
         }
 
         TaskDescriptionRepository repository = 
TaskDescriptionRepositoryFactory.getTaskDescriptionRepository(
                 SimpleQuartz.SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY);
+        if (repository == null) {
+            handleException("Task Description Repository can not found");
+        }
+
         TaskDescription taskDescription = 
repository.getTaskDescription(taskDescriptionReference);
 
         if (taskDescription == null) {
-            throw new NullPointerException("TaskDescription is null : 
reference name : " + taskDescriptionReference);
+            handleException("TaskDescription is null : reference name : " + 
taskDescriptionReference);
         }
         // this server name given by system property SynapseServerName
         // otherwise take host-name
@@ -106,14 +116,22 @@
 
         Map<String, Object> map = new HashMap<String, Object>();
         map.put(SimpleQuartzJob.SYNAPSE_ENVIRONMENT, synapseEnvironment);
+
         try {
+
             TaskScheduler taskScheduler = 
TaskSchedulerFactory.getTaskScheduler(SYNAPSE_STARTUP_TASK_SCHEDULER);
             if (taskScheduler != null) {
                 if (!taskScheduler.isInitialized()) {
                     
taskScheduler.init(synapseEnvironment.getSynapseConfiguration().getProperties());
                 }
                 taskScheduler.scheduleTask(taskDescription, map, 
SimpleQuartzJob.class);
+            } else {
+                if (log.isDebugEnabled()) {
+                    log.debug("TaskScheduler cannot be found for :" + 
SYNAPSE_STARTUP_TASK_SCHEDULER + " , " +
+                            "therefore ignore scheduling of Task  " + 
taskDescription);
+                }
             }
+
         } catch (Exception e) {
             log.fatal("Error starting up Scheduler", e);
             throw new SynapseException("Error starting up Scheduler", e);
@@ -128,4 +146,9 @@
     public void setTaskDescriptionReference(String taskDescriptionReference) {
         this.taskDescriptionReference = taskDescriptionReference;
     }
+
+    private static void handleException(String message) {
+        log.error(message);
+        throw new SynapseException(message);
+    }
 }

Modified: 
synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepository.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepository.java?rev=708841&r1=708840&r2=708841&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepository.java
 (original)
+++ 
synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepository.java
 Wed Oct 29 02:09:40 2008
@@ -61,6 +61,16 @@
     }
 
     /**
+     * Removing a TaskDescription
+     *
+     * @param name Name of the TaskDescription to be removed
+     */
+    public void removeTaskDescription(String name) {
+        validateName(name);
+        taskDescriptionMap.remove(name);
+    }
+    
+    /**
      * Explicit check for determine whether there is a task description with a 
name in interest
      *
      * @param name Name of the TaskDescription


Reply via email to