summaryrefslogtreecommitdiff
path: root/qpid/java/broker-core
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2014-01-17 13:05:23 +0000
committerKeith Wall <kwall@apache.org>2014-01-17 13:05:23 +0000
commitee76ebefc53d00751fa0c2a404c083dc63f516db (patch)
tree7d80d6b2942fb5e6f779bc244bd3cc64006929f4 /qpid/java/broker-core
parentcdf9dd41327c461b5c5264566992bc4e312cc97f (diff)
downloadqpid-python-ee76ebefc53d00751fa0c2a404c083dc63f516db.tar.gz
QPID-5065: modifications to get more tests running on windows (both ant and maven).
Also - Fixed the jca/rar pom module name, it should be qpid-ra not qpid-rar. - Added project details such as Website, Mailing List, SCM. Patch submitted by Andrew MacBean <andymacbean@gmail.com> git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1559096 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker-core')
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacade.java106
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java5
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java7
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java21
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java3
5 files changed, 84 insertions, 58 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacade.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacade.java
index 6a961c8fa4..5b411e2d8d 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacade.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacade.java
@@ -25,6 +25,8 @@ import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.apache.log4j.xml.Log4jEntityResolver;
+import org.apache.qpid.util.FileUtils;
+import org.apache.qpid.util.SystemUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -293,7 +295,9 @@ public class LoggingManagementFacade
public List<String> getAvailableLoggerLevels()
{
return new ArrayList<String>()
- {{
+ {
+ private static final long serialVersionUID = 599203507907836466L;
+ {
add(Level.ALL.toString());
add(Level.TRACE.toString());
add(Level.DEBUG.toString());
@@ -364,6 +368,65 @@ public class LoggingManagementFacade
throw new IOException("Specified log4j XML configuration file is not writable");
}
+ // Swap temp file in to replace existing configuration file.
+ File old = new File(log4jConfigFile.getAbsoluteFile() + ".old");
+ if (old.exists())
+ {
+ old.delete();
+ }
+
+ if(!SystemUtils.isWindows())
+ {
+
+ File tmp;
+ Random r = new Random();
+
+ final String absolutePath = log4jConfigFile.getAbsolutePath();
+ do
+ {
+ tmp = new File(absolutePath + r.nextInt() + ".tmp");
+ }
+ while(tmp.exists());
+
+ tmp.deleteOnExit();
+
+ writeConfigToFile(doc, new FileOutputStream(tmp));
+
+ if(!log4jConfigFile.renameTo(old))
+ {
+ //unable to rename the existing file to the backup name
+ LOGGER.error("Could not backup the existing log4j XML file");
+ throw new IOException("Could not backup the existing log4j XML file");
+ }
+
+ if(!tmp.renameTo(new File(absolutePath)))
+ {
+ //failed to rename the new file to the required filename
+
+ if(!old.renameTo(log4jConfigFile))
+ {
+ //unable to return the backup to required filename
+ LOGGER.error("Could not rename the new log4j configuration file into place, and unable to restore original file");
+ throw new IOException("Could not rename the new log4j configuration file into place, and unable to restore original file");
+ }
+
+ LOGGER.error("Could not rename the new log4j configuration file into place");
+ throw new IOException("Could not rename the new log4j configuration file into place");
+ }
+ }
+ else
+ {
+ // In windows we can't do a safe rename current -> old, tmp -> current as it will not allow
+ // a new file with the same name as current to be created while it is still open.
+
+ // Instead we have to do an unsafe "copy current to old", "replace current contents with tmp contents"
+ FileUtils.copy(log4jConfigFile,old);
+ writeConfigToFile(doc, new FileOutputStream(log4jConfigFile));
+ }
+ }
+
+ private void writeConfigToFile(Document doc, FileOutputStream outputFile) throws TransformerConfigurationException, IOException
+ {
Transformer transformer = null;
transformer = TransformerFactory.newInstance().newTransformer();
@@ -371,20 +434,10 @@ public class LoggingManagementFacade
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "log4j.dtd");
DOMSource source = new DOMSource(doc);
- File tmp;
- Random r = new Random();
-
- do
- {
- tmp = new File(log4jConfigFile.getAbsolutePath() + r.nextInt() + ".tmp");
- }
- while(tmp.exists());
-
- tmp.deleteOnExit();
try
{
- StreamResult result = new StreamResult(new FileOutputStream(tmp));
+ StreamResult result = new StreamResult(outputFile);
transformer.transform(source, result);
}
catch (TransformerException e)
@@ -392,35 +445,6 @@ public class LoggingManagementFacade
LOGGER.warn("Could not transform the XML into new file: ", e);
throw new IOException("Could not transform the XML into new file: ", e);
}
-
- // Swap temp file in to replace existing configuration file.
- File old = new File(log4jConfigFile.getAbsoluteFile() + ".old");
- if (old.exists())
- {
- old.delete();
- }
-
- if(!log4jConfigFile.renameTo(old))
- {
- //unable to rename the existing file to the backup name
- LOGGER.error("Could not backup the existing log4j XML file");
- throw new IOException("Could not backup the existing log4j XML file");
- }
-
- if(!tmp.renameTo(log4jConfigFile))
- {
- //failed to rename the new file to the required filename
-
- if(!old.renameTo(log4jConfigFile))
- {
- //unable to return the backup to required filename
- LOGGER.error("Could not rename the new log4j configuration file into place, and unable to restore original file");
- throw new IOException("Could not rename the new log4j configuration file into place, and unable to restore original file");
- }
-
- LOGGER.error("Could not rename the new log4j configuration file into place");
- throw new IOException("Could not rename the new log4j configuration file into place");
- }
}
//method to parse the XML configuration file, validating it in the process, and returning a DOM Document of the content.
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
index e7b5d65c65..b0ef11bc1b 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
@@ -71,6 +71,7 @@ import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.store.MessageStoreCreator;
import org.apache.qpid.server.util.MapValueConverter;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+import org.apache.qpid.util.SystemUtils;
public class BrokerAdapter extends AbstractAdapter implements Broker, ConfigurationChangeListener
{
@@ -750,9 +751,7 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, Configurat
}
else if(OPERATING_SYSTEM.equals(name))
{
- return System.getProperty("os.name") + " "
- + System.getProperty("os.version") + " "
- + System.getProperty("os.arch");
+ return SystemUtils.getOSString();
}
else if(PLATFORM.equals(name))
{
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
index 9d16f4b927..8e7916e4b2 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
@@ -54,6 +54,7 @@ import org.apache.qpid.server.stats.StatisticsCounter;
import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+import org.apache.qpid.util.SystemUtils;
/**
@@ -339,9 +340,9 @@ public class ApplicationRegistry implements IApplicationRegistry
logActor.message(BrokerMessages.PLATFORM(System.getProperty("java.vendor"),
System.getProperty("java.runtime.version", System.getProperty("java.version")),
- System.getProperty("os.name"),
- System.getProperty("os.version"),
- System.getProperty("os.arch")));
+ SystemUtils.getOSName(),
+ SystemUtils.getOSVersion(),
+ SystemUtils.getOSArch()));
logActor.message(BrokerMessages.MAX_MEMORY(Runtime.getRuntime().maxMemory()));
}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java
index 8eed1fa5a4..05b0052bf1 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/store/JsonFileConfigStore.java
@@ -134,26 +134,32 @@ public class JsonFileConfigStore implements DurableConfigurationStore
return file.exists();
}
- private void getFileLock() throws IOException, AMQStoreException
+ private void getFileLock() throws AMQStoreException
{
File lockFile = new File(_directoryName, _name + ".lck");
- lockFile.createNewFile();
-
- FileOutputStream out = new FileOutputStream(lockFile);
- FileChannel channel = out.getChannel();
try
{
+ lockFile.createNewFile();
+ lockFile.deleteOnExit();
+
+ @SuppressWarnings("resource")
+ FileOutputStream out = new FileOutputStream(lockFile);
+ FileChannel channel = out.getChannel();
_fileLock = channel.tryLock();
}
+ catch (IOException ioe)
+ {
+ throw new AMQStoreException("Cannot create the lock file " + lockFile.getName(), ioe);
+ }
catch(OverlappingFileLockException e)
{
_fileLock = null;
}
+
if(_fileLock == null)
{
- throw new AMQStoreException("Cannot get lock on file " + lockFile.getAbsolutePath() + " is another instance running?");
+ throw new AMQStoreException("Cannot get lock on file " + lockFile.getAbsolutePath() + ". Is another instance running?");
}
- lockFile.deleteOnExit();
}
private void checkDirectoryIsWritable(String directoryName) throws AMQStoreException
@@ -185,7 +191,6 @@ public class JsonFileConfigStore implements DurableConfigurationStore
Map data = _objectMapper.readValue(new File(_directoryName,_configFileName),Map.class);
Collection<Class<? extends ConfiguredObject>> childClasses =
MODEL.getChildTypes(VirtualHost.class);
- String modelVersion = (String) data.remove("modelVersion");
Object configVersion;
if((configVersion = data.remove("configVersion")) instanceof Integer)
{
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java
index 72b34868ba..e55e700489 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/logging/log4j/LoggingManagementFacadeTest.java
@@ -19,14 +19,11 @@
*/
package org.apache.qpid.server.logging.log4j;
-import java.io.File;
-import java.io.InputStream;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Level;
import org.apache.qpid.test.utils.TestFileUtils;
-import org.apache.qpid.util.FileUtils;
import junit.framework.TestCase;