You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by in...@apache.org on 2008/10/29 08:05:29 UTC
svn commit: r708809 - in /synapse/trunk/java/modules:
core/src/main/java/org/apache/synapse/startup/quartz/
tasks/src/main/java/org/apache/synapse/task/
Author: indika
Date: Wed Oct 29 00:05:29 2008
New Revision: 708809
URL: http://svn.apache.org/viewvc?rev=708809&view=rev
Log:
Some improvement for the task implementation
Added:
synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepositoryFactory.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java
synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionSerializer.java
synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskSchedulerFactory.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=708809&r1=708808&r2=708809&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 00:05:29 2008
@@ -30,9 +30,7 @@
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.SynapseException;
import org.apache.synapse.ServerManager;
-import org.apache.synapse.task.TaskDescription;
-import org.apache.synapse.task.TaskSchedulerFactory;
-import org.apache.synapse.task.TaskScheduler;
+import org.apache.synapse.task.*;
import org.apache.synapse.startup.AbstractStartup;
/*
@@ -45,19 +43,19 @@
public class SimpleQuartz extends AbstractStartup {
private static final Log log = LogFactory.getLog(SimpleQuartz.class);
-
- private TaskDescription taskDescription;
-
- public static String SYNAPSE_STARTUP_TASK_SCHEDULER ="synapse.startup.taskscheduler";
-
+
+ private String taskDescriptionReference;
+
+ public static String SYNAPSE_STARTUP_TASK_SCHEDULER = "synapse.startup.taskscheduler";
+ public static String SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY = "synapse.startup.taskdescriptions.repository";
+
public QName getTagQName() {
return SimpleQuartzFactory.TASK;
}
public void destroy() {
- TaskSchedulerFactory schedulerFactory = TaskSchedulerFactory.getInstance();
- TaskScheduler taskScheduler = schedulerFactory.getTaskScheduler(SYNAPSE_STARTUP_TASK_SCHEDULER);
+ TaskScheduler taskScheduler = TaskSchedulerFactory.getTaskScheduler(SYNAPSE_STARTUP_TASK_SCHEDULER);
if (taskScheduler != null && taskScheduler.isInitialized()) {
taskScheduler.shutDown();
}
@@ -65,44 +63,51 @@
public void init(SynapseEnvironment synapseEnvironment) {
- if(taskDescription == null){
- throw new NullPointerException("TaskDescription is null");
+ if (taskDescriptionReference == null || "".equals(taskDescriptionReference)) {
+ throw new NullPointerException("TaskDescriptionRefrence key is null or empty");
+ }
+
+ TaskDescriptionRepository repository = TaskDescriptionRepositoryFactory.getTaskDescriptionRepository(
+ SimpleQuartz.SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY);
+ TaskDescription taskDescription = repository.getTaskDescription(taskDescriptionReference);
+
+ if (taskDescription == null) {
+ throw new NullPointerException("TaskDescription is null : reference name : " + taskDescriptionReference);
}
// this server name given by system property SynapseServerName
// otherwise take host-name
// else assume localhost
String thisServerName = ServerManager.getInstance().getServerName();
- if(thisServerName == null || thisServerName.equals("")) {
- try {
- InetAddress addr = InetAddress.getLocalHost();
- thisServerName = addr.getHostName();
-
- } catch (UnknownHostException e) {
- log.warn("Could not get local host name", e);
- }
-
- if(thisServerName == null || thisServerName.equals("")) {
- thisServerName = "localhost";
- }
+ if (thisServerName == null || thisServerName.equals("")) {
+ try {
+ InetAddress addr = InetAddress.getLocalHost();
+ thisServerName = addr.getHostName();
+
+ } catch (UnknownHostException e) {
+ log.warn("Could not get local host name", e);
+ }
+
+ if (thisServerName == null || thisServerName.equals("")) {
+ thisServerName = "localhost";
+ }
}
log.debug("Synapse server name : " + thisServerName);
-
+
// start proxy service if either,
// pinned server name list is empty
// or pinned server list has this server name
List pinnedServers = taskDescription.getPinnedServers();
- if(pinnedServers != null && !pinnedServers.isEmpty()) {
- if(!pinnedServers.contains(thisServerName)) {
- log.info("Server name not in pinned servers list. Not starting Task : " + getName());
- return;
- }
+ if (pinnedServers != null && !pinnedServers.isEmpty()) {
+ if (!pinnedServers.contains(thisServerName)) {
+ log.info("Server name not in pinned servers list. Not starting Task : " + getName());
+ return;
+ }
}
Map<String, Object> map = new HashMap<String, Object>();
map.put(SimpleQuartzJob.SYNAPSE_ENVIRONMENT, synapseEnvironment);
try {
- TaskSchedulerFactory schedulerFactory = TaskSchedulerFactory.getInstance();
- TaskScheduler taskScheduler = schedulerFactory.getTaskScheduler(SYNAPSE_STARTUP_TASK_SCHEDULER);
+ TaskScheduler taskScheduler = TaskSchedulerFactory.getTaskScheduler(SYNAPSE_STARTUP_TASK_SCHEDULER);
if (taskScheduler != null) {
if (!taskScheduler.isInitialized()) {
taskScheduler.init(synapseEnvironment.getSynapseConfiguration().getProperties());
@@ -116,11 +121,11 @@
}
- public TaskDescription getTaskDescription() {
- return taskDescription;
+ public String getTaskDescriptionReference() {
+ return taskDescriptionReference;
}
- public void setTaskDescription(TaskDescription taskDescription) {
- this.taskDescription = taskDescription;
+ public void setTaskDescriptionReference(String taskDescriptionReference) {
+ this.taskDescriptionReference = taskDescriptionReference;
}
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java?rev=708809&r1=708808&r2=708809&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java Wed Oct 29 00:05:29 2008
@@ -30,6 +30,8 @@
import org.apache.synapse.SynapseException;
import org.apache.synapse.task.TaskDescription;
import org.apache.synapse.task.TaskDescriptionFactory;
+import org.apache.synapse.task.TaskDescriptionRepositoryFactory;
+import org.apache.synapse.task.TaskDescriptionRepository;
/**
* <task class="org.my.synapse.Task" name="string">
@@ -61,7 +63,10 @@
if(taskDescription == null){
handleException("Invalid task - Task description can not be created form :"+el);
}
- simpleQuartz.setTaskDescription(taskDescription);
+ TaskDescriptionRepository repository = TaskDescriptionRepositoryFactory.getTaskDescriptionRepository(
+ SimpleQuartz.SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY);
+ repository.addTaskDescription(taskDescription);
+ simpleQuartz.setTaskDescriptionReference(taskDescription.getName());
return simpleQuartz;
} else {
handleException("Syntax error in the task : wrong QName for the task");
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java?rev=708809&r1=708808&r2=708809&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java Wed Oct 29 00:05:29 2008
@@ -24,6 +24,8 @@
import org.apache.synapse.SynapseException;
import org.apache.synapse.task.TaskDescription;
import org.apache.synapse.task.TaskDescriptionSerializer;
+import org.apache.synapse.task.TaskDescriptionRepository;
+import org.apache.synapse.task.TaskDescriptionRepositoryFactory;
import org.apache.synapse.config.xml.StartupSerializer;
public class SimpleQuartzSerializer implements StartupSerializer {
@@ -36,16 +38,26 @@
}
SimpleQuartz sq = (SimpleQuartz) s;
- TaskDescription taskDescription = sq.getTaskDescription();
- if (taskDescription != null) {
- OMElement task = TaskDescriptionSerializer.serializeStartup(parent, taskDescription);
- if (task == null) {
- throw new SynapseException("Task Element can not be null.");
+ String taskDescriptionRef = sq.getTaskDescriptionReference();
+ if (taskDescriptionRef != null || !"".equals(taskDescriptionRef)) {
+
+ TaskDescriptionRepository repository = TaskDescriptionRepositoryFactory.getTaskDescriptionRepository(
+ SimpleQuartz.SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY);
+ TaskDescription taskDescription = repository.getTaskDescription(taskDescriptionRef);
+
+ if (taskDescription != null) {
+ OMElement task = TaskDescriptionSerializer.serializeTaskDescription(parent, taskDescription);
+ if (task == null) {
+ throw new SynapseException("Task Element can not be null.");
+ }
+ return task;
+ } else {
+ throw new SynapseException("Task Description is null for given reference :" + taskDescriptionRef);
}
- return task;
+ } else {
+ throw new SynapseException("Task Description Reference is null.");
}
- throw new SynapseException("Task Element is null.");
}
}
Added: synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepositoryFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepositoryFactory.java?rev=708809&view=auto
==============================================================================
--- synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepositoryFactory.java (added)
+++ synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepositoryFactory.java Wed Oct 29 00:05:29 2008
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.synapse.task;
+
+import java.util.Map;
+import java.util.HashMap;
+
+public class TaskDescriptionRepositoryFactory {
+
+ private final static Map<String, TaskDescriptionRepository> repositoryMap = new HashMap<String, TaskDescriptionRepository>();
+
+ private TaskDescriptionRepositoryFactory() {
+ }
+
+ /**
+ * Returns a TaskDescriptionRepository instance
+ * There is an only one instance of TaskDescriptionRepository for a given id as Factory caches TaskDescriptionRepositorys
+ *
+ * @param id Identifier for TaskDescriptionRepository
+ * @return TaskDescriptionRepository instance
+ */
+ public static TaskDescriptionRepository getTaskDescriptionRepository(String id) {
+
+ if (id == null || "".equals(id)) {
+ throw new SynapseTaskException("Name cannot be found.");
+ }
+
+ TaskDescriptionRepository repository = repositoryMap.get(id);
+ if (repository == null) {
+ repository = new TaskDescriptionRepository();
+ repositoryMap.put(id, repository);
+ }
+ return repository;
+ }
+}
Modified: synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionSerializer.java?rev=708809&r1=708808&r2=708809&view=diff
==============================================================================
--- synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionSerializer.java (original)
+++ synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionSerializer.java Wed Oct 29 00:05:29 2008
@@ -38,7 +38,7 @@
private static final String NULL_NAMESPACE = "";
private static final OMNamespace NULL_OMNS = omFactory.createOMNamespace(NULL_NAMESPACE, "");
- public static OMElement serializeStartup(OMElement parent, TaskDescription taskDescription) {
+ public static OMElement serializeTaskDescription(OMElement parent, TaskDescription taskDescription) {
if (taskDescription == null) {
throw new SynapseTaskException("TaskDescription can not be null", log);
Modified: synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskSchedulerFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskSchedulerFactory.java?rev=708809&r1=708808&r2=708809&view=diff
==============================================================================
--- synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskSchedulerFactory.java (original)
+++ synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskSchedulerFactory.java Wed Oct 29 00:05:29 2008
@@ -1,5 +1,20 @@
-/**
- * To change this template use File | Settings | File Templates.
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.apache.synapse.task;
@@ -12,14 +27,8 @@
*/
public class TaskSchedulerFactory {
- private final static TaskSchedulerFactory SCHEDULER_FACTORY = new TaskSchedulerFactory();
-
private final static Map<String, TaskScheduler> MAP = new HashMap<String, TaskScheduler>();
- public static TaskSchedulerFactory getInstance() {
- return SCHEDULER_FACTORY;
- }
-
private TaskSchedulerFactory() {
}
@@ -30,7 +39,7 @@
* @param name Name of the TaskScheduler
* @return TaskScheduler instance
*/
- public TaskScheduler getTaskScheduler(String name) {
+ public static TaskScheduler getTaskScheduler(String name) {
if (name == null || "".equals(name)) {
throw new SynapseTaskException("Name cannot be found.");