Author: ruwan
Date: Tue Feb 16 03:12:56 2010
New Revision: 910381
URL: http://svn.apache.org/viewvc?rev=910381&view=rev
Log:
Refactoring
Added:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/SynapseArtifactDeploymentStore.java
- copied, changed from r910372,
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/DeployedSynapseArtifactHolder.java
Removed:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/DeployedSynapseArtifactHolder.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/AbstractSynapseArtifactDeployer.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java?rev=910381&r1=910380&r2=910381&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java
Tue Feb 16 03:12:56 2010
@@ -30,7 +30,7 @@
import org.apache.synapse.config.SynapseConfigUtils;
import org.apache.synapse.config.SynapseConfiguration;
import org.apache.synapse.core.axis2.ProxyService;
-import org.apache.synapse.deployers.DeployedSynapseArtifactHolder;
+import org.apache.synapse.deployers.SynapseArtifactDeploymentStore;
import org.apache.synapse.endpoints.Endpoint;
import org.apache.synapse.eventing.SynapseEventSource;
import org.apache.synapse.mediators.base.SequenceMediator;
@@ -168,7 +168,7 @@
Entry entry = SynapseXMLConfigurationFactory.defineEntry(
synapseConfig, document);
entry.setFileName(file.getName());
- DeployedSynapseArtifactHolder.getInstance().addArtifact(
+ SynapseArtifactDeploymentStore.getInstance().addArtifact(
file.getAbsolutePath(), entry.getKey());
} catch (FileNotFoundException ignored) {}
}
@@ -190,7 +190,7 @@
ProxyService proxy =
SynapseXMLConfigurationFactory.defineProxy(
synapseConfig, document);
proxy.setFileName(file.getName());
- DeployedSynapseArtifactHolder.getInstance().addArtifact(
+ SynapseArtifactDeploymentStore.getInstance().addArtifact(
file.getAbsolutePath(), proxy.getName());
} catch (FileNotFoundException ignored) {}
}
@@ -214,7 +214,7 @@
if (startup instanceof AbstractStartup) {
((AbstractStartup)
startup).setFileName(file.getName());
}
- DeployedSynapseArtifactHolder.getInstance().addArtifact(
+ SynapseArtifactDeploymentStore.getInstance().addArtifact(
file.getAbsolutePath(), startup.getName());
} catch (FileNotFoundException ignored) {}
}
@@ -238,7 +238,7 @@
if (seq instanceof SequenceMediator) {
SequenceMediator sequence = (SequenceMediator) seq;
sequence.setFileName(file.getName());
-
DeployedSynapseArtifactHolder.getInstance().addArtifact(
+
SynapseArtifactDeploymentStore.getInstance().addArtifact(
file.getAbsolutePath(), sequence.getName());
}
} catch (FileNotFoundException ignored) {}
@@ -261,7 +261,7 @@
Endpoint endpoint =
SynapseXMLConfigurationFactory.defineEndpoint(
synapseConfig, document);
endpoint.setFileName(file.getName());
- DeployedSynapseArtifactHolder.getInstance().addArtifact(
+ SynapseArtifactDeploymentStore.getInstance().addArtifact(
file.getAbsolutePath(), endpoint.getName());
} catch (FileNotFoundException ignored) {}
}
@@ -283,7 +283,7 @@
SynapseEventSource eventSource =
SynapseXMLConfigurationFactory.
defineEventSource(synapseConfig, document);
eventSource.setFileName(file.getName());
- DeployedSynapseArtifactHolder.getInstance().addArtifact(
+ SynapseArtifactDeploymentStore.getInstance().addArtifact(
file.getAbsolutePath(), eventSource.getName());
} catch (FileNotFoundException ignored) {}
}
@@ -305,7 +305,7 @@
PriorityExecutor executor = SynapseXMLConfigurationFactory.
defineExecutor(synapseConfig, document);
executor.setFileName(file.getName());
- DeployedSynapseArtifactHolder.getInstance().addArtifact(
+ SynapseArtifactDeploymentStore.getInstance().addArtifact(
file.getAbsolutePath(), executor.getName());
} catch (FileNotFoundException ignored) {}
}
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/AbstractSynapseArtifactDeployer.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/AbstractSynapseArtifactDeployer.java?rev=910381&r1=910380&r2=910381&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/AbstractSynapseArtifactDeployer.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/AbstractSynapseArtifactDeployer.java
Tue Feb 16 03:12:56 2010
@@ -39,10 +39,6 @@
import javax.xml.stream.XMLStreamException;
import java.io.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
/**
* Implements the generic logic for the synapse artifact deployment and
provide a deployment framework
@@ -59,12 +55,11 @@
private static final Log log =
LogFactory.getLog(AbstractSynapseArtifactDeployer.class);
protected Log deployerLog;
protected ConfigurationContext cfgCtx;
- private Map<String, String> updatingArtifacts = new HashMap<String,
String>();
- private List<String> restoredFiles = new ArrayList<String>();
- private List<String> backedUpFiles = new ArrayList<String>();
+ private SynapseArtifactDeploymentStore deploymentStore;
protected AbstractSynapseArtifactDeployer() {
deployerLog = LogFactory.getLog(this.getClass());
+ deploymentStore = SynapseArtifactDeploymentStore.getInstance();
}
/**
@@ -102,10 +97,10 @@
String filename = deploymentFileData.getAbsolutePath();
// check whether this is triggered by a restore, if it is a restore we
do not want to deploy it again
- if (restoredFiles.contains(filename)) {
+ if (deploymentStore.isRestoredFile(filename)) {
// only one deployment trigger can happen after a restore and
hence remove it from restoredFiles
// at the first hit, allowing the further deployments/updates to
take place as usual
- restoredFiles.remove(filename);
+ deploymentStore.removeRestoredFile(filename);
return;
}
@@ -117,10 +112,11 @@
OMElement element = new StAXOMBuilder(
StAXUtils.createXMLStreamReader(in)).getDocumentElement();
String artifatcName = null;
- if (updatingArtifacts.containsKey(filename)) {
+ if (deploymentStore.isUpdatingArtifact(filename)) {
// this is an hot-update case
- String existingArtifactName =
updatingArtifacts.get(filename);
- updatingArtifacts.remove(filename);
+ String existingArtifactName
+ =
deploymentStore.getUpdatingArtifactWithFileName(filename);
+ deploymentStore.removeUpdatingArtifact(filename);
try {
artifatcName = updateSynapseArtifact(
element, filename, existingArtifactName);
@@ -145,7 +141,7 @@
}
}
if (artifatcName != null) {
-
DeployedSynapseArtifactHolder.getInstance().addArtifact(filename, artifatcName);
+ deploymentStore.addArtifact(filename, artifatcName);
}
} finally {
in.close();
@@ -175,29 +171,29 @@
public void unDeploy(String fileName) throws DeploymentException {
// We want to eliminate the undeployment when we are backing up these
files
- if (backedUpFiles.contains(fileName)) {
+ if (deploymentStore.isBackedUpArtifact(fileName)) {
// only one undeployment trigger can happen after a backup and
hence remove it from backedUpFiles
// at the first hit, allowing the further undeploymentsto take
place as usual
- backedUpFiles.remove(fileName);
+ deploymentStore.removeBackedUpArtifact(fileName);
return;
}
- DeployedSynapseArtifactHolder holder =
DeployedSynapseArtifactHolder.getInstance();
- if (holder.containsFileName(fileName)) {
+ if (deploymentStore.containsFileName(fileName)) {
File undeployingFile = new File(fileName);
// axis2 treats Hot-Update as (Undeployment + deployment), where
synapse needs to differentiate
// the Hot-Update from the above two, since it needs some
validations for a real undeployment.
// also this makes sure a zero downtime of the synapse artifacts
which are being Hot-deployed
if (undeployingFile.exists()) {
// if the file exists, which means it has been updated and is
a Hot-Update case
- updatingArtifacts.put(fileName,
holder.getArtifactNameForFile(fileName));
- holder.removeArtifactWithFileName(fileName);
+ deploymentStore.addUpdatingArtifact(
+ fileName,
deploymentStore.getArtifactNameForFile(fileName));
+ deploymentStore.removeArtifactWithFileName(fileName);
} else {
// if the file doesn't exists then it is an actual undeployment
- String artifactName = holder.getArtifactNameForFile(fileName);
+ String artifactName =
deploymentStore.getArtifactNameForFile(fileName);
try {
undeploySynapseArtifact(artifactName);
- holder.removeArtifactWithFileName(fileName);
+ deploymentStore.removeArtifactWithFileName(fileName);
} catch (SynapseArtifactDeploymentException sade) {
log.error("Unable to undeploy the artifact from file : " +
fileName, sade);
log.info("Restoring the artifact into the file : " +
fileName);
@@ -281,7 +277,7 @@
protected void writeToFile(OMElement content, String fileName) throws
Exception {
// this is not good, but I couldn't think of a better design :-(
- restoredFiles.add(fileName);
+ deploymentStore.addRestoredArtifact(fileName);
OutputStream out = new FileOutputStream(new File(fileName));
XMLPrettyPrinter.prettify(content, out);
out.flush();
@@ -300,19 +296,19 @@
private void handleDeploymentError(String msg, Exception e, String
fileName) {
log.error(msg, e);
- if (updatingArtifacts.containsKey(fileName)) {
+ if (deploymentStore.isUpdatingArtifact(fileName)) {
backupFile(new File(fileName));
log.info("Restoring the existing artifact into the file : " +
fileName);
- restoreSynapseArtifact(updatingArtifacts.get(fileName));
- DeployedSynapseArtifactHolder.getInstance().addArtifact(
- fileName, updatingArtifacts.get(fileName));
- updatingArtifacts.remove(fileName);
+
restoreSynapseArtifact(deploymentStore.getUpdatingArtifactWithFileName(fileName));
+ deploymentStore.addArtifact(
+ fileName,
deploymentStore.getUpdatingArtifactWithFileName(fileName));
+ deploymentStore.removeUpdatingArtifact(fileName);
}
}
private String backupFile(File file) {
String filePath = file.getAbsolutePath();
- backedUpFiles.add(filePath);
+ deploymentStore.addBackedUpArtifact(filePath);
String backupFilePath = filePath + ".back";
int backupIndex = 0;
while (backupIndex >= 0) {
Copied:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/SynapseArtifactDeploymentStore.java
(from r910372,
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/DeployedSynapseArtifactHolder.java)
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/SynapseArtifactDeploymentStore.java?p2=synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/SynapseArtifactDeploymentStore.java&p1=synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/DeployedSynapseArtifactHolder.java&r1=910372&r2=910381&rev=910381&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/DeployedSynapseArtifactHolder.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/deployers/SynapseArtifactDeploymentStore.java
Tue Feb 16 03:12:56 2010
@@ -22,8 +22,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
/**
* Keeps track of the artifacts deployed with files inside the synapse
repository</p>
@@ -36,29 +35,34 @@
* @see org.apache.synapse.deployers.AbstractSynapseArtifactDeployer
* @see org.apache.synapse.config.xml.MultiXMLConfigurationBuilder
*/
-public class DeployedSynapseArtifactHolder {
+public final class SynapseArtifactDeploymentStore {
- /**
- * Keeps track of the deployed artifacts in the synapse environment
- */
+ /** Keeps track of the deployed artifacts in the synapse environment */
private static Map<String, String> fileName2ArtifactName = new
HashMap<String, String>();
- private static DeployedSynapseArtifactHolder _instance;
+ /** Keeps track of the updating artifacts in the synapse environment in a
particular instance */
+ private Map<String, String> updatingArtifacts = new HashMap<String,
String>();
+
+ /** Keeps track of the restored artifacts in the synapse environment in a
particular instance */
+ private List<String> restoredFiles = new ArrayList<String>();
+
+ /** Keeps track of the backed up artifacts in the synapse environment in a
particular instance */
+ private List<String> backedUpFiles = new ArrayList<String>();
- private static final Log log =
LogFactory.getLog(DeployedSynapseArtifactHolder.class);
-
- private DeployedSynapseArtifactHolder() {}
+ private static SynapseArtifactDeploymentStore _instance;
+ private static final Log log =
LogFactory.getLog(SynapseArtifactDeploymentStore.class);
+ private SynapseArtifactDeploymentStore() {}
/**
* Provides the <code>singleton</code> instance of
- * {...@link DeployedSynapseArtifactHolder}
+ * {...@link SynapseArtifactDeploymentStore}
*
- * @return the singleton instance of DeployedSynapseArtifactHolder
+ * @return the singleton instance of SynapseArtifactDeploymentStore
*/
- public static DeployedSynapseArtifactHolder getInstance() {
+ public static SynapseArtifactDeploymentStore getInstance() {
if (_instance == null) {
- _instance = new DeployedSynapseArtifactHolder();
+ _instance = new SynapseArtifactDeploymentStore();
}
return _instance;
}
@@ -106,4 +110,100 @@
public void removeArtifactWithFileName(String fileName) {
fileName2ArtifactName.remove(fileName);
}
+
+ /**
+ * Adds an updating artifact for the given instance
+ *
+ * @param fileName name of the file from which the artifact has been loaded
+ * @param artifactName name of the actual artifact being updated
+ */
+ public void addUpdatingArtifact(String fileName, String artifactName) {
+ updatingArtifacts.put(fileName, artifactName);
+ }
+
+ /**
+ * Checks whether the given artifact is at the updating state in the given
instance
+ *
+ * @param fileName name of the file which describes the artifact to be
checked
+ * @return boolean <code>true</code> if it is at the updating state,
<code>false</code> otherwise
+ */
+ public boolean isUpdatingArtifact(String fileName) {
+ return updatingArtifacts.containsKey(fileName);
+ }
+
+ /**
+ * Retrieves the artifact name corresponds to the given updating artifact
file name
+ *
+ * @param fileName name of the file from which the artifact is being
updated
+ * @return String artifact name corresponds to the given file name
+ */
+ public String getUpdatingArtifactWithFileName(String fileName) {
+ return updatingArtifacts.get(fileName);
+ }
+
+ /**
+ * Removes an updating artifact
+ *
+ * @param fileName name of the file of the artifact to be removed from the
updating artifacts
+ */
+ public void removeUpdatingArtifact(String fileName) {
+ updatingArtifacts.remove(fileName);
+ }
+
+ /**
+ * Adds an artifact which is being restored
+ *
+ * @param fileName name of the file of the artifact which is being restored
+ */
+ public void addRestoredArtifact(String fileName) {
+ restoredFiles.add(fileName);
+ }
+
+ /**
+ * Checks whether the given artifact is being restored
+ *
+ * @param fileName name of the file to be checked
+ * @return boolean <code>true</code> if the provided filename describes a
restoring artifact,
+ * <code>false</code> otherwise
+ */
+ public boolean isRestoredFile(String fileName) {
+ return restoredFiles.contains(fileName);
+ }
+
+ /**
+ * Removes a restored artifact
+ *
+ * @param fileName name of the file of the artifact to be removed
+ */
+ public void removeRestoredFile(String fileName) {
+ restoredFiles.remove(fileName);
+ }
+
+ /**
+ * Adds an artifact to the backedUp artifacts
+ *
+ * @param fileName name of the file of the artifact to be added into the
backedUp artifacts
+ */
+ public void addBackedUpArtifact(String fileName) {
+ backedUpFiles.add(fileName);
+ }
+
+ /**
+ * Checks whether the given artifact is being backed up
+ *
+ * @param fileName name of the file of the artifact to be checked
+ * @return boolean <code>true</code> if the artifact is being backed up,
<code>false</code> otherwise
+ */
+ public boolean isBackedUpArtifact(String fileName) {
+ return backedUpFiles.contains(fileName);
+ }
+
+ /**
+ * Removes a backedUp artifact
+ *
+ * @param fileName name of the file of the artifact to be removed
+ */
+ public void removeBackedUpArtifact(String fileName) {
+ backedUpFiles.remove(fileName);
+ }
}