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 2009/04/02 10:25:28 UTC
svn commit: r761200 - in
/synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task:
TaskConstants.java TaskHelper.java
Author: indika
Date: Thu Apr 2 08:25:27 2009
New Revision: 761200
URL: http://svn.apache.org/viewvc?rev=761200&view=rev
Log:
Add take helper and task Constance
Added:
synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskConstants.java
synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java
Added: synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskConstants.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskConstants.java?rev=761200&view=auto
==============================================================================
--- synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskConstants.java (added)
+++ synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskConstants.java Thu Apr 2 08:25:27 2009
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+/**
+ * Constants related with task module
+ */
+public final class TaskConstants {
+ /* Key to refer Task Scheduler */
+ public static final String TASK_SCHEDULER = "task_scheduler";
+ /* Key to refer Task Description Repository*/
+ public static final String TASK_DESCRIPTION_REPOSITORY = "task_description_repository";
+}
Added: synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java?rev=761200&view=auto
==============================================================================
--- synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java (added)
+++ synapse/trunk/java/modules/tasks/src/main/java/org/apache/synapse/task/TaskHelper.java Thu Apr 2 08:25:27 2009
@@ -0,0 +1,101 @@
+/*
+ * 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 org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.commons.util.SynapseUtilException;
+
+/**
+ * Helper class to a share Scheduler and TaskDescriptionRepository with in a single class space
+ */
+public class TaskHelper {
+
+ 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;
+ }
+
+ /**
+ * Initialize with given TaskDescriptionRepository and TaskScheduler instances .
+ * if these are null , new instances will be created.
+ *
+ * @param taskDescriptionRepository TaskDescriptionRepository instance
+ * @param taskScheduler TaskScheduler instance
+ */
+ public void init(TaskDescriptionRepository taskDescriptionRepository, TaskScheduler taskScheduler) {
+
+ if (taskDescriptionRepository != null) {
+ this.taskDescriptionRepository = taskDescriptionRepository;
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Creating new TaskDescriptionRepository as given instance is null.");
+ }
+ this.taskDescriptionRepository =
+ TaskDescriptionRepositoryFactory.getTaskDescriptionRepository(
+ TaskConstants.TASK_DESCRIPTION_REPOSITORY);
+ }
+
+ if (taskScheduler != null) {
+ this.taskScheduler = taskScheduler;
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Creating new TaskScheduler as given instance is null.");
+ }
+ this.taskScheduler = TaskSchedulerFactory.getTaskScheduler(TaskConstants.TASK_SCHEDULER);
+
+ }
+ initialized = true;
+ }
+
+ public TaskDescriptionRepository getTaskDescriptionRepository() {
+ assertInitialized();
+ return taskDescriptionRepository;
+ }
+
+ public TaskScheduler getTaskScheduler() {
+ assertInitialized();
+ return taskScheduler;
+ }
+
+ private void assertInitialized() {
+ if (!initialized) {
+ String msg = "Task helper has not been initialized, it requires to be initialized";
+ log.error(msg);
+ throw new SynapseUtilException(msg);
+ }
+ }
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ public void cleanup() {
+ assertInitialized();
+ taskDescriptionRepository.clear();
+ taskScheduler.shutDown();
+ }
+}