You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ru...@apache.org on 2010/02/28 04:27:17 UTC

svn commit: r917110 - in /synapse/trunk/java: modules/core/src/main/java/org/apache/synapse/Startup.java modules/core/src/main/java/org/apache/synapse/deployers/TaskDeployer.java repository/conf/axis2.xml

Author: ruwan
Date: Sun Feb 28 03:27:16 2010
New Revision: 917110

URL: http://svn.apache.org/viewvc?rev=917110&view=rev
Log:
Adding Task hot deployment

Added:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/TaskDeployer.java
Modified:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java
    synapse/trunk/java/repository/conf/axis2.xml

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java?rev=917110&r1=917109&r2=917110&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java Sun Feb 28 03:27:16 2010
@@ -46,4 +46,19 @@
      * @param id String name to be set to the startup
      */
     public void setName(String id);
+
+    /**
+     * Returns the name of the file where this startup is defined
+     *
+     * @return a file name as a string or null
+     */
+    public String getFileName();
+
+
+    /**
+     * Set the name of the file name where this startup is defined
+     *
+     * @param fileName the name of the file as a string
+     */
+    public void setFileName(String fileName);
 }

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/TaskDeployer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/TaskDeployer.java?rev=917110&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/TaskDeployer.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/TaskDeployer.java Sun Feb 28 03:27:16 2010
@@ -0,0 +1,176 @@
+/*
+ *  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.deployers;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.ServerManager;
+import org.apache.synapse.Startup;
+import org.apache.synapse.config.xml.MultiXMLConfigurationBuilder;
+import org.apache.synapse.config.xml.StartupFinder;
+
+import java.io.File;
+
+/**
+ *  Handles the <code>Startup Task</code> deployment and undeployment
+ *
+ * @see org.apache.synapse.deployers.AbstractSynapseArtifactDeployer
+ */
+public class TaskDeployer extends AbstractSynapseArtifactDeployer {
+
+    private static Log log = LogFactory.getLog(TaskDeployer.class);
+
+    @Override
+    public String deploySynapseArtifact(OMElement artifactConfig, String fileName) {
+
+        if (log.isDebugEnabled()) {
+            log.debug("StartupTask Deployment from file : " + fileName + " : Started");
+        }
+
+        try {
+            Startup st = StartupFinder.getInstance().getStartup(artifactConfig);
+                st.setFileName((new File(fileName).getName()));
+                if (log.isDebugEnabled()) {
+                    log.debug("StartupTask named '" + st.getName()
+                            + "' has been built from the file " + fileName);
+                }
+                st.init(getSynapseEnvironment());
+                if (log.isDebugEnabled()) {
+                    log.debug("Initialized the StartupTask : " + st.getName());
+                }
+                getSynapseConfiguration().addStartup(st);
+                if (log.isDebugEnabled()) {
+                    log.debug("StartupTask Deployment from file : " + fileName + " : Completed");
+                }
+                log.info("StartupTask named '" + st.getName()
+                        + "' has been deployed from file : " + fileName);
+                return st.getName();
+        } catch (Exception e) {
+            handleSynapseArtifactDeploymentError(
+                    "StartupTask Deployment from the file : " + fileName + " : Failed.", e);
+        }
+
+        return null;
+    }
+
+    @Override
+    public String updateSynapseArtifact(OMElement artifactConfig, String fileName,
+                                        String existingArtifactName) {
+
+        if (log.isDebugEnabled()) {
+            log.debug("StartupTask Update from file : " + fileName + " : Started");
+        }
+
+        try {
+            Startup st = StartupFinder.getInstance().getStartup(artifactConfig);
+                st.setFileName((new File(fileName)).getName());
+                if (log.isDebugEnabled()) {
+                    log.debug("StartupTask named '" + st.getName()
+                            + "' has been built from the file " + fileName);
+                }
+                st.init(getSynapseEnvironment());
+                if (log.isDebugEnabled()) {
+                    log.debug("Initialized the StartupTask : " + st.getName());
+                }
+                Startup existingSt =
+                        getSynapseConfiguration().getStartup(existingArtifactName);
+                getSynapseConfiguration().removeStartup(existingArtifactName);
+                if (!existingArtifactName.equals(st.getName())) {
+                    log.info("StartupTask named '" + existingArtifactName + "' has been Undeployed");
+                }
+                getSynapseConfiguration().addStartup(st);
+                existingSt.destroy();
+                if (log.isDebugEnabled()) {
+                    log.debug("StartupTask " + (existingArtifactName.equals(st.getName()) ?
+                            "update" : "deployment") + " from file : " + fileName + " : Completed");
+                }
+                log.info("StartupTask named '" + st.getName()
+                        + "' has been " + (existingArtifactName.equals(st.getName()) ?
+                            "update" : "deployed") + " from file : " + fileName);
+                return st.getName();
+        } catch (Exception e) {
+            handleSynapseArtifactDeploymentError(
+                    "StartupTask Update from the file : " + fileName + " : Failed.", e);
+        }
+
+        return null;
+    }
+
+    @Override
+    public void undeploySynapseArtifact(String artifactName) {
+
+        if (log.isDebugEnabled()) {
+            log.debug("StartupTask Undeployment of the task named : "
+                    + artifactName + " : Started");
+        }
+
+        try {
+            Startup st = getSynapseConfiguration().getStartup(artifactName);
+            if (st != null) {
+                getSynapseConfiguration().removeStartup(artifactName);
+                if (log.isDebugEnabled()) {
+                    log.debug("Destroying the StartupTask named : " + artifactName);
+                }
+                st.destroy();
+                if (log.isDebugEnabled()) {
+                    log.debug("StartupTask Undeployment of the sequence named : "
+                            + artifactName + " : Completed");
+                }
+                log.info("StartupTask named '" + st.getName() + "' has been undeployed");
+            } else {
+                log.error("Couldn't find the StartupTask named : " + artifactName);
+            }
+        } catch (Exception e) {
+            handleSynapseArtifactDeploymentError(
+                    "StartupTask Undeployement of task named : " + artifactName + " : Failed", e);
+        }
+    }
+
+    @Override
+    public void restoreSynapseArtifact(String artifactName) {
+
+        if (log.isDebugEnabled()) {
+            log.debug("Restoring the StartupTask with name : " + artifactName + " : Started");
+        }
+
+        try {
+            Startup st = getSynapseConfiguration().getStartup(artifactName);
+            OMElement stElem = StartupFinder.getInstance().serializeStartup(null, st);
+            if (st.getFileName() != null) {
+                String fileName = ServerManager.getInstance()
+                        .getServerConfigurationInformation().getSynapseXMLLocation()
+                        + File.separator + MultiXMLConfigurationBuilder.TASKS_DIR
+                        + File.separator + st.getFileName();
+                writeToFile(stElem, fileName);
+                if (log.isDebugEnabled()) {
+                    log.debug("Restoring the StartupTask with name : " + artifactName + " : Completed");
+                }
+                log.info("StartupTask named '" + artifactName + "' has been restored");
+            } else {
+                handleSynapseArtifactDeploymentError("Couldn't restore the StartupTask named '"
+                        + artifactName + "', filename cannot be found");
+            }
+        } catch (Exception e) {
+            handleSynapseArtifactDeploymentError(
+                    "Restoring of the StartupTask named '" + artifactName + "' has failed", e);
+        }
+    }
+}

Modified: synapse/trunk/java/repository/conf/axis2.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/axis2.xml?rev=917110&r1=917109&r2=917110&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/axis2.xml (original)
+++ synapse/trunk/java/repository/conf/axis2.xml Sun Feb 28 03:27:16 2010
@@ -87,6 +87,7 @@
     <deployer extension="xml" directory="conf/synapse-config/local-entries" class="org.apache.synapse.deployers.LocalEntryDeployer"/>
     <deployer extension="xml" directory="conf/synapse-config/proxy-services" class="org.apache.synapse.deployers.ProxyServiceDeployer"/>
     <deployer extension="xml" directory="conf/synapse-config/event-sources" class="org.apache.synapse.deployers.EventSourceDeployer"/>
+    <deployer extension="xml" directory="conf/synapse-config/tasks" class="org.apache.synapse.deployers.TaskDeployer"/>
 
     <!-- Following parameter will set the host name for the epr-->
     <!--<parameter name="hostname" locked="true">myhost.com</parameter>-->