diff options
author | Robert Godfrey <rgodfrey@apache.org> | 2010-09-12 22:40:40 +0000 |
---|---|---|
committer | Robert Godfrey <rgodfrey@apache.org> | 2010-09-12 22:40:40 +0000 |
commit | 8c8130d0288446f88deef393823cccffcaed474d (patch) | |
tree | 781c5801bc2e3d2f84724bec6c959b2af329f3bd | |
parent | 8a4c51f79be29149fa30a01e7fab6f36301f24bb (diff) | |
download | qpid-python-8c8130d0288446f88deef393823cccffcaed474d.tar.gz |
QPID-2857 : Address issues found by running FindBugs against the Java codebase
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@996393 13f79535-47bb-0310-9956-ffa450edef68
159 files changed, 1803 insertions, 1285 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java b/qpid/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java index 83a6ff705d..4426a7aeec 100644 --- a/qpid/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java +++ b/qpid/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java @@ -106,9 +106,6 @@ public class QpidCompositeRollingAppender extends FileAppender /** Helper class to determine next rollover time */ RollingCalendar rc = new RollingCalendar(); - /** Current period for roll overs */ - int checkPeriod = TOP_OF_TROUBLE; - /** The default maximum file size is 10MB. */ protected long maxFileSize = 10 * 1024 * 1024; @@ -1037,23 +1034,32 @@ public class QpidCompositeRollingAppender extends FileAppender { // Create the GZIP output stream GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(target)); + try + { + // Open the input file + FileInputStream in = new FileInputStream(from); + try + { + // Transfer bytes from the input file to the GZIP output stream + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) + { + out.write(buf, 0, len); + } + } + finally + { + in.close(); + } - // Open the input file - FileInputStream in = new FileInputStream(from); - - // Transfer bytes from the input file to the GZIP output stream - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) + // Complete the GZIP file + out.finish(); + } + finally { - out.write(buf, 0, len); + out.close(); } - - in.close(); - - // Complete the GZIP file - out.finish(); - out.close(); // Remove old file. from.delete(); } @@ -1068,7 +1074,7 @@ public class QpidCompositeRollingAppender extends FileAppender } } - private class CompressJob + private static class CompressJob { File _from, _to; diff --git a/qpid/java/broker/src/main/java/org/apache/log4j/xml/QpidLog4JConfigurator.java b/qpid/java/broker/src/main/java/org/apache/log4j/xml/QpidLog4JConfigurator.java index 6fa412cce6..1200ba6e0b 100644 --- a/qpid/java/broker/src/main/java/org/apache/log4j/xml/QpidLog4JConfigurator.java +++ b/qpid/java/broker/src/main/java/org/apache/log4j/xml/QpidLog4JConfigurator.java @@ -166,7 +166,7 @@ public class QpidLog4JConfigurator private static String constructMessage(final String msg, final SAXParseException ex) { - return new String(msg + ": Line " + ex.getLineNumber()+" column " +ex.getColumnNumber() + ": " + ex.getMessage()); + return msg + ": Line " + ex.getLineNumber()+" column " +ex.getColumnNumber() + ": " + ex.getMessage(); } } @@ -252,10 +252,11 @@ public class QpidLog4JConfigurator loggersLevels.put("Root", rootLoggerlevelString); - for (String loggerName : loggersLevels.keySet()) + for (Map.Entry<String, String> entry : loggersLevels.entrySet()) { - String levelString = loggersLevels.get(loggerName); - + String loggerName = entry.getKey(); + String levelString = entry.getValue(); + //let log4j replace any properties in the string String log4jConfiguredString = domConfig.subst(levelString); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/configuration/Configuration.java b/qpid/java/broker/src/main/java/org/apache/qpid/configuration/Configuration.java index 40ff590a0a..0b63c68854 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/configuration/Configuration.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/configuration/Configuration.java @@ -178,7 +178,7 @@ public class Configuration } - public class InitException extends Exception + public static class InitException extends Exception { InitException(String msg, Throwable cause) { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/qmf/ManagementExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/qmf/ManagementExchange.java index 67620d384b..593c1616fb 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/qmf/ManagementExchange.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/qmf/ManagementExchange.java @@ -90,7 +90,6 @@ public class ManagementExchange implements Exchange, QMFService.Listener public void enqueue(ServerMessage message) throws AMQException { - AMQMessageHeader h = message.getMessageHeader(); long size = message.getSize(); ByteBuffer buf = ByteBuffer.allocate((int) size); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/qmf/QMFMessage.java b/qpid/java/broker/src/main/java/org/apache/qpid/qmf/QMFMessage.java index de9bf1e9cb..895ff643a2 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/qmf/QMFMessage.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/qmf/QMFMessage.java @@ -185,7 +185,7 @@ public class QMFMessage implements ServerMessage, InboundMessage, AMQMessageHead return len; } - private class QMFMessageReference extends MessageReference<QMFMessage> + private static class QMFMessageReference extends MessageReference<QMFMessage> { public QMFMessageReference(QMFMessage message) { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/qmf/QMFService.java b/qpid/java/broker/src/main/java/org/apache/qpid/qmf/QMFService.java index 7e999a720b..7ed6a9114a 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/qmf/QMFService.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/qmf/QMFService.java @@ -467,7 +467,7 @@ public class QMFService implements ConfigStore.ConfigEventListener, Closeable classObjectsById.put(object.getId(),qmfObject); - if(classObjects.putIfAbsent(object, qmfObject) == null); + if(classObjects.putIfAbsent(object, qmfObject) == null) { objectAdded(qmfObject); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java index 811e45f4ae..a612f280d6 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java @@ -106,15 +106,7 @@ public class AMQBrokerManagerMBean extends AMQManagedObject implements ManagedBr */ public List<String> retrieveQueueAttributeNames() throws IOException { - List<String> attributeList = new ArrayList<String>(); - for(String attr : ManagedQueue.QUEUE_ATTRIBUTES) - { - attributeList.add(attr); - } - - Collections.sort(attributeList); - - return attributeList; + return ManagedQueue.QUEUE_ATTRIBUTES; } /** @@ -153,7 +145,7 @@ public class AMQBrokerManagerMBean extends AMQManagedObject implements ManagedBr } catch (Exception e) { - attributeValues.add(new String("-")); + attributeValues.add("-"); } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java index 13927f28ab..452ddf5895 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java @@ -592,9 +592,16 @@ public class Main } else { - Properties fallbackProps = new Properties(); - fallbackProps.load(propsFile); - PropertyConfigurator.configure(fallbackProps); + try + { + Properties fallbackProps = new Properties(); + fallbackProps.load(propsFile); + PropertyConfigurator.configure(fallbackProps); + } + finally + { + propsFile.close(); + } } } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigStore.java index 572d886c18..0e03e33be8 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigStore.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigStore.java @@ -27,6 +27,7 @@ import java.util.Collections; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; public class ConfigStore { @@ -36,14 +37,14 @@ public class ConfigStore private ConcurrentHashMap<ConfigObjectType, CopyOnWriteArrayList<ConfigEventListener>> _listenerMap = new ConcurrentHashMap<ConfigObjectType, CopyOnWriteArrayList<ConfigEventListener>>(); - private SystemConfig _root; + private AtomicReference<SystemConfig> _root = new AtomicReference<SystemConfig>(null); private final AtomicLong _objectIdSource = new AtomicLong(0l); public enum Event { - CREATED, DELETED; + CREATED, DELETED } public interface ConfigEventListener<T extends ConfigObjectType<T,C>, C extends ConfiguredObject<T, C>> @@ -151,11 +152,10 @@ public class ConfigStore } } - public synchronized boolean setRoot(SystemConfig object) + public boolean setRoot(SystemConfig object) { - if(_root == null) + if(_root.compareAndSet(null,object)) { - _root = object; addConfiguredObject(object); return true; } @@ -173,7 +173,7 @@ public class ConfigStore public SystemConfig getRoot() { - return _root; + return _root.get(); } public static ConfigStore newInstance() diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java index 7681354f19..45c52a8891 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java @@ -339,7 +339,7 @@ public class ServerConfiguration extends ConfigurationPlugin implements SignalHa locale = new Locale(parts[0], parts[1]); break; default: - String variant = parts[2]; + StringBuilder variant = new StringBuilder(parts[2]); // If we have a variant such as the Java doc suggests for Spanish // Traditional_WIN we may end up with more than 3 parts on a // split with '_'. So we should recombine the variant. @@ -347,11 +347,11 @@ public class ServerConfiguration extends ConfigurationPlugin implements SignalHa { for (int index = 3; index < parts.length; index++) { - variant = variant + "_" + parts[index]; + variant.append('_').append(parts[index]); } } - locale = new Locale(parts[0], parts[1], variant); + locale = new Locale(parts[0], parts[1], variant.toString()); } return locale; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java index 1245efdafa..e523eb24fb 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/TopicExchange.java @@ -251,7 +251,7 @@ public class TopicExchange extends AbstractExchange { for(Binding b : _bindings.keySet()) { - if(b.getBindingKey().equals(routingKey)) + if(b.getBindingKey().equals(routingKey.toString())) { return true; } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/headers/HeadersParser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/headers/HeadersParser.java index 85e74122c3..0e3a3894fe 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/headers/HeadersParser.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/exchange/headers/HeadersParser.java @@ -425,6 +425,8 @@ public class HeadersParser public boolean equals(Object o) { + assert o != null; + assert o instanceof KeyValuePair; KeyValuePair other = (KeyValuePair)o; return (_key == other._key) && (_value == null ? other._value == null : _value.equals(other._value)); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/federation/Bridge.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/federation/Bridge.java index a4974c75ff..befa979d37 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/federation/Bridge.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/federation/Bridge.java @@ -662,6 +662,8 @@ public class Bridge implements BridgeConfig public void setSession(final Session session) { + assert session instanceof ServerSession; + session.setSessionListener(this); ExchangeRegistry exchangeRegistry = getVirtualHost().getExchangeRegistry(); @@ -750,6 +752,8 @@ public class Bridge implements BridgeConfig public void setSession(final Session session) { + assert session instanceof ServerSession; + session.setSessionListener(this); QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ArithmeticExpression.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ArithmeticExpression.java index 2ead9e57af..221d23ef0d 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ArithmeticExpression.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ArithmeticExpression.java @@ -163,13 +163,13 @@ public abstract class ArithmeticExpression extends BinaryExpression { case INTEGER: - return new Integer(left.intValue() + right.intValue()); + return Integer.valueOf(left.intValue() + right.intValue()); case LONG: - return new Long(left.longValue() + right.longValue()); + return Long.valueOf(left.longValue() + right.longValue()); default: - return new Double(left.doubleValue() + right.doubleValue()); + return Double.valueOf(left.doubleValue() + right.doubleValue()); } } @@ -179,13 +179,13 @@ public abstract class ArithmeticExpression extends BinaryExpression { case INTEGER: - return new Integer(left.intValue() - right.intValue()); + return Integer.valueOf(left.intValue() - right.intValue()); case LONG: - return new Long(left.longValue() - right.longValue()); + return Long.valueOf(left.longValue() - right.longValue()); default: - return new Double(left.doubleValue() - right.doubleValue()); + return Double.valueOf(left.doubleValue() - right.doubleValue()); } } @@ -195,24 +195,24 @@ public abstract class ArithmeticExpression extends BinaryExpression { case INTEGER: - return new Integer(left.intValue() * right.intValue()); + return Integer.valueOf(left.intValue() * right.intValue()); case LONG: - return new Long(left.longValue() * right.longValue()); + return Long.valueOf(left.longValue() * right.longValue()); default: - return new Double(left.doubleValue() * right.doubleValue()); + return Double.valueOf(left.doubleValue() * right.doubleValue()); } } protected Number divide(Number left, Number right) { - return new Double(left.doubleValue() / right.doubleValue()); + return Double.valueOf(left.doubleValue() / right.doubleValue()); } protected Number mod(Number left, Number right) { - return new Double(left.doubleValue() % right.doubleValue()); + return Double.valueOf(left.doubleValue() % right.doubleValue()); } private int numberType(Number left, Number right) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java index f0650cb642..aad9d41174 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java @@ -45,30 +45,30 @@ public abstract class ComparisonExpression extends BinaryExpression implements B return LogicExpression.createOR(createLessThan(value, left), createGreaterThan(value, right)); } - private static final HashSet REGEXP_CONTROL_CHARS = new HashSet(); + private static final HashSet<Character> REGEXP_CONTROL_CHARS = new HashSet<Character>(); static { - REGEXP_CONTROL_CHARS.add(new Character('.')); - REGEXP_CONTROL_CHARS.add(new Character('\\')); - REGEXP_CONTROL_CHARS.add(new Character('[')); - REGEXP_CONTROL_CHARS.add(new Character(']')); - REGEXP_CONTROL_CHARS.add(new Character('^')); - REGEXP_CONTROL_CHARS.add(new Character('$')); - REGEXP_CONTROL_CHARS.add(new Character('?')); - REGEXP_CONTROL_CHARS.add(new Character('*')); - REGEXP_CONTROL_CHARS.add(new Character('+')); - REGEXP_CONTROL_CHARS.add(new Character('{')); - REGEXP_CONTROL_CHARS.add(new Character('}')); - REGEXP_CONTROL_CHARS.add(new Character('|')); - REGEXP_CONTROL_CHARS.add(new Character('(')); - REGEXP_CONTROL_CHARS.add(new Character(')')); - REGEXP_CONTROL_CHARS.add(new Character(':')); - REGEXP_CONTROL_CHARS.add(new Character('&')); - REGEXP_CONTROL_CHARS.add(new Character('<')); - REGEXP_CONTROL_CHARS.add(new Character('>')); - REGEXP_CONTROL_CHARS.add(new Character('=')); - REGEXP_CONTROL_CHARS.add(new Character('!')); + REGEXP_CONTROL_CHARS.add('.'); + REGEXP_CONTROL_CHARS.add('\\'); + REGEXP_CONTROL_CHARS.add('['); + REGEXP_CONTROL_CHARS.add(']'); + REGEXP_CONTROL_CHARS.add('^'); + REGEXP_CONTROL_CHARS.add('$'); + REGEXP_CONTROL_CHARS.add('?'); + REGEXP_CONTROL_CHARS.add('*'); + REGEXP_CONTROL_CHARS.add('+'); + REGEXP_CONTROL_CHARS.add('{'); + REGEXP_CONTROL_CHARS.add('}'); + REGEXP_CONTROL_CHARS.add('|'); + REGEXP_CONTROL_CHARS.add('('); + REGEXP_CONTROL_CHARS.add(')'); + REGEXP_CONTROL_CHARS.add(':'); + REGEXP_CONTROL_CHARS.add('&'); + REGEXP_CONTROL_CHARS.add('<'); + REGEXP_CONTROL_CHARS.add('>'); + REGEXP_CONTROL_CHARS.add('='); + REGEXP_CONTROL_CHARS.add('!'); } static class LikeExpression extends UnaryExpression implements BooleanExpression @@ -109,7 +109,7 @@ public abstract class ComparisonExpression extends BinaryExpression implements B { regexp.append("."); // match one } - else if (REGEXP_CONTROL_CHARS.contains(new Character(c))) + else if (REGEXP_CONTROL_CHARS.contains(c)) { regexp.append("\\x"); regexp.append(Integer.toHexString(0xFFFF & c)); @@ -415,23 +415,23 @@ public abstract class ComparisonExpression extends BinaryExpression implements B { if (rc == Short.class) { - lv = new Short(((Number) lv).shortValue()); + lv = ((Number) lv).shortValue(); } else if (rc == Integer.class) { - lv = new Integer(((Number) lv).intValue()); + lv = ((Number) lv).intValue(); } else if (rc == Long.class) { - lv = new Long(((Number) lv).longValue()); + lv = ((Number) lv).longValue(); } else if (rc == Float.class) { - lv = new Float(((Number) lv).floatValue()); + lv = ((Number) lv).floatValue(); } else if (rc == Double.class) { - lv = new Double(((Number) lv).doubleValue()); + lv = ((Number) lv).doubleValue(); } else { @@ -442,19 +442,19 @@ public abstract class ComparisonExpression extends BinaryExpression implements B { if (rc == Integer.class) { - lv = new Integer(((Number) lv).intValue()); + lv = ((Number) lv).intValue(); } else if (rc == Long.class) { - lv = new Long(((Number) lv).longValue()); + lv = ((Number) lv).longValue(); } else if (rc == Float.class) { - lv = new Float(((Number) lv).floatValue()); + lv = ((Number) lv).floatValue(); } else if (rc == Double.class) { - lv = new Double(((Number) lv).doubleValue()); + lv = ((Number) lv).doubleValue(); } else { @@ -465,15 +465,15 @@ public abstract class ComparisonExpression extends BinaryExpression implements B { if (rc == Long.class) { - lv = new Long(((Number) lv).longValue()); + lv = ((Number) lv).longValue(); } else if (rc == Float.class) { - lv = new Float(((Number) lv).floatValue()); + lv = ((Number) lv).floatValue(); } else if (rc == Double.class) { - lv = new Double(((Number) lv).doubleValue()); + lv = ((Number) lv).doubleValue(); } else { @@ -484,15 +484,15 @@ public abstract class ComparisonExpression extends BinaryExpression implements B { if (rc == Integer.class) { - rv = new Long(((Number) rv).longValue()); + rv = ((Number) rv).longValue(); } else if (rc == Float.class) { - lv = new Float(((Number) lv).floatValue()); + lv = ((Number) lv).floatValue(); } else if (rc == Double.class) { - lv = new Double(((Number) lv).doubleValue()); + lv = ((Number) lv).doubleValue(); } else { @@ -503,15 +503,15 @@ public abstract class ComparisonExpression extends BinaryExpression implements B { if (rc == Integer.class) { - rv = new Float(((Number) rv).floatValue()); + rv = ((Number) rv).floatValue(); } else if (rc == Long.class) { - rv = new Float(((Number) rv).floatValue()); + rv = ((Number) rv).floatValue(); } else if (rc == Double.class) { - lv = new Double(((Number) lv).doubleValue()); + lv = ((Number) lv).doubleValue(); } else { @@ -522,15 +522,15 @@ public abstract class ComparisonExpression extends BinaryExpression implements B { if (rc == Integer.class) { - rv = new Double(((Number) rv).doubleValue()); + rv = ((Number) rv).doubleValue(); } else if (rc == Long.class) { - rv = new Double(((Number) rv).doubleValue()); + rv = ((Number) rv).doubleValue(); } else if (rc == Float.class) { - rv = new Float(((Number) rv).doubleValue()); + rv = ((Number) rv).doubleValue(); } else { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ConstantExpression.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ConstantExpression.java index 15cb770216..5cc9ca8ef2 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ConstantExpression.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/ConstantExpression.java @@ -77,7 +77,7 @@ public class ConstantExpression implements Expression long l = value.longValue(); if ((Integer.MIN_VALUE <= l) && (l <= Integer.MAX_VALUE)) { - value = new Integer(value.intValue()); + value = value.intValue(); } return new ConstantExpression(value); @@ -85,11 +85,11 @@ public class ConstantExpression implements Expression public static ConstantExpression createFromHex(String text) { - Number value = new Long(Long.parseLong(text.substring(2), 16)); + Number value = Long.parseLong(text.substring(2), 16); long l = value.longValue(); if ((Integer.MIN_VALUE <= l) && (l <= Integer.MAX_VALUE)) { - value = new Integer(value.intValue()); + value = value.intValue(); } return new ConstantExpression(value); @@ -97,11 +97,11 @@ public class ConstantExpression implements Expression public static ConstantExpression createFromOctal(String text) { - Number value = new Long(Long.parseLong(text, 8)); + Number value = Long.parseLong(text, 8); long l = value.longValue(); if ((Integer.MIN_VALUE <= l) && (l <= Integer.MAX_VALUE)) { - value = new Integer(value.intValue()); + value = value.intValue(); } return new ConstantExpression(value); @@ -141,7 +141,7 @@ public class ConstantExpression implements Expression if (value instanceof Boolean) { - return ((Boolean) value).booleanValue() ? "TRUE" : "FALSE"; + return ((Boolean) value) ? "TRUE" : "FALSE"; } if (value instanceof String) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/UnaryExpression.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/UnaryExpression.java index 9e03ecd8bd..557af95001 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/UnaryExpression.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/filter/UnaryExpression.java @@ -110,19 +110,19 @@ public abstract class UnaryExpression implements Expression Class clazz = left.getClass(); if (clazz == Integer.class) { - return new Integer(-left.intValue()); + return -left.intValue(); } else if (clazz == Long.class) { - return new Long(-left.longValue()); + return -left.longValue(); } else if (clazz == Float.class) { - return new Float(-left.floatValue()); + return -left.floatValue(); } else if (clazz == Double.class) { - return new Double(-left.doubleValue()); + return -left.doubleValue(); } else if (clazz == BigDecimal.class) { @@ -135,7 +135,7 @@ public abstract class UnaryExpression implements Expression if (BD_LONG_MIN_VALUE.compareTo(bd) == 0) { - return new Long(Long.MIN_VALUE); + return Long.MIN_VALUE; } return bd; @@ -186,14 +186,7 @@ public abstract class UnaryExpression implements Expression */ public boolean equals(Object o) { - - if ((o == null) || !this.getClass().equals(o.getClass())) - { - return false; - } - - return toString().equals(o.toString()); - + return ((o != null) && this.getClass().equals(o.getClass())) && toString().equals(o.toString()); } /** diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/management/LoggingManagementMBean.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/management/LoggingManagementMBean.java index 36e8f6cf84..258552f2f5 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/management/LoggingManagementMBean.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/management/LoggingManagementMBean.java @@ -528,9 +528,10 @@ public class LoggingManagementMBean extends AMQManagedObject implements LoggingM Map<String,String> levels = retrieveConfigFileLoggersLevels(_log4jConfigFileName); - for (String loggerName : levels.keySet()) + for (Map.Entry<String,String> entry : levels.entrySet()) { - String level = levels.get(loggerName); + String loggerName = entry.getKey(); + String level = entry.getValue(); try { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/BindingLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/BindingLogSubject.java index 69139d38a3..536c5cdb0a 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/BindingLogSubject.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/BindingLogSubject.java @@ -37,7 +37,7 @@ public class BindingLogSubject extends AbstractLogSubject * 3 - Queue Name * 4 - Binding RoutingKey */ - protected static String BINDING_FORMAT = "vh(/{0})/ex({1}/{2})/qu({3})/rk({4})"; + protected static final String BINDING_FORMAT = "vh(/{0})/ex({1}/{2})/qu({3})/rk({4})"; /** * Create a BindingLogSubject that Logs in the following format. diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ChannelLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ChannelLogSubject.java index dc6e79a214..7660804b19 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ChannelLogSubject.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ChannelLogSubject.java @@ -36,7 +36,7 @@ public class ChannelLogSubject extends AbstractLogSubject * 3 - Virtualhost * 4 - Channel ID */ - public static String CHANNEL_FORMAT = ConnectionLogSubject.CONNECTION_FORMAT + public static final String CHANNEL_FORMAT = ConnectionLogSubject.CONNECTION_FORMAT + "/ch:{4}"; public ChannelLogSubject(AMQChannel channel) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubject.java index 6c41718177..eec7888b2d 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubject.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubject.java @@ -32,7 +32,7 @@ public class ConnectionLogSubject extends AbstractLogSubject * 0 - Connection ID * 1 - Remote Address */ - public static String SOCKET_FORMAT = "con:{0}({1})"; + public static final String SOCKET_FORMAT = "con:{0}({1})"; /** * LOG FORMAT for the ConnectionLogSubject, diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubject.java index 0fc2d7392f..d954ff64d7 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubject.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/ExchangeLogSubject.java @@ -35,7 +35,7 @@ public class ExchangeLogSubject extends AbstractLogSubject * 1 - Exchange Type * 2 - Exchange Name */ - protected static String BINDING_FORMAT = "vh(/{0})/ex({1}/{2})"; + protected static final String BINDING_FORMAT = "vh(/{0})/ex({1}/{2})"; /** Create an ExchangeLogSubject that Logs in the following format. */ public ExchangeLogSubject(Exchange exchange, VirtualHost vhost) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubject.java index e11cbba4f4..0417a218ee 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubject.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/MessageStoreLogSubject.java @@ -34,7 +34,7 @@ public class MessageStoreLogSubject extends AbstractLogSubject * 0 - Virtualhost Name * 1 - Message Store Type */ - protected static String BINDING_FORMAT = "vh(/{0})/ms({1})"; + protected static final String BINDING_FORMAT = "vh(/{0})/ms({1})"; /** Create an ExchangeLogSubject that Logs in the following format. */ public MessageStoreLogSubject(VirtualHost vhost, MessageStore store) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/QueueLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/QueueLogSubject.java index b132d9e93f..be96f66074 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/QueueLogSubject.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/QueueLogSubject.java @@ -33,7 +33,7 @@ public class QueueLogSubject extends AbstractLogSubject * 0 - Virtualhost name * 1 - queue name */ - public static String LOG_FORMAT = "vh(/{0})/qu({1})"; + public static final String LOG_FORMAT = "vh(/{0})/qu({1})"; /** Create an QueueLogSubject that Logs in the following format. */ public QueueLogSubject(AMQQueue queue) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubject.java index 0683c8e361..5d82e97768 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubject.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubject.java @@ -34,7 +34,7 @@ public class SubscriptionLogSubject extends AbstractLogSubject * * 0 - Subscription ID */ - public static String SUBSCRIPTION_FORMAT = "sub:{0}"; + public static final String SUBSCRIPTION_FORMAT = "sub:{0}"; /** * Create an QueueLogSubject that Logs in the following format. diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java index 03e1d1fcaa..0334a856c1 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/JMXManagedObjectRegistry.java @@ -326,7 +326,7 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry * made using the object reference will not be affected and continue to operate normally. */ - private class CustomRMIServerSocketFactory implements RMIServerSocketFactory + private static class CustomRMIServerSocketFactory implements RMIServerSocketFactory { public ServerSocket createServerSocket(int port) throws IOException @@ -334,7 +334,7 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry return new NoLocalAddressServerSocket(port); } - private class NoLocalAddressServerSocket extends ServerSocket + private static class NoLocalAddressServerSocket extends ServerSocket { NoLocalAddressServerSocket(int port) throws IOException { @@ -350,7 +350,7 @@ public class JMXManagedObjectRegistry implements ManagedObjectRegistry } } - private class NoLocalAddressSocket extends Socket + private static class NoLocalAddressSocket extends Socket { @Override public InetAddress getInetAddress() diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanIntrospector.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanIntrospector.java index 9c2a455897..17a6851abc 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanIntrospector.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanIntrospector.java @@ -361,19 +361,21 @@ class MBeanIntrospector { */ private static MBeanConstructorInfo getMBeanConstructorInfo(Constructor cons) { - String desc = null; + String desc = _defaultConstructorDescription; Annotation anno = cons.getAnnotation(MBeanConstructor.class); if (anno != null && MBeanConstructor.class.isInstance(anno)) { desc = MBeanConstructor.class.cast(anno).value(); + if(desc == null) + { + desc = _defaultConstructorDescription; + } } //MBeanParameterInfo[] paramsInfo = getParametersInfo(cons.getParameterAnnotations(), // cons.getParameterTypes()); - return new MBeanConstructorInfo(cons.getName(), - desc != null ? _defaultConstructorDescription : desc , - null); + return new MBeanConstructorInfo(cons.getName(), desc, null); } /** diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java index 19b4586017..964b5ed5a0 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java @@ -294,7 +294,9 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler, Notificati public void handleNotification(Notification notification, Object handback) { - // only RMI Connections are serviced here, Local API atta + assert notification instanceof JMXConnectionNotification; + + // only RMI Connections are serviced here, Local API atta // rmi://169.24.29.116 guest 3 String[] connectionData = ((JMXConnectionNotification) notification).getConnectionId().split(" "); String user = connectionData[1]; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData.java index 2f8c2e09a2..30bea7b6e6 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData.java @@ -110,7 +110,6 @@ public class MessageMetaData implements StorableMessageMetaData public int getStorableSize() { - BasicContentHeaderProperties properties = (BasicContentHeaderProperties) (_contentHeaderBody.properties); int size = _contentHeaderBody.getSize(); size += 4; size += EncodingUtils.encodedShortStringLength(_messagePublishInfo.getExchange()); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageTransferHeader.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageTransferHeader.java index a15e16a64f..0296735699 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageTransferHeader.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageTransferHeader.java @@ -56,7 +56,7 @@ class MessageTransferHeader implements AMQMessageHeader public long getExpiration() { - return _deliveryProps == null ? null : _deliveryProps.getExpiration(); + return _deliveryProps == null ? 0L : _deliveryProps.getExpiration(); } public String getMessageId() diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java index 5a7c9923f8..c55c07a145 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolEngine.java @@ -652,7 +652,7 @@ public class AMQProtocolEngine implements ProtocolEngine, Managable, AMQProtocol // InvalidArgument and if they then decide to close the session/connection then the there will be time // for that to occur i.e. a new close method be sent before the exeption handling can mark the session closed. //removeChannel(channelId); - _closingChannelsList.remove(new Integer(channelId)); + _closingChannelsList.remove(channelId); } private void markChannelAwaitingCloseOk(int channelId) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java index b3cb90fc6e..e894dda341 100755 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java @@ -382,7 +382,7 @@ private static final byte[] AMQP_0_9_1_HEADER = { _networkDriver.send(ByteBuffer.wrap(newestSupported)); - newDelegate = new ClosedDelegateProtocolEngine(); + _delegate = new ClosedDelegateProtocolEngine(); } else { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java index 6bfd7470ac..bee55118ba 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueueFactory.java @@ -170,9 +170,9 @@ public class AMQQueueFactory conflationKey = QPID_LVQ_KEY; } } - else if(arguments.containsKey(X_QPID_PRIORITIES)) + else if(arguments.containsKey(X_QPID_PRIORITIES.toString())) { - Object prioritiesObj = arguments.get(X_QPID_PRIORITIES); + Object prioritiesObj = arguments.get(X_QPID_PRIORITIES.toString()); if(prioritiesObj instanceof Number) { priorities = ((Number)prioritiesObj).intValue(); @@ -202,9 +202,9 @@ public class AMQQueueFactory { for(QueueProperty p : DECLAREABLE_PROPERTIES) { - if(arguments.containsKey(p.getArgumentName())) + if(arguments.containsKey(p.getArgumentName().toString())) { - p.setPropertyValue(q, arguments.get(p.getArgumentName())); + p.setPropertyValue(q, arguments.get(p.getArgumentName().toString())); } } } @@ -225,10 +225,8 @@ public class AMQQueueFactory Map<String,Object> arguments = null; if(config.isLVQ() || config.getLVQKey() != null) { - if(arguments == null) - { - arguments = new HashMap<String,Object>(); - } + + arguments = new HashMap<String,Object>(); arguments.put(QPID_LAST_VALUE_QUEUE, 1); arguments.put(QPID_LAST_VALUE_QUEUE_KEY, config.getLVQKey() == null ? QPID_LVQ_KEY : config.getLVQKey()); } @@ -238,10 +236,7 @@ public class AMQQueueFactory int priorities = config.getPriorities(); if(priority || priorities > 0) { - if(arguments == null) - { - arguments = new HashMap<String,Object>(); - } + arguments = new HashMap<String,Object>(); if (priorities < 0) { priorities = 10; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java index 484dd5971d..fc04e1382e 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleAMQQueue.java @@ -162,7 +162,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener private final AtomicLong _stateChangeCount = new AtomicLong(Long.MIN_VALUE); - private AtomicReference _asynchronousRunner = new AtomicReference(null); + private AtomicReference<Runnable> _asynchronousRunner = new AtomicReference<Runnable>(null); private final Executor _asyncDelivery; private AtomicInteger _deliveredMessages = new AtomicInteger(); private AtomicBoolean _stopped = new AtomicBoolean(false); @@ -1085,23 +1085,22 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener */ public List<QueueEntry> getMessagesRangeOnTheQueue(final long fromPosition, final long toPosition) { - List<QueueEntry> entries = getMessagesOnTheQueue(new QueueEntryFilter() - { - private long position = 0; + return getMessagesOnTheQueue(new QueueEntryFilter() + { + private long position = 0; - public boolean accept(QueueEntry entry) - { - position++; - return (position >= fromPosition) && (position <= toPosition); - } + public boolean accept(QueueEntry entry) + { + position++; + return (position >= fromPosition) && (position <= toPosition); + } - public boolean filterComplete() - { - return position >= toPosition; - } - }); + public boolean filterComplete() + { + return position >= toPosition; + } + }); - return entries; } public void moveMessagesToAnotherQueue(final long fromMessageId, @@ -1410,7 +1409,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener adapter.setEntry(entry); final List<? extends BaseQueue> rerouteQueues = _alternateExchange.route(adapter); final ServerMessage message = entry.getMessage(); - if(rerouteQueues != null & rerouteQueues.size() != 0) + if(rerouteQueues != null && rerouteQueues.size() != 0) { txn.enqueue(rerouteQueues, entry.getMessage(), new ServerTransaction.Action() @@ -1801,7 +1800,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener boolean deliveryIncomplete = true; int extraLoops = 1; - Long iterations = new Long(MAX_ASYNC_DELIVERIES); + long iterations = MAX_ASYNC_DELIVERIES; _asynchronousRunner.compareAndSet(runner, null); @@ -1823,7 +1822,7 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener previousStateChangeCount = stateChangeCount; deliveryIncomplete = _subscriptionList.size() != 0; - boolean done = true; + boolean done; SubscriptionList.SubscriptionNodeIterator subscriptionIter = _subscriptionList.iterator(); //iterate over the subscribers and try to advance their pointer @@ -1833,10 +1832,9 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener sub.getSendLock(); try { - if (sub != null) - { - done = attemptDelivery(sub); - } + + done = attemptDelivery(sub); + if (done) { if (extraLoops == 0) @@ -2050,6 +2048,8 @@ public class SimpleAMQQueue implements AMQQueue, Subscription.StateListener public boolean equals(Object o) { + assert o != null; + assert o instanceof QueueEntryListener; return _sub == ((QueueEntryListener) o)._sub; } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java index 8721da0f78..334b7f4ea9 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/SimpleQueueEntryList.java @@ -164,7 +164,7 @@ public class SimpleQueueEntryList implements QueueEntryList } - public class QueueEntryIteratorImpl implements QueueEntryIterator + public static class QueueEntryIteratorImpl implements QueueEntryIterator { private QueueEntryImpl _lastNode; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectProperties.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectProperties.java index af47ed6bf9..70a9ea5356 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectProperties.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/access/ObjectProperties.java @@ -21,6 +21,7 @@ package org.apache.qpid.server.security.access; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.commons.lang.StringUtils; import org.apache.qpid.framing.AMQShortString; @@ -288,9 +289,11 @@ public class ObjectProperties extends HashMap<ObjectProperties.Property, String> return false; } - for (Property key : properties.keySet()) + for (Map.Entry<Property,String> entry : properties.entrySet()) { - String ruleValue = properties.get(key); + Property key = entry.getKey(); + String ruleValue = entry.getValue(); + String thisValue = get(key); if (!valueMatches(thisValue, ruleValue)) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java index 6ca9c8e762..5a92b33e43 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabase.java @@ -250,10 +250,7 @@ public class Base64MD5PasswordFilePrincipalDatabase implements PrincipalDatabase } finally { - if (_userUpdate.isHeldByCurrentThread()) - { - _userUpdate.unlock(); - } + _userUpdate.unlock(); } } catch (Exception e) @@ -300,10 +297,7 @@ public class Base64MD5PasswordFilePrincipalDatabase implements PrincipalDatabase } finally { - if (_userUpdate.isHeldByCurrentThread()) - { - _userUpdate.unlock(); - } + _userUpdate.unlock(); } } @@ -335,10 +329,7 @@ public class Base64MD5PasswordFilePrincipalDatabase implements PrincipalDatabase } finally { - if (_userUpdate.isHeldByCurrentThread()) - { - _userUpdate.unlock(); - } + _userUpdate.unlock(); } return true; @@ -420,10 +411,7 @@ public class Base64MD5PasswordFilePrincipalDatabase implements PrincipalDatabase } finally { - if (_userUpdate.isHeldByCurrentThread()) - { - _userUpdate.unlock(); - } + _userUpdate.unlock(); } } @@ -567,10 +555,7 @@ public class Base64MD5PasswordFilePrincipalDatabase implements PrincipalDatabase } finally { - if (_userUpdate.isHeldByCurrentThread()) - { - _userUpdate.unlock(); - } + _userUpdate.unlock(); } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java index cea4e90c31..76ebea0321 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabase.java @@ -232,10 +232,7 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase } finally { - if (_userUpdate.isHeldByCurrentThread()) - { - _userUpdate.unlock(); - } + _userUpdate.unlock(); } } @@ -267,10 +264,7 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase } finally { - if (_userUpdate.isHeldByCurrentThread()) - { - _userUpdate.unlock(); - } + _userUpdate.unlock(); } return true; @@ -369,10 +363,7 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase } finally { - if (_userUpdate.isHeldByCurrentThread()) - { - _userUpdate.unlock(); - } + _userUpdate.unlock(); } } @@ -501,10 +492,7 @@ public class PlainPasswordFilePrincipalDatabase implements PrincipalDatabase } finally { - if (_userUpdate.isHeldByCurrentThread()) - { - _userUpdate.unlock(); - } + _userUpdate.unlock(); } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/management/AMQUserManagementMBean.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/management/AMQUserManagementMBean.java index 153b8c25db..a9bee4466f 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/management/AMQUserManagementMBean.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/management/AMQUserManagementMBean.java @@ -192,10 +192,7 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana } finally { - if (_accessRightsUpdate.isHeldByCurrentThread()) - { - _accessRightsUpdate.unlock(); - } + _accessRightsUpdate.unlock(); } return true; @@ -256,10 +253,7 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana } finally { - if (_accessRightsUpdate.isHeldByCurrentThread()) - { - _accessRightsUpdate.unlock(); - } + _accessRightsUpdate.unlock(); } } } @@ -409,16 +403,22 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana _accessRightsUpdate.lock(); Properties accessRights = new Properties(); - accessRights.load(new FileInputStream(_accessFile)); + FileInputStream inStream = new FileInputStream(_accessFile); + try + { + accessRights.load(inStream); + } + finally + { + inStream.close(); + } + checkAccessRights(accessRights); setAccessRights(accessRights); } finally { - if (_accessRightsUpdate.isHeldByCurrentThread()) - { - _accessRightsUpdate.unlock(); - } + _accessRightsUpdate.unlock(); } } else @@ -494,10 +494,7 @@ public class AMQUserManagementMBean extends AMQManagedObject implements UserMana } finally { - if (_accessRightsUpdate.isHeldByCurrentThread()) - { - _accessRightsUpdate.unlock(); - } + _accessRightsUpdate.unlock(); } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePasswordInitialiser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePasswordInitialiser.java index dd0bd096c3..5c13e03886 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePasswordInitialiser.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/UsernamePasswordInitialiser.java @@ -46,7 +46,7 @@ public abstract class UsernamePasswordInitialiser implements AuthenticationProvi private ServerCallbackHandler _callbackHandler; - private class ServerCallbackHandler implements CallbackHandler + private static class ServerCallbackHandler implements CallbackHandler { private final PrincipalDatabase _principalDatabase; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java index 38e84c799b..8020d97364 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/crammd5/CRAMMD5HexInitialiser.java @@ -55,7 +55,7 @@ public class CRAMMD5HexInitialiser extends UsernamePasswordInitialiser } - private class HexifyPrincipalDatabase implements PrincipalDatabase + private static class HexifyPrincipalDatabase implements PrincipalDatabase { private PrincipalDatabase _realPricipalDatabase; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DerbyMessageStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DerbyMessageStore.java index 838867f233..0865165925 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DerbyMessageStore.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DerbyMessageStore.java @@ -22,6 +22,7 @@ package org.apache.qpid.server.store; import java.io.ByteArrayInputStream; import java.io.File; +import java.io.IOException; import java.lang.ref.SoftReference; import java.nio.ByteBuffer; import java.sql.Blob; @@ -277,14 +278,25 @@ public class DerbyMessageStore implements MessageStore if(!tableExists(DB_VERSION_TABLE_NAME, conn)) { Statement stmt = conn.createStatement(); - - stmt.execute(CREATE_DB_VERSION_TABLE); - stmt.close(); + try + { + stmt.execute(CREATE_DB_VERSION_TABLE); + } + finally + { + stmt.close(); + } PreparedStatement pstmt = conn.prepareStatement(INSERT_INTO_DB_VERSION); - pstmt.setInt(1, DB_VERSION); - pstmt.execute(); - pstmt.close(); + try + { + pstmt.setInt(1, DB_VERSION); + pstmt.execute(); + } + finally + { + pstmt.close(); + } } } @@ -295,9 +307,14 @@ public class DerbyMessageStore implements MessageStore if(!tableExists(EXCHANGE_TABLE_NAME, conn)) { Statement stmt = conn.createStatement(); - - stmt.execute(CREATE_EXCHANGE_TABLE); - stmt.close(); + try + { + stmt.execute(CREATE_EXCHANGE_TABLE); + } + finally + { + stmt.close(); + } } } @@ -306,8 +323,14 @@ public class DerbyMessageStore implements MessageStore if(!tableExists(QUEUE_TABLE_NAME, conn)) { Statement stmt = conn.createStatement(); - stmt.execute(CREATE_QUEUE_TABLE); - stmt.close(); + try + { + stmt.execute(CREATE_QUEUE_TABLE); + } + finally + { + stmt.close(); + } } } @@ -316,9 +339,14 @@ public class DerbyMessageStore implements MessageStore if(!tableExists(BINDINGS_TABLE_NAME, conn)) { Statement stmt = conn.createStatement(); - stmt.execute(CREATE_BINDINGS_TABLE); - - stmt.close(); + try + { + stmt.execute(CREATE_BINDINGS_TABLE); + } + finally + { + stmt.close(); + } } } @@ -328,9 +356,14 @@ public class DerbyMessageStore implements MessageStore if(!tableExists(QUEUE_ENTRY_TABLE_NAME, conn)) { Statement stmt = conn.createStatement(); - stmt.execute(CREATE_QUEUE_ENTRY_TABLE); - - stmt.close(); + try + { + stmt.execute(CREATE_QUEUE_ENTRY_TABLE); + } + finally + { + stmt.close(); + } } } @@ -340,9 +373,14 @@ public class DerbyMessageStore implements MessageStore if(!tableExists(META_DATA_TABLE_NAME, conn)) { Statement stmt = conn.createStatement(); - stmt.execute(CREATE_META_DATA_TABLE); - - stmt.close(); + try + { + stmt.execute(CREATE_META_DATA_TABLE); + } + finally + { + stmt.close(); + } } } @@ -353,9 +391,14 @@ public class DerbyMessageStore implements MessageStore if(!tableExists(MESSAGE_CONTENT_TABLE_NAME, conn)) { Statement stmt = conn.createStatement(); + try + { stmt.execute(CREATE_MESSAGE_CONTENT_TABLE); - - stmt.close(); + } + finally + { + stmt.close(); + } } } @@ -365,12 +408,24 @@ public class DerbyMessageStore implements MessageStore private boolean tableExists(final String tableName, final Connection conn) throws SQLException { PreparedStatement stmt = conn.prepareStatement(TABLE_EXISTANCE_QUERY); - stmt.setString(1, tableName); - ResultSet rs = stmt.executeQuery(); - boolean exists = rs.next(); - rs.close(); - stmt.close(); - return exists; + try + { + stmt.setString(1, tableName); + ResultSet rs = stmt.executeQuery(); + try + { + return rs.next(); + } + finally + { + rs.close(); + } + } + finally + { + stmt.close(); + } + } public void recover(ConfigurationRecoveryHandler recoveryHandler) throws AMQException @@ -382,7 +437,7 @@ public class DerbyMessageStore implements MessageStore try { ConfigurationRecoveryHandler.QueueRecoveryHandler qrh = recoveryHandler.begin(this); - List<String> queues = loadQueues(qrh); + loadQueues(qrh); ConfigurationRecoveryHandler.ExchangeRecoveryHandler erh = qrh.completeQueueRecovery(); List<String> exchanges = loadExchanges(erh); @@ -399,42 +454,57 @@ public class DerbyMessageStore implements MessageStore } - private List<String> loadQueues(ConfigurationRecoveryHandler.QueueRecoveryHandler qrh) throws SQLException + private void loadQueues(ConfigurationRecoveryHandler.QueueRecoveryHandler qrh) throws SQLException { Connection conn = newAutoCommitConnection(); + try + { + Statement stmt = conn.createStatement(); + try + { + ResultSet rs = stmt.executeQuery(SELECT_FROM_QUEUE); + try + { - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery(SELECT_FROM_QUEUE); - List<String> queues = new ArrayList<String>(); + while(rs.next()) + { + String queueName = rs.getString(1); + String owner = rs.getString(2); + boolean exclusive = rs.getBoolean(3); + Blob argumentsAsBlob = rs.getBlob(4); + + byte[] dataAsBytes = argumentsAsBlob.getBytes(1,(int) argumentsAsBlob.length()); + FieldTable arguments; + if(dataAsBytes.length > 0) + { + org.apache.mina.common.ByteBuffer buffer = org.apache.mina.common.ByteBuffer.wrap(dataAsBytes); - while(rs.next()) - { - String queueName = rs.getString(1); - String owner = rs.getString(2); - boolean exclusive = rs.getBoolean(3); - Blob argumentsAsBlob = rs.getBlob(4); + arguments = new FieldTable(buffer,buffer.limit()); + } + else + { + arguments = null; + } - byte[] dataAsBytes = argumentsAsBlob.getBytes(1,(int) argumentsAsBlob.length()); - FieldTable arguments; - if(dataAsBytes.length > 0) - { - org.apache.mina.common.ByteBuffer buffer = org.apache.mina.common.ByteBuffer.wrap(dataAsBytes); + qrh.queue(queueName, owner, exclusive, arguments); - arguments = new FieldTable(buffer,buffer.limit()); + } + + } + finally + { + rs.close(); + } } - else + finally { - arguments = null; + stmt.close(); } - - qrh.queue(queueName, owner, exclusive, arguments); - - queues.add(queueName); } - - conn.close(); - - return queues; + finally + { + conn.close(); + } } @@ -448,21 +518,33 @@ public class DerbyMessageStore implements MessageStore conn = newAutoCommitConnection(); Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery(SELECT_FROM_EXCHANGE); - - while(rs.next()) + try { - String exchangeName = rs.getString(1); - String type = rs.getString(2); - boolean autoDelete = rs.getShort(3) != 0; + ResultSet rs = stmt.executeQuery(SELECT_FROM_EXCHANGE); + try + { + while(rs.next()) + { + String exchangeName = rs.getString(1); + String type = rs.getString(2); + boolean autoDelete = rs.getShort(3) != 0; - exchanges.add(exchangeName); + exchanges.add(exchangeName); - erh.exchange(exchangeName, type, autoDelete); + erh.exchange(exchangeName, type, autoDelete); + } + return exchanges; + } + finally + { + rs.close(); + } + } + finally + { + stmt.close(); } - return exchanges; - } finally { @@ -485,31 +567,44 @@ public class DerbyMessageStore implements MessageStore PreparedStatement stmt = conn.prepareStatement(SELECT_FROM_BINDINGS); - ResultSet rs = stmt.executeQuery(); - - - while(rs.next()) + try { - String exchangeName = rs.getString(1); - String queueName = rs.getString(2); - String bindingKey = rs.getString(3); - Blob arguments = rs.getBlob(4); - java.nio.ByteBuffer buf; + ResultSet rs = stmt.executeQuery(); - if(arguments != null && arguments.length() != 0) + try { - byte[] argumentBytes = arguments.getBytes(1, (int) arguments.length()); - buf = java.nio.ByteBuffer.wrap(argumentBytes); + + while(rs.next()) + { + String exchangeName = rs.getString(1); + String queueName = rs.getString(2); + String bindingKey = rs.getString(3); + Blob arguments = rs.getBlob(4); + java.nio.ByteBuffer buf; + + if(arguments != null && arguments.length() != 0) + { + byte[] argumentBytes = arguments.getBytes(1, (int) arguments.length()); + buf = java.nio.ByteBuffer.wrap(argumentBytes); + } + else + { + buf = null; + } + + brh.binding(exchangeName, queueName, bindingKey, buf); + } } - else + finally { - buf = null; + rs.close(); } - - brh.binding(exchangeName, queueName, bindingKey, buf); } - - stmt.close(); + finally + { + stmt.close(); + } + } finally { @@ -529,7 +624,10 @@ public class DerbyMessageStore implements MessageStore try { - DriverManager.getConnection(_connectionURL + ";shutdown=true"); + Connection conn = DriverManager.getConnection(_connectionURL + ";shutdown=true"); + // Shouldn't reach this point - shutdown=true should throw SQLException + conn.close(); + _logger.error("Unable to shut down the store"); } catch (SQLException e) { @@ -563,48 +661,59 @@ public class DerbyMessageStore implements MessageStore public void removeMessage(long messageId) { - Connection conn = null; try { - conn = newConnection(); - PreparedStatement stmt = conn.prepareStatement(DELETE_FROM_META_DATA); - stmt.setLong(1,messageId); - int results = stmt.executeUpdate(); - stmt.close(); - - if (results == 0) + Connection conn = newConnection(); + try { - throw new RuntimeException("Message metadata not found for message id " + messageId); - } + PreparedStatement stmt = conn.prepareStatement(DELETE_FROM_META_DATA); + try + { + stmt.setLong(1,messageId); + int results = stmt.executeUpdate(); + stmt.close(); - if (_logger.isDebugEnabled()) - { - _logger.debug("Deleted metadata for message " + messageId); - } + if (results == 0) + { + throw new RuntimeException("Message metadata not found for message id " + messageId); + } - stmt = conn.prepareStatement(DELETE_FROM_MESSAGE_CONTENT); - stmt.setLong(1,messageId); - results = stmt.executeUpdate(); - stmt.close(); + if (_logger.isDebugEnabled()) + { + _logger.debug("Deleted metadata for message " + messageId); + } - conn.commit(); - conn.close(); - } - catch (SQLException e) - { - if ((conn != null)) + stmt = conn.prepareStatement(DELETE_FROM_MESSAGE_CONTENT); + stmt.setLong(1,messageId); + results = stmt.executeUpdate(); + } + finally + { + stmt.close(); + } + conn.commit(); + } + catch(SQLException e) { try { conn.rollback(); - conn.close(); } - catch (SQLException e1) + catch(SQLException t) { - + // ignore - we are re-throwing underlying exception } - } + throw e; + + } + finally + { + conn.close(); + } + } + catch (SQLException e) + { throw new RuntimeException("Error removing message with id " + messageId + " from database: " + e.getMessage(), e); } @@ -616,37 +725,52 @@ public class DerbyMessageStore implements MessageStore { try { - Connection conn = null; + Connection conn = newAutoCommitConnection(); try { - conn = newAutoCommitConnection(); - PreparedStatement stmt = conn.prepareStatement(FIND_EXCHANGE); - stmt.setString(1, exchange.getNameShortString().toString()); - ResultSet rs = stmt.executeQuery(); + PreparedStatement stmt = conn.prepareStatement(FIND_EXCHANGE); + try + { + stmt.setString(1, exchange.getNameShortString().toString()); + ResultSet rs = stmt.executeQuery(); + try + { - // If we don't have any data in the result set then we can add this exchange - if (!rs.next()) + // If we don't have any data in the result set then we can add this exchange + if (!rs.next()) + { + + PreparedStatement insertStmt = conn.prepareStatement(INSERT_INTO_EXCHANGE); + try + { + insertStmt.setString(1, exchange.getName().toString()); + insertStmt.setString(2, exchange.getTypeShortString().asString()); + insertStmt.setShort(3, exchange.isAutoDelete() ? (short) 1 : (short) 0); + insertStmt.execute(); + } + finally + { + insertStmt.close(); + } + } + } + finally + { + rs.close(); + } + } + finally { stmt.close(); - - stmt = conn.prepareStatement(INSERT_INTO_EXCHANGE); - stmt.setString(1, exchange.getName().toString()); - stmt.setString(2, exchange.getTypeShortString().asString()); - stmt.setShort(3, exchange.isAutoDelete() ? (short) 1 : (short) 0); - stmt.execute(); - stmt.close(); } } finally { - if(conn != null) - { - conn.close(); - } + conn.close(); } } catch (SQLException e) @@ -659,39 +783,37 @@ public class DerbyMessageStore implements MessageStore public void removeExchange(Exchange exchange) throws AMQStoreException { - Connection conn = null; try { - conn = newAutoCommitConnection(); - PreparedStatement stmt = conn.prepareStatement(DELETE_FROM_EXCHANGE); - stmt.setString(1, exchange.getNameShortString().toString()); - int results = stmt.executeUpdate(); - stmt.close(); - if(results == 0) + Connection conn = newAutoCommitConnection(); + try + { + PreparedStatement stmt = conn.prepareStatement(DELETE_FROM_EXCHANGE); + try + { + stmt.setString(1, exchange.getNameShortString().toString()); + int results = stmt.executeUpdate(); + stmt.close(); + if(results == 0) + { + throw new AMQStoreException("Exchange " + exchange.getNameShortString() + " not found"); + } + } + finally + { + stmt.close(); + } + } + finally { - throw new AMQStoreException("Exchange " + exchange.getNameShortString() + " not found"); + conn.close(); } } catch (SQLException e) { throw new AMQStoreException("Error deleting Exchange with name " + exchange.getNameShortString() + " from database: " + e.getMessage(), e); } - finally - { - if(conn != null) - { - try - { - conn.close(); - } - catch (SQLException e) - { - _logger.error(e); - } - } - - } } public void bindQueue(Exchange exchange, AMQShortString routingKey, AMQQueue queue, FieldTable args) @@ -699,44 +821,69 @@ public class DerbyMessageStore implements MessageStore { if (_state != State.RECOVERING) { - Connection conn = null; - try { - conn = newAutoCommitConnection(); - - PreparedStatement stmt = conn.prepareStatement(FIND_BINDING); - stmt.setString(1, exchange.getNameShortString().toString() ); - stmt.setString(2, queue.getNameShortString().toString()); - stmt.setString(3, routingKey == null ? null : routingKey.toString()); - - ResultSet rs = stmt.executeQuery(); + Connection conn = newAutoCommitConnection(); - // If this binding is not already in the store then create it. - if (!rs.next()) + try { - stmt = conn.prepareStatement(INSERT_INTO_BINDINGS); - stmt.setString(1, exchange.getNameShortString().toString() ); - stmt.setString(2, queue.getNameShortString().toString()); - stmt.setString(3, routingKey == null ? null : routingKey.toString()); - if(args != null) + + PreparedStatement stmt = conn.prepareStatement(FIND_BINDING); + try { - /* This would be the Java 6 way of setting a Blob - Blob blobArgs = conn.createBlob(); - blobArgs.setBytes(0, args.getDataAsBytes()); - stmt.setBlob(4, blobArgs); - */ - byte[] bytes = args.getDataAsBytes(); - ByteArrayInputStream bis = new ByteArrayInputStream(bytes); - stmt.setBinaryStream(4, bis, bytes.length); + stmt.setString(1, exchange.getNameShortString().toString() ); + stmt.setString(2, queue.getNameShortString().toString()); + stmt.setString(3, routingKey == null ? null : routingKey.toString()); + + ResultSet rs = stmt.executeQuery(); + try + { + // If this binding is not already in the store then create it. + if (!rs.next()) + { + PreparedStatement insertStmt = conn.prepareStatement(INSERT_INTO_BINDINGS); + try + { + insertStmt.setString(1, exchange.getNameShortString().toString() ); + insertStmt.setString(2, queue.getNameShortString().toString()); + insertStmt.setString(3, routingKey == null ? null : routingKey.toString()); + if(args != null) + { + /* This would be the Java 6 way of setting a Blob + Blob blobArgs = conn.createBlob(); + blobArgs.setBytes(0, args.getDataAsBytes()); + stmt.setBlob(4, blobArgs); + */ + byte[] bytes = args.getDataAsBytes(); + ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + insertStmt.setBinaryStream(4, bis, bytes.length); + } + else + { + insertStmt.setNull(4, Types.BLOB); + } + + insertStmt.executeUpdate(); + } + finally + { + insertStmt.close(); + } + } + } + finally + { + rs.close(); + } } - else + finally { - stmt.setNull(4, Types.BLOB); + stmt.close(); } - - stmt.executeUpdate(); - stmt.close(); + } + finally + { + conn.close(); } } catch (SQLException e) @@ -744,21 +891,6 @@ public class DerbyMessageStore implements MessageStore throw new AMQStoreException("Error writing binding for AMQQueue with name " + queue.getNameShortString() + " to exchange " + exchange.getNameShortString() + " to database: " + e.getMessage(), e); } - finally - { - if(conn != null) - { - try - { - conn.close(); - } - catch (SQLException e) - { - _logger.error(e); - } - } - - } } @@ -828,39 +960,58 @@ public class DerbyMessageStore implements MessageStore Connection conn = newAutoCommitConnection(); PreparedStatement stmt = conn.prepareStatement(FIND_QUEUE); - stmt.setString(1, queue.getNameShortString().toString()); - - ResultSet rs = stmt.executeQuery(); - - // If we don't have any data in the result set then we can add this queue - if (!rs.next()) + try { - stmt = conn.prepareStatement(INSERT_INTO_QUEUE); - - String owner = queue.getOwner() == null ? null : queue.getOwner().toString(); - stmt.setString(1, queue.getNameShortString().toString()); - stmt.setString(2, owner); - stmt.setBoolean(3,queue.isExclusive()); - - final byte[] underlying; - if(arguments != null) + ResultSet rs = stmt.executeQuery(); + try { - underlying = arguments.getDataAsBytes(); + + // If we don't have any data in the result set then we can add this queue + if (!rs.next()) + { + PreparedStatement insertStmt = conn.prepareStatement(INSERT_INTO_QUEUE); + + try + { + String owner = queue.getOwner() == null ? null : queue.getOwner().toString(); + + insertStmt.setString(1, queue.getNameShortString().toString()); + insertStmt.setString(2, owner); + insertStmt.setBoolean(3,queue.isExclusive()); + + final byte[] underlying; + if(arguments != null) + { + underlying = arguments.getDataAsBytes(); + } + else + { + underlying = new byte[0]; + } + + ByteArrayInputStream bis = new ByteArrayInputStream(underlying); + insertStmt.setBinaryStream(4,bis,underlying.length); + + insertStmt.execute(); + } + finally + { + insertStmt.close(); + } + } } - else + finally { - underlying = new byte[0]; + rs.close(); } - - ByteArrayInputStream bis = new ByteArrayInputStream(underlying); - stmt.setBinaryStream(4,bis,underlying.length); - - stmt.execute(); + } + finally + { stmt.close(); - - conn.close(); } + conn.close(); + } catch (SQLException e) { @@ -886,24 +1037,46 @@ public class DerbyMessageStore implements MessageStore { Connection conn = newAutoCommitConnection(); - PreparedStatement stmt = conn.prepareStatement(FIND_QUEUE); - stmt.setString(1, queue.getNameShortString().toString()); - - ResultSet rs = stmt.executeQuery(); - - if (rs.next()) + try { - PreparedStatement stmt2 = conn.prepareStatement(UPDATE_QUEUE_EXCLUSIVITY); - - stmt2.setBoolean(1,queue.isExclusive()); - stmt2.setString(2, queue.getNameShortString().toString()); + PreparedStatement stmt = conn.prepareStatement(FIND_QUEUE); + try + { + stmt.setString(1, queue.getNameShortString().toString()); - stmt2.execute(); - stmt2.close(); + ResultSet rs = stmt.executeQuery(); + try + { + if (rs.next()) + { + PreparedStatement stmt2 = conn.prepareStatement(UPDATE_QUEUE_EXCLUSIVITY); + try + { + stmt2.setBoolean(1,queue.isExclusive()); + stmt2.setString(2, queue.getNameShortString().toString()); + + stmt2.execute(); + } + finally + { + stmt2.close(); + } + } + } + finally + { + rs.close(); + } + } + finally + { + stmt.close(); + } + } + finally + { + conn.close(); } - - stmt.close(); - conn.close(); } catch (SQLException e) { @@ -920,7 +1093,22 @@ public class DerbyMessageStore implements MessageStore private Connection newAutoCommitConnection() throws SQLException { final Connection connection = newConnection(); - connection.setAutoCommit(true); + try + { + connection.setAutoCommit(true); + } + catch (SQLException sqlEx) + { + + try + { + connection.close(); + } + finally + { + throw sqlEx; + } + } return connection; } @@ -932,8 +1120,22 @@ public class DerbyMessageStore implements MessageStore private Connection newConnection() throws SQLException { final Connection connection = DriverManager.getConnection(_connectionURL); - connection.setAutoCommit(false); - connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); + try + { + connection.setAutoCommit(false); + connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); + } + catch (SQLException sqlEx) + { + try + { + connection.close(); + } + finally + { + throw sqlEx; + } + } return connection; } @@ -999,10 +1201,16 @@ public class DerbyMessageStore implements MessageStore } PreparedStatement stmt = conn.prepareStatement(INSERT_INTO_QUEUE_ENTRY); - stmt.setString(1,name); - stmt.setLong(2,messageId); - stmt.executeUpdate(); - stmt.close(); + try + { + stmt.setString(1,name); + stmt.setLong(2,messageId); + stmt.executeUpdate(); + } + finally + { + stmt.close(); + } } catch (SQLException e) { @@ -1024,19 +1232,27 @@ public class DerbyMessageStore implements MessageStore try { PreparedStatement stmt = conn.prepareStatement(DELETE_FROM_QUEUE_ENTRY); - stmt.setString(1,name); - stmt.setLong(2,messageId); - int results = stmt.executeUpdate(); - stmt.close(); - - if(results != 1) + try { - throw new AMQStoreException("Unable to find message with id " + messageId + " on queue " + name); - } + stmt.setString(1,name); + stmt.setLong(2,messageId); + int results = stmt.executeUpdate(); - if (_logger.isDebugEnabled()) + + + if(results != 1) + { + throw new AMQStoreException("Unable to find message with id " + messageId + " on queue " + name); + } + + if (_logger.isDebugEnabled()) + { + _logger.debug("Dequeuing message " + messageId + " on queue " + name );//+ "[Connection" + conn + "]"); + } + } + finally { - _logger.debug("Dequeuing message " + messageId + " on queue " + name );//+ "[Connection" + conn + "]"); + stmt.close(); } } catch (SQLException e) @@ -1147,25 +1363,48 @@ public class DerbyMessageStore implements MessageStore } PreparedStatement stmt = conn.prepareStatement(INSERT_INTO_META_DATA); - stmt.setLong(1,messageId); - - final int bodySize = 1 + metaData.getStorableSize(); - byte[] underlying = new byte[bodySize]; - underlying[0] = (byte) metaData.getType().ordinal(); - java.nio.ByteBuffer buf = java.nio.ByteBuffer.wrap(underlying); - buf.position(1); - buf = buf.slice(); - - metaData.writeToBuffer(0, buf); - ByteArrayInputStream bis = new ByteArrayInputStream(underlying); - stmt.setBinaryStream(2,bis,underlying.length); - int result = stmt.executeUpdate(); - stmt.close(); - - if(result == 0) + try { - throw new RuntimeException("Unable to add meta data for message " +messageId); + stmt.setLong(1,messageId); + + final int bodySize = 1 + metaData.getStorableSize(); + byte[] underlying = new byte[bodySize]; + underlying[0] = (byte) metaData.getType().ordinal(); + java.nio.ByteBuffer buf = java.nio.ByteBuffer.wrap(underlying); + buf.position(1); + buf = buf.slice(); + + metaData.writeToBuffer(0, buf); + ByteArrayInputStream bis = new ByteArrayInputStream(underlying); + try + { + stmt.setBinaryStream(2,bis,underlying.length); + int result = stmt.executeUpdate(); + + if(result == 0) + { + throw new RuntimeException("Unable to add meta data for message " +messageId); + } + } + finally + { + try + { + bis.close(); + } + catch (IOException e) + { + + throw new SQLException(e); + } + } + } + finally + { + stmt.close(); + } + } @@ -1174,38 +1413,58 @@ public class DerbyMessageStore implements MessageStore private void recoverMessages(MessageStoreRecoveryHandler recoveryHandler) throws SQLException { Connection conn = newAutoCommitConnection(); + try + { + MessageStoreRecoveryHandler.StoredMessageRecoveryHandler messageHandler = recoveryHandler.begin(); - MessageStoreRecoveryHandler.StoredMessageRecoveryHandler messageHandler = recoveryHandler.begin(); + Statement stmt = conn.createStatement(); + try + { + ResultSet rs = stmt.executeQuery(SELECT_ALL_FROM_META_DATA); + try + { - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery(SELECT_ALL_FROM_META_DATA); + long maxId = 0; - long maxId = 0; + while(rs.next()) + { - while(rs.next()) - { + long messageId = rs.getLong(1); + Blob dataAsBlob = rs.getBlob(2); + + if(messageId > maxId) + { + maxId = messageId; + } + + byte[] dataAsBytes = dataAsBlob.getBytes(1,(int) dataAsBlob.length()); + java.nio.ByteBuffer buf = java.nio.ByteBuffer.wrap(dataAsBytes); + buf.position(1); + buf = buf.slice(); + MessageMetaDataType type = MessageMetaDataType.values()[dataAsBytes[0]]; + StorableMessageMetaData metaData = type.getFactory().createMetaData(buf); + StoredDerbyMessage message = new StoredDerbyMessage(messageId, metaData, false); + messageHandler.message(message); + } - long messageId = rs.getLong(1); - Blob dataAsBlob = rs.getBlob(2); + _messageId.set(maxId); - if(messageId > maxId) + messageHandler.completeMessageRecovery(); + } + finally + { + rs.close(); + } + } + finally { - maxId = messageId; + stmt.close(); } - - byte[] dataAsBytes = dataAsBlob.getBytes(1,(int) dataAsBlob.length()); - java.nio.ByteBuffer buf = java.nio.ByteBuffer.wrap(dataAsBytes); - buf.position(1); - buf = buf.slice(); - MessageMetaDataType type = MessageMetaDataType.values()[dataAsBytes[0]]; - StorableMessageMetaData metaData = type.getFactory().createMetaData(buf); - StoredDerbyMessage message = new StoredDerbyMessage(messageId, metaData, false); - messageHandler.message(message); } - - _messageId.set(maxId); - - messageHandler.completeMessageRecovery(); + finally + { + conn.close(); + } } @@ -1213,23 +1472,40 @@ public class DerbyMessageStore implements MessageStore private void recoverQueueEntries(TransactionLogRecoveryHandler recoveryHandler) throws SQLException { Connection conn = newAutoCommitConnection(); + try + { + TransactionLogRecoveryHandler.QueueEntryRecoveryHandler queueEntryHandler = recoveryHandler.begin(this); - TransactionLogRecoveryHandler.QueueEntryRecoveryHandler queueEntryHandler = recoveryHandler.begin(this); + Statement stmt = conn.createStatement(); + try + { + ResultSet rs = stmt.executeQuery(SELECT_FROM_QUEUE_ENTRY); + try + { + while(rs.next()) + { - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery(SELECT_FROM_QUEUE_ENTRY); + String queueName = rs.getString(1); + long messageId = rs.getLong(2); + queueEntryHandler.queueEntry(queueName,messageId); + } + } + finally + { + rs.close(); + } + } + finally + { + stmt.close(); + } - while(rs.next()) + queueEntryHandler.completeQueueEntryRecovery(); + } + finally { - - String queueName = rs.getString(1); - long messageId = rs.getLong(2); - queueEntryHandler.queueEntry(queueName,messageId); + conn.close(); } - - stmt.close(); - - queueEntryHandler.completeQueueEntryRecovery(); } StorableMessageMetaData getMetaData(long messageId) throws SQLException @@ -1239,31 +1515,40 @@ public class DerbyMessageStore implements MessageStore try { PreparedStatement stmt = conn.prepareStatement(SELECT_FROM_META_DATA); - stmt.setLong(1,messageId); - ResultSet rs = stmt.executeQuery(); - - if(rs.next()) + try { - stmt.close(); - - Blob dataAsBlob = rs.getBlob(1); + stmt.setLong(1,messageId); + ResultSet rs = stmt.executeQuery(); + try + { + + if(rs.next()) + { + Blob dataAsBlob = rs.getBlob(1); - byte[] dataAsBytes = dataAsBlob.getBytes(1,(int) dataAsBlob.length()); - java.nio.ByteBuffer buf = java.nio.ByteBuffer.wrap(dataAsBytes); - buf.position(1); - buf = buf.slice(); - MessageMetaDataType type = MessageMetaDataType.values()[dataAsBytes[0]]; - StorableMessageMetaData metaData = type.getFactory().createMetaData(buf); + byte[] dataAsBytes = dataAsBlob.getBytes(1,(int) dataAsBlob.length()); + java.nio.ByteBuffer buf = java.nio.ByteBuffer.wrap(dataAsBytes); + buf.position(1); + buf = buf.slice(); + MessageMetaDataType type = MessageMetaDataType.values()[dataAsBytes[0]]; + StorableMessageMetaData metaData = type.getFactory().createMetaData(buf); - return metaData; + return metaData; + } + else + { + throw new RuntimeException("Meta data not found for message with id " + messageId); + } + } + finally + { + rs.close(); + } } - else + finally { stmt.close(); - - throw new RuntimeException("Meta data not found for message with id " + messageId); } - } finally { diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionList.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionList.java index 3fbb6bfa4a..9ea81660c6 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionList.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/SubscriptionList.java @@ -34,7 +34,6 @@ public class SubscriptionList private final SubscriptionNode _head = new SubscriptionNode(); private AtomicReference<SubscriptionNode> _tail = new AtomicReference<SubscriptionNode>(_head); - private final AMQQueue _queue; private AtomicInteger _size = new AtomicInteger(); @@ -115,7 +114,6 @@ public class SubscriptionList public SubscriptionList(AMQQueue queue) { - _queue = queue; } private void advanceHead() @@ -176,7 +174,7 @@ public class SubscriptionList } - public class SubscriptionNodeIterator + public static class SubscriptionNodeIterator { private SubscriptionNode _lastNode; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java index 117be3e3b7..84601b1b7a 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSessionDelegate.java @@ -198,7 +198,7 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session,method,ExecutionErrorCode.NOT_FOUND, "Queue: " + queueName + " not found"); } - if(queue.getPrincipalHolder() != null && queue.getPrincipalHolder() != session) + else if(queue.getPrincipalHolder() != null && queue.getPrincipalHolder() != session) { exception(session,method,ExecutionErrorCode.RESOURCE_LOCKED, "Exclusive Queue: " + queueName + " owned exclusively by another session"); } @@ -1162,8 +1162,7 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session, sfm, ExecutionErrorCode.NOT_FOUND, "not-found: destination '"+destination+"'"); } - - if(sub.isStopped()) + else if(sub.isStopped()) { sub.setFlowMode(sfm.getFlowMode()); } @@ -1180,8 +1179,10 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session, stop, ExecutionErrorCode.NOT_FOUND, "not-found: destination '"+destination+"'"); } - - sub.stop(); + else + { + sub.stop(); + } } @@ -1196,8 +1197,10 @@ public class ServerSessionDelegate extends SessionDelegate { exception(session, flow, ExecutionErrorCode.NOT_FOUND, "not-found: destination '"+destination+"'"); } - - sub.addCredit(flow.getUnit(), flow.getValue()); + else + { + sub.addCredit(flow.getUnit(), flow.getValue()); + } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/HouseKeepingTask.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/HouseKeepingTask.java index 45d4be9340..2db1944cd1 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/HouseKeepingTask.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/HouseKeepingTask.java @@ -29,15 +29,15 @@ public abstract class HouseKeepingTask implements Runnable { Logger _logger = Logger.getLogger(this.getClass()); - protected VirtualHost _virtualhost; + private VirtualHost _virtualHost; private String _name; private RootMessageLogger _rootLogger; public HouseKeepingTask(VirtualHost vhost) { - _virtualhost = vhost; - _name = _virtualhost.getName() + ":" + this.getClass().getSimpleName(); + _virtualHost = vhost; + _name = _virtualHost.getName() + ":" + this.getClass().getSimpleName(); _rootLogger = CurrentActor.get().getRootMessageLogger(); } @@ -65,6 +65,10 @@ public abstract class HouseKeepingTask implements Runnable } } + public VirtualHost getVirtualHost() + { + return _virtualHost; + } /** Execute the plugin. */ public abstract void execute(); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java index f2444718af..6ec1c512e5 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java @@ -299,11 +299,13 @@ public class VirtualHostImpl implements VirtualHost if (plugins != null) { - for (String pluginName : plugins.keySet()) + for (Map.Entry<String, VirtualHostPluginFactory> entry : plugins.entrySet()) { + String pluginName = entry.getKey(); + VirtualHostPluginFactory factory = entry.getValue(); try { - VirtualHostPlugin plugin = plugins.get(pluginName).newInstance(this); + VirtualHostPlugin plugin = factory.newInstance(this); // If we had configuration for the plugin the schedule it. if (plugin != null) @@ -636,8 +638,10 @@ public class VirtualHostImpl implements VirtualHost final String password) { BrokerLink blink = new BrokerLink(this, transport, host, port, vhost, durable, authMechanism, username, password); - _links.putIfAbsent(blink,blink); - getConfigStore().addConfiguredObject(blink); + if(_links.putIfAbsent(blink,blink) != null) + { + getConfigStore().addConfiguredObject(blink); + } } public void removeBrokerConnection(final String transport, @@ -671,7 +675,7 @@ public class VirtualHostImpl implements VirtualHost * This is so we can replay the creation of queues/exchanges in to the real _RT after it has been loaded. * This should be removed after the _RT has been fully split from the the TL */ - private class StartupRoutingTable implements DurableConfigurationStore + private static class StartupRoutingTable implements DurableConfigurationStore { public List<Exchange> exchange = new LinkedList<Exchange>(); public List<CreateQueueTuple> queue = new LinkedList<CreateQueueTuple>(); @@ -740,7 +744,7 @@ public class VirtualHostImpl implements VirtualHost } - private class CreateQueueTuple + private static class CreateQueueTuple { public AMQQueue queue; public FieldTable arguments; @@ -752,7 +756,7 @@ public class VirtualHostImpl implements VirtualHost } } - private class CreateBindingTuple + private static class CreateBindingTuple { public AMQQueue queue; public FieldTable arguments; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetection.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetection.java index ddc55652a8..5c4fe0aab8 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetection.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/SlowConsumerDetection.java @@ -19,7 +19,6 @@ */ package org.apache.qpid.server.virtualhost.plugins; -import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -32,8 +31,6 @@ import org.apache.qpid.server.plugins.Plugin; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.server.virtualhost.plugins.logging.SlowConsumerDetectionMessages; -import org.apache.qpid.server.virtualhost.plugins.VirtualHostHouseKeepingPlugin; -import org.apache.qpid.server.virtualhost.plugins.VirtualHostPluginFactory; public class SlowConsumerDetection extends VirtualHostHouseKeepingPlugin { @@ -67,10 +64,10 @@ public class SlowConsumerDetection extends VirtualHostHouseKeepingPlugin public void configure(ConfigurationPlugin config) { _config = (SlowConsumerDetectionConfiguration) config; - _listener = new ConfiguredQueueBindingListener(_virtualhost.getName()); - for (AMQShortString exchangeName : _virtualhost.getExchangeRegistry().getExchangeNames()) + _listener = new ConfiguredQueueBindingListener(getVirtualHost().getName()); + for (AMQShortString exchangeName : getVirtualHost().getExchangeRegistry().getExchangeNames()) { - _virtualhost.getExchangeRegistry().getExchange(exchangeName).addBindingListener(_listener); + getVirtualHost().getExchangeRegistry().getExchange(exchangeName).addBindingListener(_listener); } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java index d119190842..3798f47f0b 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostHouseKeepingPlugin.java @@ -30,18 +30,11 @@ public abstract class VirtualHostHouseKeepingPlugin extends HouseKeepingTask imp { protected final Logger _logger = Logger.getLogger(getClass()); - protected VirtualHost _virtualhost; - public VirtualHostHouseKeepingPlugin(VirtualHost vhost) { super(vhost); - setVirtualHost(vhost); } - public void setVirtualHost(VirtualHost vhost) - { - _virtualhost = vhost; - } /** * Long value representing the delay between repeats diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java index 26eb5bbd7f..1886c2d01d 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/virtualhost/plugins/VirtualHostPlugin.java @@ -27,8 +27,6 @@ import org.apache.qpid.server.virtualhost.VirtualHost; public interface VirtualHostPlugin extends Runnable, Plugin { - public void setVirtualHost(VirtualHost vhost); - /** * Long value representing the delay between repeats * diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java b/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java index f26611f0bc..dca165fa7e 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java @@ -171,7 +171,7 @@ public class MessageStoreTool /** * Simple ShutdownHook to cleanly shutdown the databases */ - class ShutdownHook implements Runnable + static class ShutdownHook implements Runnable { MessageStoreTool _tool; @@ -443,7 +443,7 @@ public class MessageStoreTool * * */ - public class State + public static class State { private VirtualHost _vhost = null; private AMQQueue _queue = null; diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Dump.java b/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Dump.java index a7d58dc6dd..8bb5d02b01 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Dump.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Dump.java @@ -127,7 +127,7 @@ public class Dump extends Show addShowInformation(hex, ascii, msg, null, false, false, true); } - // Add Content Body seciont + // Add Content Body section hex.add("Content Body"); ascii.add(""); hex.add(Console.ROW_DIVIDER); @@ -182,12 +182,12 @@ public class Dump extends Show String encStr = new String(encoded, 0, bufsize * 2, DEFAULT_ENCODING); String hexLine = ""; - int strKength = encStr.length(); - for (int c = 0; c < strKength; c++) + int strLength = encStr.length(); + for (int c = 0; c < strLength; c++) { hexLine += encStr.charAt(c); - if (c % 2 == 1 && SPACE_BYTES) + if ((c & 1) == 1 && SPACE_BYTES) { hexLine += BYTE_SPACER; } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/tools/utils/SimpleConsole.java b/qpid/java/broker/src/main/java/org/apache/qpid/tools/utils/SimpleConsole.java index ec080a4611..2791a39f92 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/tools/utils/SimpleConsole.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/tools/utils/SimpleConsole.java @@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -35,10 +36,10 @@ public class SimpleConsole implements Console private static Logger _devlog = LoggerFactory.getLogger(SimpleConsole.class); /** Console Writer. */ - protected static BufferedWriter _consoleWriter; + protected BufferedWriter _consoleWriter; /** Console Reader. */ - protected static BufferedReader _consoleReader; + protected BufferedReader _consoleReader; /** Parser for command-line input. */ protected CommandParser _parser; @@ -62,7 +63,7 @@ public class SimpleConsole implements Console } catch (IOException e) { - _devlog.error(e.getMessage() + ": Occured whilst trying to write:" + message); + _devlog.error(e.getMessage() + ": Occurred whilst trying to write:" + Arrays.asList(message)); } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java index 9ef4af2932..b3223f16c4 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/ack/AcknowledgeTest.java @@ -33,19 +33,19 @@ public class AcknowledgeTest extends InternalBrokerBaseCase public void testTransactionalSingleAck() throws AMQException { - _channel.setLocalTransactional(); + getChannel().setLocalTransactional(); runMessageAck(1, 1, 1, false, 0); } public void testTransactionalMultiAck() throws AMQException { - _channel.setLocalTransactional(); + getChannel().setLocalTransactional(); runMessageAck(10, 1, 5, true, 5); } public void testTransactionalAckAll() throws AMQException { - _channel.setLocalTransactional(); + getChannel().setLocalTransactional(); runMessageAck(10, 1, 0, true, 0); } @@ -70,31 +70,31 @@ public class AcknowledgeTest extends InternalBrokerBaseCase checkStoreContents(0); //Send required messsages to the queue - publishMessages(_session, _channel, sendMessageCount); + publishMessages(getSession(), getChannel(), sendMessageCount); - if (_channel.isTransactional()) + if (getChannel().isTransactional()) { - _channel.commit(); + getChannel().commit(); } //Ensure they are stored checkStoreContents(sendMessageCount); //Check that there are no unacked messages - assertEquals("Channel should have no unacked msgs ", 0, _channel.getUnacknowledgedMessageMap().size()); + assertEquals("Channel should have no unacked msgs ", 0, getChannel().getUnacknowledgedMessageMap().size()); //Subscribe to the queue - AMQShortString subscriber = subscribe(_session, _channel, _queue); + AMQShortString subscriber = subscribe(getSession(), getChannel(), getQueue()); - _queue.deliverAsync(); + getQueue().deliverAsync(); //Wait for the messages to be delivered - _session.awaitDelivery(sendMessageCount); + getSession().awaitDelivery(sendMessageCount); //Check that they are all waiting to be acknoledged - assertEquals("Channel should have unacked msgs", sendMessageCount, _channel.getUnacknowledgedMessageMap().size()); + assertEquals("Channel should have unacked msgs", sendMessageCount, getChannel().getUnacknowledgedMessageMap().size()); - List<InternalTestProtocolSession.DeliveryPair> messages = _session.getDelivers(_channel.getChannelId(), subscriber, sendMessageCount); + List<InternalTestProtocolSession.DeliveryPair> messages = getSession().getDelivers(getChannel().getChannelId(), subscriber, sendMessageCount); //Double check we received the right number of messages assertEquals(sendMessageCount, messages.size()); @@ -103,15 +103,15 @@ public class AcknowledgeTest extends InternalBrokerBaseCase assertEquals("First message does not have expected deliveryTag", firstDeliveryTag, messages.get(0).getDeliveryTag()); //Send required Acknowledgement - _channel.acknowledgeMessage(acknowledgeDeliveryTag, acknowldegeMultiple); + getChannel().acknowledgeMessage(acknowledgeDeliveryTag, acknowldegeMultiple); - if (_channel.isTransactional()) + if (getChannel().isTransactional()) { - _channel.commit(); + getChannel().commit(); } // Check Remaining Acknowledgements - assertEquals("Channel unacked msgs count incorrect", remainingUnackedMessages, _channel.getUnacknowledgedMessageMap().size()); + assertEquals("Channel unacked msgs count incorrect", remainingUnackedMessages, getChannel().getUnacknowledgedMessageMap().size()); //Check store contents are also correct. checkStoreContents(remainingUnackedMessages); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/TopicConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/TopicConfigurationTest.java index e3b07b072b..7fc3b2d06a 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/TopicConfigurationTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/TopicConfigurationTest.java @@ -40,12 +40,12 @@ public class TopicConfigurationTest extends InternalBrokerBaseCase @Override public void configure() { - _configXml.addProperty("virtualhosts.virtualhost.test.topics.topic.name", "stocks.nyse.appl"); + getConfigXml().addProperty("virtualhosts.virtualhost.test.topics.topic.name", "stocks.nyse.appl"); - _configXml.addProperty("virtualhosts.virtualhost.test.topics.topic(1).subscriptionName", getName()+":stockSubscription"); + getConfigXml().addProperty("virtualhosts.virtualhost.test.topics.topic(1).subscriptionName", getName()+":stockSubscription"); - _configXml.addProperty("virtualhosts.virtualhost.test.topics.topic(2).name", "stocks.nyse.orcl"); - _configXml.addProperty("virtualhosts.virtualhost.test.topics.topic(2).subscriptionName", getName()+":stockSubscription"); + getConfigXml().addProperty("virtualhosts.virtualhost.test.topics.topic(2).name", "stocks.nyse.orcl"); + getConfigXml().addProperty("virtualhosts.virtualhost.test.topics.topic(2).subscriptionName", getName()+":stockSubscription"); } /** @@ -57,10 +57,10 @@ public class TopicConfigurationTest extends InternalBrokerBaseCase */ public void testTopicCreation() throws ConfigurationException, AMQSecurityException, AMQInternalException { - Exchange topicExchange = _virtualHost.getExchangeRegistry().getExchange(ExchangeDefaults.TOPIC_EXCHANGE_NAME); - _virtualHost.getBindingFactory().addBinding("stocks.nyse.appl", _queue, topicExchange, null); + Exchange topicExchange = getVirtualHost().getExchangeRegistry().getExchange(ExchangeDefaults.TOPIC_EXCHANGE_NAME); + getVirtualHost().getBindingFactory().addBinding("stocks.nyse.appl", getQueue(), topicExchange, null); - TopicConfig config = _queue.getConfiguration().getConfiguration(TopicConfig.class.getName()); + TopicConfig config = getQueue().getConfiguration().getConfiguration(TopicConfig.class.getName()); assertNotNull("Queue should have topic configuration bound to it.", config); assertEquals("Configuration name not correct", "stocks.nyse.appl", config.getName()); @@ -77,15 +77,15 @@ public class TopicConfigurationTest extends InternalBrokerBaseCase { AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(new AMQShortString(getName()+":stockSubscription"), false, new AMQShortString("testowner"), - false, false, _virtualHost, null); + false, false, getVirtualHost(), null); - _virtualHost.getQueueRegistry().registerQueue(queue); - Exchange defaultExchange = _virtualHost.getExchangeRegistry().getDefaultExchange(); - _virtualHost.getBindingFactory().addBinding(getName(), queue, defaultExchange, null); + getVirtualHost().getQueueRegistry().registerQueue(queue); + Exchange defaultExchange = getVirtualHost().getExchangeRegistry().getDefaultExchange(); + getVirtualHost().getBindingFactory().addBinding(getName(), queue, defaultExchange, null); - Exchange topicExchange = _virtualHost.getExchangeRegistry().getExchange(ExchangeDefaults.TOPIC_EXCHANGE_NAME); - _virtualHost.getBindingFactory().addBinding("stocks.nyse.orcl", queue, topicExchange, null); + Exchange topicExchange = getVirtualHost().getExchangeRegistry().getExchange(ExchangeDefaults.TOPIC_EXCHANGE_NAME); + getVirtualHost().getBindingFactory().addBinding("stocks.nyse.orcl", queue, topicExchange, null); TopicConfig config = queue.getConfiguration().getConfiguration(TopicConfig.class.getName()); @@ -107,15 +107,15 @@ public class TopicConfigurationTest extends InternalBrokerBaseCase { AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(new AMQShortString(getName()+":stockSubscription"), false, new AMQShortString("testowner"), - false, false, _virtualHost, null); + false, false, getVirtualHost(), null); - _virtualHost.getQueueRegistry().registerQueue(queue); - Exchange defaultExchange = _virtualHost.getExchangeRegistry().getDefaultExchange(); - _virtualHost.getBindingFactory().addBinding(getName(), queue, defaultExchange, null); + getVirtualHost().getQueueRegistry().registerQueue(queue); + Exchange defaultExchange = getVirtualHost().getExchangeRegistry().getDefaultExchange(); + getVirtualHost().getBindingFactory().addBinding(getName(), queue, defaultExchange, null); - Exchange topicExchange = _virtualHost.getExchangeRegistry().getExchange(ExchangeDefaults.TOPIC_EXCHANGE_NAME); - _virtualHost.getBindingFactory().addBinding("stocks.nyse.ibm", queue, topicExchange, null); + Exchange topicExchange = getVirtualHost().getExchangeRegistry().getExchange(ExchangeDefaults.TOPIC_EXCHANGE_NAME); + getVirtualHost().getBindingFactory().addBinding("stocks.nyse.ibm", queue, topicExchange, null); TopicConfig config = queue.getConfiguration().getConfiguration(TopicConfig.class.getName()); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java index 2a542f2a0d..917755e8a5 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/VirtualHostConfigurationTest.java @@ -20,8 +20,6 @@ package org.apache.qpid.server.configuration; -import org.apache.commons.configuration.XMLConfiguration; - import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.server.queue.AMQPriorityQueue; import org.apache.qpid.server.queue.AMQQueue; @@ -38,12 +36,12 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase { super.setUp(); // Set the default configuration items - _configXml.clear(); - _configXml.addProperty("virtualhosts.virtualhost(-1).name", "test"); - _configXml.addProperty("virtualhosts.virtualhost(-1).test.store.class", TestableMemoryMessageStore.class.getName()); + getConfigXml().clear(); + getConfigXml().addProperty("virtualhosts.virtualhost(-1).name", "test"); + getConfigXml().addProperty("virtualhosts.virtualhost(-1).test.store.class", TestableMemoryMessageStore.class.getName()); - _configXml.addProperty("virtualhosts.virtualhost.name", getName()); - _configXml.addProperty("virtualhosts.virtualhost."+getName()+".store.class", TestableMemoryMessageStore.class.getName()); + getConfigXml().addProperty("virtualhosts.virtualhost.name", getName()); + getConfigXml().addProperty("virtualhosts.virtualhost."+getName()+".store.class", TestableMemoryMessageStore.class.getName()); } @Override @@ -55,27 +53,27 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase public void testQueuePriority() throws Exception { // Set up queue with 5 priorities - _configXml.addProperty("virtualhosts.virtualhost.testQueuePriority.queues(-1).queue(-1).name(-1)", + getConfigXml().addProperty("virtualhosts.virtualhost.testQueuePriority.queues(-1).queue(-1).name(-1)", "atest"); - _configXml.addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.atest(-1).exchange", + getConfigXml().addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.atest(-1).exchange", "amq.direct"); - _configXml.addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.atest.priorities", + getConfigXml().addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.atest.priorities", "5"); // Set up queue with JMS style priorities - _configXml.addProperty("virtualhosts.virtualhost.testQueuePriority.queues(-1).queue(-1).name(-1)", + getConfigXml().addProperty("virtualhosts.virtualhost.testQueuePriority.queues(-1).queue(-1).name(-1)", "ptest"); - _configXml.addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.ptest(-1).exchange", + getConfigXml().addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.ptest(-1).exchange", "amq.direct"); - _configXml.addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.ptest.priority", + getConfigXml().addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.ptest.priority", "true"); // Set up queue with no priorities - _configXml.addProperty("virtualhosts.virtualhost.testQueuePriority.queues(-1).queue(-1).name(-1)", + getConfigXml().addProperty("virtualhosts.virtualhost.testQueuePriority.queues(-1).queue(-1).name(-1)", "ntest"); - _configXml.addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.ntest(-1).exchange", + getConfigXml().addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.ntest(-1).exchange", "amq.direct"); - _configXml.addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.ntest.priority", + getConfigXml().addProperty("virtualhosts.virtualhost.testQueuePriority.queues.queue.ntest.priority", "false"); // Start the broker now. @@ -102,18 +100,18 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase public void testQueueAlerts() throws Exception { // Set up queue with 5 priorities - _configXml.addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.exchange", "amq.topic"); - _configXml.addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.maximumQueueDepth", "1"); - _configXml.addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.maximumMessageSize", "2"); - _configXml.addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.maximumMessageAge", "3"); + getConfigXml().addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.exchange", "amq.topic"); + getConfigXml().addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.maximumQueueDepth", "1"); + getConfigXml().addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.maximumMessageSize", "2"); + getConfigXml().addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.maximumMessageAge", "3"); - _configXml.addProperty("virtualhosts.virtualhost.testQueueAlerts.queues(-1).queue(1).name(1)", "atest"); - _configXml.addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.queue.atest(-1).exchange", "amq.direct"); - _configXml.addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.queue.atest(-1).maximumQueueDepth", "4"); - _configXml.addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.queue.atest(-1).maximumMessageSize", "5"); - _configXml.addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.queue.atest(-1).maximumMessageAge", "6"); + getConfigXml().addProperty("virtualhosts.virtualhost.testQueueAlerts.queues(-1).queue(1).name(1)", "atest"); + getConfigXml().addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.queue.atest(-1).exchange", "amq.direct"); + getConfigXml().addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.queue.atest(-1).maximumQueueDepth", "4"); + getConfigXml().addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.queue.atest(-1).maximumMessageSize", "5"); + getConfigXml().addProperty("virtualhosts.virtualhost.testQueueAlerts.queues.queue.atest(-1).maximumMessageAge", "6"); - _configXml.addProperty("virtualhosts.virtualhost.testQueueAlerts.queues(-1).queue(-1).name(-1)", "btest"); + getConfigXml().addProperty("virtualhosts.virtualhost.testQueueAlerts.queues(-1).queue(-1).name(-1)", "btest"); // Start the broker now. super.createBroker(); @@ -143,7 +141,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase { int initialPoolSize = 10; - _configXml.addProperty("virtualhosts.virtualhost.testHouseKeepingThreadCount.housekeeping.poolSize", + getConfigXml().addProperty("virtualhosts.virtualhost.testHouseKeepingThreadCount.housekeeping.poolSize", initialPoolSize); // Start the broker now. @@ -186,7 +184,7 @@ public class VirtualHostConfigurationTest extends InternalBrokerBaseCase { int initialPoolSize = 10; - _configXml.addProperty("virtualhosts.virtualhost.testDynamicHouseKeepingPoolSizeChange.housekeeping.poolSize", + getConfigXml().addProperty("virtualhosts.virtualhost.testDynamicHouseKeepingPoolSizeChange.housekeeping.poolSize", initialPoolSize); // Start the broker now. diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java index 696e57e83f..7b58966a4c 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/exchange/AbstractHeadersExchangeTestBase.java @@ -383,11 +383,6 @@ public class AbstractHeadersExchangeTestBase extends InternalBrokerBaseCase return false; //To change body of implemented methods use File | Settings | File Templates. } - public void setDeliveredToSubscription() - { - //To change body of implemented methods use File | Settings | File Templates. - } - public void release() { //To change body of implemented methods use File | Settings | File Templates. @@ -443,12 +438,7 @@ public class AbstractHeadersExchangeTestBase extends InternalBrokerBaseCase return false; //To change body of implemented methods use File | Settings | File Templates. } - public void requeue() - { - //To change body of implemented methods use File | Settings | File Templates. - } - - public void requeue(Subscription subscription) + public void requeue(Subscription subscription) { //To change body of implemented methods use File | Settings | File Templates. } @@ -463,11 +453,6 @@ public class AbstractHeadersExchangeTestBase extends InternalBrokerBaseCase //To change body of implemented methods use File | Settings | File Templates. } - public void restoreCredit() - { - //To change body of implemented methods use File | Settings | File Templates. - } - public void discard() { //To change body of implemented methods use File | Settings | File Templates. diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java index c7727bfa1a..6346fff85f 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPChannelActorTest.java @@ -24,8 +24,6 @@ import java.util.List; import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.AMQException; -import org.apache.qpid.server.logging.LogMessage; -import org.apache.qpid.server.logging.LogSubject; /** * Test : AMQPChannelActorTest @@ -56,7 +54,7 @@ public class AMQPChannelActorTest extends BaseConnectionActorTestCase { super.createBroker(); - _amqpActor = new AMQPChannelActor(_channel, _rootLogger); + _amqpActor = new AMQPChannelActor(getChannel(), _rootLogger); } @@ -69,7 +67,7 @@ public class AMQPChannelActorTest extends BaseConnectionActorTestCase */ public void testChannel() throws Exception { - _configXml.setProperty("status-updates", "ON"); + getConfigXml().setProperty("status-updates", "ON"); startBrokerNow(); @@ -107,7 +105,7 @@ public class AMQPChannelActorTest extends BaseConnectionActorTestCase */ public void testChannelLoggingOFF() throws Exception, AMQException { - _configXml.setProperty("status-updates", "OFF"); + getConfigXml().setProperty("status-updates", "OFF"); // Start the broker now. startBrokerNow(); @@ -128,7 +126,7 @@ public class AMQPChannelActorTest extends BaseConnectionActorTestCase */ public void testChannelLoggingOfF() throws Exception, AMQException { - _configXml.setProperty("status-updates", "OfF"); + getConfigXml().setProperty("status-updates", "OfF"); startBrokerNow(); @@ -148,7 +146,7 @@ public class AMQPChannelActorTest extends BaseConnectionActorTestCase */ public void testChannelLoggingOff() throws Exception, AMQException { - _configXml.setProperty("status-updates", "Off"); + getConfigXml().setProperty("status-updates", "Off"); startBrokerNow(); @@ -168,7 +166,7 @@ public class AMQPChannelActorTest extends BaseConnectionActorTestCase */ public void testChannelLoggingofF() throws Exception, AMQException { - _configXml.setProperty("status-updates", "ofF"); + getConfigXml().setProperty("status-updates", "ofF"); startBrokerNow(); @@ -188,7 +186,7 @@ public class AMQPChannelActorTest extends BaseConnectionActorTestCase */ public void testChannelLoggingoff() throws Exception, AMQException { - _configXml.setProperty("status-updates", "off"); + getConfigXml().setProperty("status-updates", "off"); startBrokerNow(); @@ -208,7 +206,7 @@ public class AMQPChannelActorTest extends BaseConnectionActorTestCase */ public void testChannelLoggingoFf() throws Exception, AMQException { - _configXml.setProperty("status-updates", "oFf"); + getConfigXml().setProperty("status-updates", "oFf"); startBrokerNow(); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java index 71d06f81ae..4eda9e9da1 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/AMQPConnectionActorTest.java @@ -20,11 +20,7 @@ */ package org.apache.qpid.server.logging.actors; -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.qpid.AMQException; -import org.apache.qpid.server.configuration.ServerConfiguration; import org.apache.qpid.server.logging.LogMessage; import org.apache.qpid.server.logging.LogSubject; @@ -64,7 +60,7 @@ public class AMQPConnectionActorTest extends BaseConnectionActorTestCase */ public void testConnection() throws Exception { - _configXml.setProperty("status-updates", "ON"); + getConfigXml().setProperty("status-updates", "ON"); super.createBroker(); @@ -94,7 +90,7 @@ public class AMQPConnectionActorTest extends BaseConnectionActorTestCase public void testConnectionLoggingOff() throws Exception, AMQException { - _configXml.setProperty("status-updates", "OFF"); + getConfigXml().setProperty("status-updates", "OFF"); // Start the broker now. super.createBroker(); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java index 3d4ded5898..60ecbef438 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseActorTestCase.java @@ -38,7 +38,7 @@ public class BaseActorTestCase extends InternalBrokerBaseCase @Override public void configure() { - _configuration.getConfig().setProperty(ServerConfiguration.STATUS_UPDATES, "on"); + getConfiguration().getConfig().setProperty(ServerConfiguration.STATUS_UPDATES, "on"); } @Override @@ -46,7 +46,7 @@ public class BaseActorTestCase extends InternalBrokerBaseCase { super.createBroker(); - _rawLogger = new UnitTestMessageLogger(_configuration); + _rawLogger = new UnitTestMessageLogger(getConfiguration()); _rootLogger = _rawLogger; } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java index 1b95d53702..956d296dce 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/BaseConnectionActorTestCase.java @@ -28,6 +28,6 @@ public class BaseConnectionActorTestCase extends BaseActorTestCase { super.createBroker(); - _amqpActor = new AMQPConnectionActor(_session, _rootLogger); + _amqpActor = new AMQPConnectionActor(getSession(), _rootLogger); } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java index 95a5610917..32ad1d110d 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/CurrentActorTest.java @@ -77,7 +77,7 @@ public class CurrentActorTest extends BaseConnectionActorTestCase // we remove the session actor and so all is good. stopBroker(); - AMQPConnectionActor connectionActor = new AMQPConnectionActor(_session, + AMQPConnectionActor connectionActor = new AMQPConnectionActor(getSession(), new NullRootMessageLogger()); /* @@ -104,7 +104,7 @@ public class CurrentActorTest extends BaseConnectionActorTestCase * */ - AMQChannel channel = new AMQChannel(_session, 1, _session.getVirtualHost().getMessageStore()); + AMQChannel channel = new AMQChannel(getSession(), 1, getSession().getVirtualHost().getMessageStore()); AMQPChannelActor channelActor = new AMQPChannelActor(channel, new NullRootMessageLogger()); @@ -228,7 +228,7 @@ public class CurrentActorTest extends BaseConnectionActorTestCase try { - AMQPConnectionActor actor = new AMQPConnectionActor(_session, + AMQPConnectionActor actor = new AMQPConnectionActor(getSession(), new NullRootMessageLogger()); CurrentActor.set(actor); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java index 8cb74ab29b..409f7c84b7 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/QueueActorTest.java @@ -20,12 +20,6 @@ */ package org.apache.qpid.server.logging.actors; -import org.apache.qpid.server.configuration.ServerConfiguration; -import org.apache.qpid.server.logging.LogMessage; -import org.apache.qpid.server.logging.LogSubject; -import org.apache.qpid.server.queue.MockAMQQueue; -import org.apache.qpid.AMQException; - import java.util.List; public class QueueActorTest extends BaseConnectionActorTestCase @@ -35,7 +29,7 @@ public class QueueActorTest extends BaseConnectionActorTestCase public void createBroker() throws Exception { super.createBroker(); - _amqpActor = new QueueActor(_queue, _rootLogger); + _amqpActor = new QueueActor(getQueue(), _rootLogger); } /** diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java index d9246b13ec..a2272cc395 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/actors/SubscriptionActorTest.java @@ -22,8 +22,6 @@ package org.apache.qpid.server.logging.actors; import java.util.List; -import org.apache.qpid.server.logging.LogMessage; -import org.apache.qpid.server.logging.LogSubject; import org.apache.qpid.server.subscription.MockSubscription; /** @@ -45,7 +43,7 @@ public class SubscriptionActorTest extends BaseConnectionActorTestCase MockSubscription mockSubscription = new MockSubscription(); - mockSubscription.setQueue(_queue, false); + mockSubscription.setQueue(getQueue(), false); _amqpActor = new SubscriptionActor(_rootLogger, mockSubscription); } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java index 025f899a6c..1cd8d55b0d 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/AbstractTestLogSubject.java @@ -59,20 +59,12 @@ public abstract class AbstractTestLogSubject extends InternalBrokerBaseCase protected Configuration _config = new PropertiesConfiguration(); protected LogSubject _subject = null; - AMQProtocolSession _session; - @Override public void setUp() throws Exception { super.setUp(); _config.setProperty(ServerConfiguration.STATUS_UPDATES, "ON"); - - VirtualHost virtualHost = ApplicationRegistry.getInstance(). - getVirtualHostRegistry().getVirtualHosts().iterator().next(); - - // Create a single session for this test. - _session = new InternalTestProtocolSession(virtualHost); } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java index 279628501c..e80c4c4679 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/BindingLogSubjectTest.java @@ -33,10 +33,10 @@ import org.apache.qpid.server.virtualhost.VirtualHost; public class BindingLogSubjectTest extends AbstractTestLogSubject { - AMQQueue _queue; - AMQShortString _routingKey; - Exchange _exchange; - VirtualHost _testVhost; + private AMQQueue _queue; + private AMQShortString _routingKey; + private Exchange _exchange; + private VirtualHost _testVhost; public void setUp() throws Exception { diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java index 41760e1b05..6bc5effa05 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ChannelLogSubjectTest.java @@ -34,7 +34,7 @@ public class ChannelLogSubjectTest extends ConnectionLogSubjectTest { super.setUp(); - AMQChannel channel = new AMQChannel(_session, _channelID, _session.getVirtualHost().getMessageStore()); + AMQChannel channel = new AMQChannel(getSession(), _channelID, getSession().getVirtualHost().getMessageStore()); _subject = new ChannelLogSubject(channel); } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java index 92234e9241..c246fff2a8 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/ConnectionLogSubjectTest.java @@ -30,7 +30,7 @@ public class ConnectionLogSubjectTest extends AbstractTestLogSubject { super.setUp(); - _subject = new ConnectionLogSubject(_session); + _subject = new ConnectionLogSubject(getSession()); } /** @@ -40,7 +40,7 @@ public class ConnectionLogSubjectTest extends AbstractTestLogSubject */ protected void validateLogStatement(String message) { - verifyConnection(_session.getSessionID(), "InternalTestProtocolSession", "127.0.0.1:1", "test", message); + verifyConnection(getSession().getSessionID(), "InternalTestProtocolSession", "127.0.0.1:1", "test", message); } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java index 147ec2a275..1f432be57a 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/QueueLogSubjectTest.java @@ -31,8 +31,8 @@ import org.apache.qpid.server.virtualhost.VirtualHost; public class QueueLogSubjectTest extends AbstractTestLogSubject { - AMQQueue _queue; - VirtualHost _testVhost; + private AMQQueue _queue; + private VirtualHost _testVhost; @Override public void setUp() throws Exception diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java index e96dc47367..0c356e1838 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/logging/subjects/SubscriptionLogSubjectTest.java @@ -37,10 +37,10 @@ import org.apache.qpid.server.virtualhost.VirtualHost; public class SubscriptionLogSubjectTest extends AbstractTestLogSubject { - AMQQueue _queue; - VirtualHost _testVhost; + private AMQQueue _queue; + private VirtualHost _testVhost; private int _channelID = 1; - Subscription _subscription; + private Subscription _subscription; public void setUp() throws Exception { @@ -52,13 +52,13 @@ public class SubscriptionLogSubjectTest extends AbstractTestLogSubject _queue = new MockAMQQueue("SubscriptionLogSubjectTest"); ((MockAMQQueue) _queue).setVirtualHost(_testVhost); - AMQChannel channel = new AMQChannel(_session, _channelID, _session.getVirtualHost().getMessageStore()); + AMQChannel channel = new AMQChannel(getSession(), _channelID, getSession().getVirtualHost().getMessageStore()); - _session.addChannel(channel); + getSession().addChannel(channel); SubscriptionFactory factory = new SubscriptionFactoryImpl(); - _subscription = factory.createSubscription(_channelID, _session, new AMQShortString("cTag"), + _subscription = factory.createSubscription(_channelID, getSession(), new AMQShortString("cTag"), false, null, false, new LimitlessCreditManager()); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java index dd1126992c..8c18ab85b0 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java @@ -34,13 +34,13 @@ public class PluginTest extends InternalBrokerBaseCase @Override public void configure() { - _configuration.getConfig().addProperty("plugin-directory", PLUGIN_DIRECTORY); - _configuration.getConfig().addProperty("cache-directory", CACHE_DIRECTORY); + getConfiguration().getConfig().addProperty("plugin-directory", PLUGIN_DIRECTORY); + getConfiguration().getConfig().addProperty("cache-directory", CACHE_DIRECTORY); } public void disabled_testLoadExchanges() throws Exception { - PluginManager manager = _registry.getPluginManager(); + PluginManager manager = getRegistry().getPluginManager(); Map<String, ExchangeType<?>> exchanges = manager.getExchanges(); assertNotNull("No exchanges found in " + PLUGIN_DIRECTORY, exchanges); assertEquals("Wrong number of exchanges found in " + PLUGIN_DIRECTORY, 2, exchanges.size()); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java index 6af011f91d..0707cab3d5 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java @@ -55,14 +55,14 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase */ public void testMessageCountAlert() throws Exception { - _session = new InternalTestProtocolSession(_virtualHost); - AMQChannel channel = new AMQChannel(_session, 2, _messageStore); - _session.addChannel(channel); + setSession(new InternalTestProtocolSession(getVirtualHost())); + AMQChannel channel = new AMQChannel(getSession(), 2, getMessageStore()); + getSession().addChannel(channel); - _queue = AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testQueue1"), false, new AMQShortString("AMQueueAlertTest"), + setQueue(AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testQueue1"), false, new AMQShortString("AMQueueAlertTest"), false, false, - _virtualHost, null); - _queueMBean = (AMQQueueMBean) _queue.getManagedObject(); + getVirtualHost(), null)); + _queueMBean = (AMQQueueMBean) getQueue().getManagedObject(); _queueMBean.setMaximumMessageCount(MAX_MESSAGE_COUNT); @@ -83,14 +83,14 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase */ public void testMessageSizeAlert() throws Exception { - _session = new InternalTestProtocolSession(_virtualHost); - AMQChannel channel = new AMQChannel(_session, 2, _messageStore); - _session.addChannel(channel); + setSession(new InternalTestProtocolSession(getVirtualHost())); + AMQChannel channel = new AMQChannel(getSession(), 2, getMessageStore()); + getSession().addChannel(channel); - _queue = AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testQueue2"), false, new AMQShortString("AMQueueAlertTest"), + setQueue(AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testQueue2"), false, new AMQShortString("AMQueueAlertTest"), false, false, - _virtualHost, null); - _queueMBean = (AMQQueueMBean) _queue.getManagedObject(); + getVirtualHost(), null)); + _queueMBean = (AMQQueueMBean) getQueue().getManagedObject(); _queueMBean.setMaximumMessageCount(MAX_MESSAGE_COUNT); _queueMBean.setMaximumMessageSize(MAX_MESSAGE_SIZE); @@ -113,18 +113,18 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase */ public void testQueueDepthAlertNoSubscriber() throws Exception { - _session = new InternalTestProtocolSession(_virtualHost); - AMQChannel channel = new AMQChannel(_session, 2, _messageStore); - _session.addChannel(channel); + setSession(new InternalTestProtocolSession(getVirtualHost())); + AMQChannel channel = new AMQChannel(getSession(), 2, getMessageStore()); + getSession().addChannel(channel); - _queue = AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testQueue3"), false, new AMQShortString("AMQueueAlertTest"), + setQueue(AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testQueue3"), false, new AMQShortString("AMQueueAlertTest"), false, false, - _virtualHost, null); - _queueMBean = (AMQQueueMBean) _queue.getManagedObject(); + getVirtualHost(), null)); + _queueMBean = (AMQQueueMBean) getQueue().getManagedObject(); _queueMBean.setMaximumMessageCount(MAX_MESSAGE_COUNT); _queueMBean.setMaximumQueueDepth(MAX_QUEUE_DEPTH); - while (_queue.getQueueDepth() < MAX_QUEUE_DEPTH) + while (getQueue().getQueueDepth() < MAX_QUEUE_DEPTH) { sendMessages(channel, 1, MAX_MESSAGE_SIZE); } @@ -146,14 +146,14 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase */ public void testMessageAgeAlert() throws Exception { - _session = new InternalTestProtocolSession(_virtualHost); - AMQChannel channel = new AMQChannel(_session, 2, _messageStore); - _session.addChannel(channel); + setSession(new InternalTestProtocolSession(getVirtualHost())); + AMQChannel channel = new AMQChannel(getSession(), 2, getMessageStore()); + getSession().addChannel(channel); - _queue = AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testQueue4"), false, new AMQShortString("AMQueueAlertTest"), + setQueue(AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testQueue4"), false, new AMQShortString("AMQueueAlertTest"), false, false, - _virtualHost, null); - _queueMBean = (AMQQueueMBean) _queue.getManagedObject(); + getVirtualHost(), null)); + _queueMBean = (AMQQueueMBean) getQueue().getManagedObject(); _queueMBean.setMaximumMessageCount(MAX_MESSAGE_COUNT); _queueMBean.setMaximumMessageAge(MAX_MESSAGE_AGE); @@ -179,18 +179,18 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase */ public void testQueueDepthAlertWithSubscribers() throws Exception { - AMQChannel channel = new AMQChannel(_session, 2, _messageStore); - _session.addChannel(channel); + AMQChannel channel = new AMQChannel(getSession(), 2, getMessageStore()); + getSession().addChannel(channel); // Create queue - _queue = getNewQueue(); + setQueue(getNewQueue()); Subscription subscription = - SUBSCRIPTION_FACTORY.createSubscription(channel.getChannelId(), _session, new AMQShortString("consumer_tag"), true, null, false, channel.getCreditManager()); + SUBSCRIPTION_FACTORY.createSubscription(channel.getChannelId(), getSession(), new AMQShortString("consumer_tag"), true, null, false, channel.getCreditManager()); - _queue.registerSubscription( + getQueue().registerSubscription( subscription, false); - _queueMBean = (AMQQueueMBean) _queue.getManagedObject(); + _queueMBean = (AMQQueueMBean) getQueue().getManagedObject(); _queueMBean.setMaximumMessageCount(9999l); // Set a high value, because this is not being tested _queueMBean.setMaximumQueueDepth(MAX_QUEUE_DEPTH); @@ -207,7 +207,7 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase // Kill the subscriber and check for the queue depth values. // Messages are unacknowledged, so those should get requeued. All messages should be on the Queue - _queue.unregisterSubscription(subscription); + getQueue().unregisterSubscription(subscription); channel.requeue(); assertEquals(new Long(totalSize), new Long(_queueMBean.getQueueDepth())); @@ -220,12 +220,12 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase // Connect a consumer again and check QueueDepth values. The queue should get emptied. // Messages will get delivered but still are unacknowledged. Subscription subscription2 = - SUBSCRIPTION_FACTORY.createSubscription(channel.getChannelId(), _session, new AMQShortString("consumer_tag"), true, null, false, channel.getCreditManager()); + SUBSCRIPTION_FACTORY.createSubscription(channel.getChannelId(), getSession(), new AMQShortString("consumer_tag"), true, null, false, channel.getCreditManager()); - _queue.registerSubscription( + getQueue().registerSubscription( subscription2, false); - while (_queue.getUndeliveredMessageCount()!= 0) + while (getQueue().getUndeliveredMessageCount()!= 0) { Thread.sleep(100); } @@ -233,11 +233,11 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase // Kill the subscriber again. Now those messages should get requeued again. Check if the queue depth // value is correct. - _queue.unregisterSubscription(subscription2); + getQueue().unregisterSubscription(subscription2); channel.requeue(); assertEquals(new Long(totalSize), new Long(_queueMBean.getQueueDepth())); - _session.closeSession(); + getSession().closeSession(); // Check the clear queue _queueMBean.clearQueue(); @@ -289,7 +289,7 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase protected void configure() { // Increase Alert Check period - _configuration.setHousekeepingExpiredMessageCheckPeriod(200); + getConfiguration().setHousekeepingExpiredMessageCheckPeriod(200); } private void sendMessages(AMQChannel channel, long messageCount, final long size) throws AMQException @@ -300,9 +300,9 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase { messages[i] = message(false, size); ArrayList<AMQQueue> qs = new ArrayList<AMQQueue>(); - qs.add(_queue); + qs.add(getQueue()); metaData[i] = messages[i].headersReceived(); - messages[i].setStoredMessage(_messageStore.addMessage(metaData[i])); + messages[i].setStoredMessage(getMessageStore().addMessage(metaData[i])); messages[i].enqueue(qs); @@ -334,7 +334,7 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase } }); - _queue.enqueue(new AMQMessage(messages[i].getStoredMessage())); + getQueue().enqueue(new AMQMessage(messages[i].getStoredMessage())); } } @@ -345,6 +345,6 @@ public class AMQQueueAlertTest extends InternalBrokerBaseCase false, new AMQShortString("AMQueueAlertTest"), false, - false, _virtualHost, null); + false, getVirtualHost(), null); } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java index 3735ef123d..5b72cfac40 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueMBeanTest.java @@ -34,7 +34,6 @@ import org.apache.qpid.server.message.MessageMetaData; import org.apache.qpid.server.subscription.Subscription; import org.apache.qpid.server.subscription.SubscriptionFactory; import org.apache.qpid.server.subscription.SubscriptionFactoryImpl; -import org.apache.qpid.server.protocol.AMQProtocolSession; import org.apache.qpid.server.protocol.InternalTestProtocolSession; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.store.TestableMemoryMessageStore; @@ -145,7 +144,7 @@ public class AMQQueueMBeanTest extends InternalBrokerBaseCase private void verifyBrokerState() { - TestableMemoryMessageStore store = (TestableMemoryMessageStore)_virtualHost.getMessageStore(); + TestableMemoryMessageStore store = (TestableMemoryMessageStore) getVirtualHost().getMessageStore(); // Unlike MessageReturnTest there is no need for a delay as there this thread does the clean up. @@ -155,19 +154,19 @@ public class AMQQueueMBeanTest extends InternalBrokerBaseCase public void testConsumerCount() throws AMQException { - assertTrue(_queue.getActiveConsumerCount() == 0); + assertTrue(getQueue().getActiveConsumerCount() == 0); assertTrue(_queueMBean.getActiveConsumerCount() == 0); - InternalTestProtocolSession protocolSession = new InternalTestProtocolSession(_virtualHost); + InternalTestProtocolSession protocolSession = new InternalTestProtocolSession(getVirtualHost()); - AMQChannel channel = new AMQChannel(protocolSession, 1, _messageStore); + AMQChannel channel = new AMQChannel(protocolSession, 1, getMessageStore()); protocolSession.addChannel(channel); Subscription subscription = SUBSCRIPTION_FACTORY.createSubscription(channel.getChannelId(), protocolSession, new AMQShortString("test"), false, null, false, channel.getCreditManager()); - _queue.registerSubscription(subscription, false); + getQueue().registerSubscription(subscription, false); assertEquals(1,(int)_queueMBean.getActiveConsumerCount()); @@ -187,8 +186,8 @@ public class AMQQueueMBeanTest extends InternalBrokerBaseCase null, true, channel.getCreditManager()); - _queue.registerSubscription(s1,false); - _queue.registerSubscription(s2,false); + getQueue().registerSubscription(s1,false); + getQueue().registerSubscription(s2,false); assertTrue(_queueMBean.getActiveConsumerCount() == 3); assertTrue(_queueMBean.getConsumerCount() == 3); @@ -215,10 +214,10 @@ public class AMQQueueMBeanTest extends InternalBrokerBaseCase //set+get exclusivity using the mbean, and also verify it is actually updated in the queue _queueMBean.setExclusive(true); assertTrue("Exclusive property should be true.",_queueMBean.isExclusive()); - assertTrue("Exclusive property should be true.",_queue.isExclusive()); + assertTrue("Exclusive property should be true.", getQueue().isExclusive()); _queueMBean.setExclusive(false); assertFalse("Exclusive property should be false.",_queueMBean.isExclusive()); - assertFalse("Exclusive property should be false.",_queue.isExclusive()); + assertFalse("Exclusive property should be false.", getQueue().isExclusive()); } public void testExceptions() throws Exception @@ -266,12 +265,12 @@ public class AMQQueueMBeanTest extends InternalBrokerBaseCase } IncomingMessage msg = message(false, false); - _queue.clearQueue(); + getQueue().clearQueue(); ArrayList<AMQQueue> qs = new ArrayList<AMQQueue>(); - qs.add(_queue); + qs.add(getQueue()); msg.enqueue(qs); MessageMetaData mmd = msg.headersReceived(); - msg.setStoredMessage(_messageStore.addMessage(mmd)); + msg.setStoredMessage(getMessageStore().addMessage(mmd)); long id = msg.getMessageNumber(); msg.addContentBodyFrame(new ContentChunk() @@ -356,8 +355,8 @@ public class AMQQueueMBeanTest extends InternalBrokerBaseCase } //create a channel and use it to exercise the capacity check mechanism - AMQChannel channel = new AMQChannel(_session, 1, _messageStore); - _queue.checkCapacity(channel); + AMQChannel channel = new AMQChannel(getSession(), 1, getMessageStore()); + getQueue().checkCapacity(channel); assertTrue(_queueMBean.isFlowOverfull()); assertTrue(channel.getBlocking()); @@ -416,7 +415,7 @@ public class AMQQueueMBeanTest extends InternalBrokerBaseCase { super.setUp(); - _queueMBean = new AMQQueueMBean(_queue); + _queueMBean = new AMQQueueMBean(getQueue()); } public void tearDown() @@ -430,16 +429,16 @@ public class AMQQueueMBeanTest extends InternalBrokerBaseCase { IncomingMessage currentMessage = message(false, persistent); ArrayList<AMQQueue> qs = new ArrayList<AMQQueue>(); - qs.add(_queue); + qs.add(getQueue()); currentMessage.enqueue(qs); // route header MessageMetaData mmd = currentMessage.headersReceived(); - currentMessage.setStoredMessage(_messageStore.addMessage(mmd)); + currentMessage.setStoredMessage(getMessageStore().addMessage(mmd)); // Add the body so we have somthing to test later currentMessage.addContentBodyFrame( - _session.getMethodRegistry() + getSession().getMethodRegistry() .getProtocolVersionMethodConverter() .convertToContentChunk( new ContentBody(ByteBuffer.allocate((int) MESSAGE_SIZE), diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java index b0a655e8b6..9b65b7750c 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java @@ -236,7 +236,6 @@ public class SimpleAMQQueueTest extends InternalBrokerBaseCase ex = e; } assertNotNull(ex); - assertTrue(ex instanceof AMQException); // Check we cannot add an exclusive subscriber to a queue with an // existing subscription diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java index 512efca9bc..e45c8d7b96 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/registry/ApplicationRegistryShutdownTest.java @@ -84,7 +84,7 @@ public class ApplicationRegistryShutdownTest extends InternalBrokerBaseCase assertTrue("No new SASL mechanisms added by initialisation.", additions.size() != 0 ); //Close the registry which will perform the close the AuthenticationManager - _registry.close(); + getRegistry().close(); //Validate that the SASL plugFins have been removed. Provider[] providersAfterClose = Security.getProviders(); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreShutdownTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreShutdownTest.java index a695a67eea..6ca88d1796 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreShutdownTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreShutdownTest.java @@ -32,11 +32,11 @@ public class MessageStoreShutdownTest extends InternalBrokerBaseCase public void test() { - subscribe(_session, _channel, _queue); + subscribe(getSession(), getChannel(), getQueue()); try { - publishMessages(_session, _channel, 1); + publishMessages(getSession(), getChannel(), 1); } catch (AMQException e) { @@ -46,7 +46,7 @@ public class MessageStoreShutdownTest extends InternalBrokerBaseCase try { - _registry.close(); + getRegistry().close(); } catch (Exception e) { @@ -54,7 +54,7 @@ public class MessageStoreShutdownTest extends InternalBrokerBaseCase fail(e.getMessage()); } - assertTrue("Session should now be closed", _session.isClosed()); + assertTrue("Session should now be closed", getSession().isClosed()); //Test attempting to modify the broker state after session has been closed. @@ -62,14 +62,14 @@ public class MessageStoreShutdownTest extends InternalBrokerBaseCase //The Message should have been removed from the unacked list. //Ack Messages - List<InternalTestProtocolSession.DeliveryPair> list = _session.getDelivers(_channel.getChannelId(), new AMQShortString("sgen_1"), 1); + List<InternalTestProtocolSession.DeliveryPair> list = getSession().getDelivers(getChannel().getChannelId(), new AMQShortString("sgen_1"), 1); InternalTestProtocolSession.DeliveryPair pair = list.get(0); try { // The message should now be requeued and so unable to ack it. - _channel.acknowledgeMessage(pair.getDeliveryTag(), false); + getChannel().acknowledgeMessage(pair.getDeliveryTag(), false); } catch (AMQException e) { diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java index 9cc9148c55..3ebe631f62 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java @@ -110,15 +110,15 @@ public class MessageStoreTest extends InternalBrokerBaseCase protected void reloadVirtualHost() { - VirtualHost original = _virtualHost; + VirtualHost original = getVirtualHost(); - if (_virtualHost != null) + if (getVirtualHost() != null) { try { - _virtualHost.close(); - _virtualHost.getApplicationRegistry(). - getVirtualHostRegistry().unregisterVirtualHost(_virtualHost); + getVirtualHost().close(); + getVirtualHost().getApplicationRegistry(). + getVirtualHostRegistry().unregisterVirtualHost(getVirtualHost()); } catch (Exception e) { @@ -128,7 +128,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase try { - _virtualHost = ApplicationRegistry.getInstance().createVirtualHost(new VirtualHostConfiguration(getClass().getName(), _config)); + setVirtualHost(ApplicationRegistry.getInstance().createVirtualHost(new VirtualHostConfiguration(getClass().getName(), _config))); } catch (Exception e) { @@ -136,7 +136,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase fail(e.getMessage()); } - assertTrue("Virtualhost has not changed, reload was not successful", original != _virtualHost); + assertTrue("Virtualhost has not changed, reload was not successful", original != getVirtualHost()); } /** @@ -145,7 +145,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase */ public void testQueueExchangeAndBindingCreation() throws Exception { - assertEquals("Should not be any existing queues", 0, _virtualHost.getQueueRegistry().getQueues().size()); + assertEquals("Should not be any existing queues", 0, getVirtualHost().getQueueRegistry().getQueues().size()); createAllQueues(); createAllTopicQueues(); @@ -183,7 +183,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase validateMessageOnTopics(2, true); assertEquals("Not all queues correctly registered", - 10, _virtualHost.getQueueRegistry().getQueues().size()); + 10, getVirtualHost().getQueueRegistry().getQueues().size()); } /** @@ -212,7 +212,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase { testMessagePersistence(); - QueueRegistry queueRegistry = _virtualHost.getQueueRegistry(); + QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); assertEquals("Incorrect number of queues registered after recovery", 6, queueRegistry.getQueues().size()); @@ -237,7 +237,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase public void testQueuePersistence() throws Exception { assertEquals("Should not be any existing queues", - 0, _virtualHost.getQueueRegistry().getQueues().size()); + 0, getVirtualHost().getQueueRegistry().getQueues().size()); //create durable and non durable queues/topics createAllQueues(); @@ -246,7 +246,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase //reload the virtual host, prompting recovery of the queues/topics reloadVirtualHost(); - QueueRegistry queueRegistry = _virtualHost.getQueueRegistry(); + QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); assertEquals("Incorrect number of queues registered after recovery", 6, queueRegistry.getQueues().size()); @@ -285,22 +285,22 @@ public class MessageStoreTest extends InternalBrokerBaseCase //Register Durable Queue createQueue(durableQueueName, false, true, false, false); - QueueRegistry queueRegistry = _virtualHost.getQueueRegistry(); + QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); assertEquals("Incorrect number of queues registered before recovery", 1, queueRegistry.getQueues().size()); reloadVirtualHost(); - queueRegistry = _virtualHost.getQueueRegistry(); + queueRegistry = getVirtualHost().getQueueRegistry(); assertEquals("Incorrect number of queues registered after first recovery", 1, queueRegistry.getQueues().size()); //test that removing the queue means it is not recovered next time - _virtualHost.getDurableConfigurationStore().removeQueue(queueRegistry.getQueue(durableQueueName)); + getVirtualHost().getDurableConfigurationStore().removeQueue(queueRegistry.getQueue(durableQueueName)); reloadVirtualHost(); - queueRegistry = _virtualHost.getQueueRegistry(); + queueRegistry = getVirtualHost().getQueueRegistry(); assertEquals("Incorrect number of queues registered after second recovery", 0, queueRegistry.getQueues().size()); assertNull("Durable queue was not removed:" + durableQueueName, @@ -314,12 +314,12 @@ public class MessageStoreTest extends InternalBrokerBaseCase */ public void testExchangePersistence() throws Exception { - int origExchangeCount = _virtualHost.getExchangeRegistry().getExchangeNames().size(); + int origExchangeCount = getVirtualHost().getExchangeRegistry().getExchangeNames().size(); Map<AMQShortString, Exchange> oldExchanges = createExchanges(); assertEquals("Incorrect number of exchanges registered before recovery", - origExchangeCount + 3, _virtualHost.getExchangeRegistry().getExchangeNames().size()); + origExchangeCount + 3, getVirtualHost().getExchangeRegistry().getExchangeNames().size()); reloadVirtualHost(); @@ -334,26 +334,26 @@ public class MessageStoreTest extends InternalBrokerBaseCase */ public void testDurableExchangeRemoval() throws Exception { - int origExchangeCount = _virtualHost.getExchangeRegistry().getExchangeNames().size(); + int origExchangeCount = getVirtualHost().getExchangeRegistry().getExchangeNames().size(); createExchange(DirectExchange.TYPE, directExchangeName, true); - ExchangeRegistry exchangeRegistry = _virtualHost.getExchangeRegistry(); + ExchangeRegistry exchangeRegistry = getVirtualHost().getExchangeRegistry(); assertEquals("Incorrect number of exchanges registered before recovery", origExchangeCount + 1, exchangeRegistry.getExchangeNames().size()); reloadVirtualHost(); - exchangeRegistry = _virtualHost.getExchangeRegistry(); + exchangeRegistry = getVirtualHost().getExchangeRegistry(); assertEquals("Incorrect number of exchanges registered after first recovery", origExchangeCount + 1, exchangeRegistry.getExchangeNames().size()); //test that removing the exchange means it is not recovered next time - _virtualHost.getDurableConfigurationStore().removeExchange(exchangeRegistry.getExchange(directExchangeName)); + getVirtualHost().getDurableConfigurationStore().removeExchange(exchangeRegistry.getExchange(directExchangeName)); reloadVirtualHost(); - exchangeRegistry = _virtualHost.getExchangeRegistry(); + exchangeRegistry = getVirtualHost().getExchangeRegistry(); assertEquals("Incorrect number of exchanges registered after second recovery", origExchangeCount, exchangeRegistry.getExchangeNames().size()); assertNull("Durable exchange was not removed:" + directExchangeName, @@ -368,7 +368,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase */ public void testBindingPersistence() throws Exception { - int origExchangeCount = _virtualHost.getExchangeRegistry().getExchangeNames().size(); + int origExchangeCount = getVirtualHost().getExchangeRegistry().getExchangeNames().size(); createAllQueues(); createAllTopicQueues(); @@ -384,7 +384,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase bindAllTopicQueuesToExchange(topicExchange, topicRouting); assertEquals("Incorrect number of exchanges registered before recovery", - origExchangeCount + 3, _virtualHost.getExchangeRegistry().getExchangeNames().size()); + origExchangeCount + 3, getVirtualHost().getExchangeRegistry().getExchangeNames().size()); reloadVirtualHost(); @@ -400,7 +400,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase */ public void testDurableBindingRemoval() throws Exception { - QueueRegistry queueRegistry = _virtualHost.getQueueRegistry(); + QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); //create durable queue and exchange, bind them Exchange exch = createExchange(DirectExchange.TYPE, directExchangeName, true); @@ -413,11 +413,11 @@ public class MessageStoreTest extends InternalBrokerBaseCase //verify binding is actually normally recovered reloadVirtualHost(); - queueRegistry = _virtualHost.getQueueRegistry(); + queueRegistry = getVirtualHost().getQueueRegistry(); assertEquals("Incorrect number of bindings registered after first recovery", 1, queueRegistry.getQueue(durableQueueName).getBindings().size()); - ExchangeRegistry exchangeRegistry = _virtualHost.getExchangeRegistry(); + ExchangeRegistry exchangeRegistry = getVirtualHost().getExchangeRegistry(); exch = exchangeRegistry.getExchange(directExchangeName); assertNotNull("Exchange was not recovered", exch); @@ -426,7 +426,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase reloadVirtualHost(); - queueRegistry = _virtualHost.getQueueRegistry(); + queueRegistry = getVirtualHost().getQueueRegistry(); assertEquals("Incorrect number of bindings registered after second recovery", 0, queueRegistry.getQueue(durableQueueName).getBindings().size()); } @@ -438,7 +438,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase */ private void validateExchanges(int originalNumExchanges, Map<AMQShortString, Exchange> oldExchanges) { - ExchangeRegistry registry = _virtualHost.getExchangeRegistry(); + ExchangeRegistry registry = getVirtualHost().getExchangeRegistry(); assertTrue(directExchangeName + " exchange NOT reloaded", registry.getExchangeNames().contains(directExchangeName)); @@ -461,7 +461,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase /** Validates the Durable queues and their properties are as expected following recovery */ private void validateBindingProperties() { - QueueRegistry queueRegistry = _virtualHost.getQueueRegistry(); + QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); assertEquals("Incorrect number of (durable) queues following recovery", 6, queueRegistry.getQueues().size()); @@ -497,7 +497,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase private void setQueueExclusivity(boolean exclusive) throws AMQException { - QueueRegistry queueRegistry = _virtualHost.getQueueRegistry(); + QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); AMQQueue queue = queueRegistry.getQueue(durableExclusiveQueueName); @@ -506,7 +506,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase private void validateQueueExclusivityProperty(boolean expected) { - QueueRegistry queueRegistry = _virtualHost.getQueueRegistry(); + QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); AMQQueue queue = queueRegistry.getQueue(durableExclusiveQueueName); @@ -516,7 +516,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase private void validateDurableQueueProperties() { - QueueRegistry queueRegistry = _virtualHost.getQueueRegistry(); + QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); validateQueueProperties(queueRegistry.getQueue(durablePriorityQueueName), true, true, false, false); validateQueueProperties(queueRegistry.getQueue(durablePriorityTopicQueueName), true, true, false, false); @@ -603,7 +603,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase currentMessage.setExpiration(); MessageMetaData mmd = currentMessage.headersReceived(); - currentMessage.setStoredMessage(_virtualHost.getMessageStore().addMessage(mmd)); + currentMessage.setStoredMessage(getVirtualHost().getMessageStore().addMessage(mmd)); currentMessage.getStoredMessage().flushToStore(); currentMessage.route(); @@ -611,7 +611,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase // check and deliver if header says body length is zero if (currentMessage.allContentReceived()) { - ServerTransaction trans = new AutoCommitTransaction(_virtualHost.getMessageStore()); + ServerTransaction trans = new AutoCommitTransaction(getVirtualHost().getMessageStore()); final List<? extends BaseQueue> destinationQueues = currentMessage.getDestinationQueues(); trans.enqueue(currentMessage.getDestinationQueues(), currentMessage, new ServerTransaction.Action() { public void postCommit() @@ -703,13 +703,13 @@ public class MessageStoreTest extends InternalBrokerBaseCase try { queue = AMQQueueFactory.createAMQQueueImpl(queueName, durable, queueOwner, false, exclusive, - _virtualHost, queueArguments); + getVirtualHost(), queueArguments); validateQueueProperties(queue, usePriority, durable, exclusive, lastValueQueue); if (queue.isDurable() && !queue.isAutoDelete()) { - _virtualHost.getMessageStore().createQueue(queue, queueArguments); + getVirtualHost().getMessageStore().createQueue(queue, queueArguments); } } catch (AMQException e) @@ -717,7 +717,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase fail(e.getMessage()); } - _virtualHost.getQueueRegistry().registerQueue(queue); + getVirtualHost().getQueueRegistry().registerQueue(queue); } @@ -741,7 +741,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase try { - exchange = type.newInstance(_virtualHost, name, durable, 0, false); + exchange = type.newInstance(getVirtualHost(), name, durable, 0, false); } catch (AMQException e) { @@ -750,10 +750,10 @@ public class MessageStoreTest extends InternalBrokerBaseCase try { - _virtualHost.getExchangeRegistry().registerExchange(exchange); + getVirtualHost().getExchangeRegistry().registerExchange(exchange); if (durable) { - _virtualHost.getMessageStore().createExchange(exchange); + getVirtualHost().getMessageStore().createExchange(exchange); } } catch (AMQException e) @@ -768,7 +768,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase FieldTable queueArguments = new FieldTable(); queueArguments.put(AMQQueueFactory.X_QPID_PRIORITIES, DEFAULT_PRIORTY_LEVEL); - QueueRegistry queueRegistry = _virtualHost.getQueueRegistry(); + QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); bindQueueToExchange(exchange, routingKey, queueRegistry.getQueue(durablePriorityQueueName), false, queueArguments); bindQueueToExchange(exchange, routingKey, queueRegistry.getQueue(durableQueueName), false, null); @@ -782,7 +782,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase FieldTable queueArguments = new FieldTable(); queueArguments.put(AMQQueueFactory.X_QPID_PRIORITIES, DEFAULT_PRIORTY_LEVEL); - QueueRegistry queueRegistry = _virtualHost.getQueueRegistry(); + QueueRegistry queueRegistry = getVirtualHost().getQueueRegistry(); bindQueueToExchange(exchange, routingKey, queueRegistry.getQueue(durablePriorityTopicQueueName), true, queueArguments); bindQueueToExchange(exchange, routingKey, queueRegistry.getQueue(durableTopicQueueName), true, null); @@ -803,7 +803,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase try { - _virtualHost.getBindingFactory().addBinding(String.valueOf(routingKey), queue, exchange, FieldTable.convertToMap(bindArguments)); + getVirtualHost().getBindingFactory().addBinding(String.valueOf(routingKey), queue, exchange, FieldTable.convertToMap(bindArguments)); } catch (Exception e) { @@ -823,7 +823,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase try { - _virtualHost.getBindingFactory().removeBinding(String.valueOf(routingKey), queue, exchange, FieldTable.convertToMap(bindArguments)); + getVirtualHost().getBindingFactory().removeBinding(String.valueOf(routingKey), queue, exchange, FieldTable.convertToMap(bindArguments)); } catch (Exception e) { @@ -857,7 +857,7 @@ public class MessageStoreTest extends InternalBrokerBaseCase private void validateMessageOnQueue(AMQShortString queueName, long messageCount) { - AMQQueue queue = _virtualHost.getQueueRegistry().getQueue(queueName); + AMQQueue queue = getVirtualHost().getQueueRegistry().getQueue(queueName); assertNotNull("Queue(" + queueName + ") not correctly registered:", queue); diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java index d0db4ebd38..b315a79b33 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/QueueBrowserUsesNoAckTest.java @@ -39,29 +39,29 @@ public class QueueBrowserUsesNoAckTest extends InternalBrokerBaseCase checkStoreContents(0); //Send required messsages to the queue - publishMessages(_session, _channel, sendMessageCount); + publishMessages(getSession(), getChannel(), sendMessageCount); //Ensure they are stored checkStoreContents(sendMessageCount); //Check that there are no unacked messages assertEquals("Channel should have no unacked msgs ", 0, - _channel.getUnacknowledgedMessageMap().size()); + getChannel().getUnacknowledgedMessageMap().size()); //Set the prefetch on the session to be less than the sent messages - _channel.setCredit(0, prefetch); + getChannel().setCredit(0, prefetch); //browse the queue - AMQShortString browser = browse(_channel, _queue); + AMQShortString browser = browse(getChannel(), getQueue()); - _queue.deliverAsync(); + getQueue().deliverAsync(); //Wait for messages to fill the prefetch - _session.awaitDelivery(prefetch); + getSession().awaitDelivery(prefetch); //Get those messages List<InternalTestProtocolSession.DeliveryPair> messages = - _session.getDelivers(_channel.getChannelId(), browser, + getSession().getDelivers(getChannel().getChannelId(), browser, prefetch); //Ensure we recevied the prefetched messages @@ -70,7 +70,7 @@ public class QueueBrowserUsesNoAckTest extends InternalBrokerBaseCase //Check the process didn't suspend the subscription as this would // indicate we are using the prefetch credit. i.e. using acks not No-Ack assertTrue("The subscription has been suspended", - !_channel.getSubscription(browser).getState() + !getChannel().getSubscription(browser).getState() .equals(Subscription.State.SUSPENDED)); } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java index 47b5b1c1c2..595822173f 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java @@ -49,16 +49,16 @@ import org.apache.qpid.util.MockChannel; public class InternalBrokerBaseCase extends QpidTestCase { - protected IApplicationRegistry _registry; - protected MessageStore _messageStore; - protected MockChannel _channel; - protected InternalTestProtocolSession _session; - protected VirtualHost _virtualHost; - protected AMQQueue _queue; - protected AMQShortString QUEUE_NAME; - protected ServerConfiguration _configuration; - protected XMLConfiguration _configXml = new XMLConfiguration(); - protected boolean _started = false; + private IApplicationRegistry _registry; + private MessageStore _messageStore; + private MockChannel _channel; + private InternalTestProtocolSession _session; + private VirtualHost _virtualHost; + private AMQQueue _queue; + private AMQShortString QUEUE_NAME; + private ServerConfiguration _configuration; + private XMLConfiguration _configXml = new XMLConfiguration(); + private boolean _started = false; public void setUp() throws Exception { @@ -266,4 +266,103 @@ public class InternalBrokerBaseCase extends QpidTestCase } } + public IApplicationRegistry getRegistry() + { + return _registry; + } + + public void setRegistry(IApplicationRegistry registry) + { + _registry = registry; + } + + public MessageStore getMessageStore() + { + return _messageStore; + } + + public void setMessageStore(MessageStore messageStore) + { + _messageStore = messageStore; + } + + public MockChannel getChannel() + { + return _channel; + } + + public void setChannel(MockChannel channel) + { + _channel = channel; + } + + public InternalTestProtocolSession getSession() + { + return _session; + } + + public void setSession(InternalTestProtocolSession session) + { + _session = session; + } + + public VirtualHost getVirtualHost() + { + return _virtualHost; + } + + public void setVirtualHost(VirtualHost virtualHost) + { + _virtualHost = virtualHost; + } + + public AMQQueue getQueue() + { + return _queue; + } + + public void setQueue(AMQQueue queue) + { + _queue = queue; + } + + public AMQShortString getQUEUE_NAME() + { + return QUEUE_NAME; + } + + public void setQUEUE_NAME(AMQShortString QUEUE_NAME) + { + this.QUEUE_NAME = QUEUE_NAME; + } + + public ServerConfiguration getConfiguration() + { + return _configuration; + } + + public void setConfiguration(ServerConfiguration configuration) + { + _configuration = configuration; + } + + public XMLConfiguration getConfigXml() + { + return _configXml; + } + + public void setConfigXml(XMLConfiguration configXml) + { + _configXml = configXml; + } + + public boolean isStarted() + { + return _started; + } + + public void setStarted(boolean started) + { + _started = started; + } } diff --git a/qpid/java/broker/src/velocity/java/org/apache/qpid/server/logging/GenerateLogMessages.java b/qpid/java/broker/src/velocity/java/org/apache/qpid/server/logging/GenerateLogMessages.java index 672c869f77..902b86f80b 100644 --- a/qpid/java/broker/src/velocity/java/org/apache/qpid/server/logging/GenerateLogMessages.java +++ b/qpid/java/broker/src/velocity/java/org/apache/qpid/server/logging/GenerateLogMessages.java @@ -37,7 +37,7 @@ import java.util.ResourceBundle; public class GenerateLogMessages { private boolean DEBUG = false; - private static String _tmplDir; + private String _tmplDir; private String _outputDir; private List<String> _logMessages = new LinkedList<String>(); private String _packageSource; @@ -508,7 +508,7 @@ public class GenerateLogMessages * Just a inner exception to be able to identify when a type that is not * 'number' occurs in the message parameter text. */ - private class InvalidTypeException extends Throwable + private static class InvalidTypeException extends Exception { public InvalidTypeException(String message) { diff --git a/qpid/java/client/example/src/main/java/org/apache/qpid/example/Drain.java b/qpid/java/client/example/src/main/java/org/apache/qpid/example/Drain.java index 831cea8745..b43031ad23 100644 --- a/qpid/java/client/example/src/main/java/org/apache/qpid/example/Drain.java +++ b/qpid/java/client/example/src/main/java/org/apache/qpid/example/Drain.java @@ -100,6 +100,6 @@ public class Drain extends OptionParser String u = "Usage: drain [OPTIONS] 'ADDRESS'"; String d = "Drains messages from the specified address."; - Drain drain = new Drain(args,u,d); + new Drain(args,u,d); } } diff --git a/qpid/java/client/example/src/main/java/org/apache/qpid/example/OptionParser.java b/qpid/java/client/example/src/main/java/org/apache/qpid/example/OptionParser.java index 6b1f514258..f4e17c5c4c 100644 --- a/qpid/java/client/example/src/main/java/org/apache/qpid/example/OptionParser.java +++ b/qpid/java/client/example/src/main/java/org/apache/qpid/example/OptionParser.java @@ -69,7 +69,7 @@ public class OptionParser protected Map<String,Object> optMap = new HashMap<String,Object>(); - protected static List<Option> optDefs = new ArrayList<Option>(); + protected static final List<Option> optDefs = new ArrayList<Option>(); protected String usage; protected String desc; diff --git a/qpid/java/client/example/src/main/java/org/apache/qpid/example/Spout.java b/qpid/java/client/example/src/main/java/org/apache/qpid/example/Spout.java index e831df8d28..5da319a658 100644 --- a/qpid/java/client/example/src/main/java/org/apache/qpid/example/Spout.java +++ b/qpid/java/client/example/src/main/java/org/apache/qpid/example/Spout.java @@ -143,6 +143,6 @@ public class Spout extends OptionParser String u = "Usage: spout [OPTIONS] 'ADDRESS'"; String d = "Send messages to the specified address."; - Spout drain = new Spout(args,u,d); + new Spout(args,u,d); } } diff --git a/qpid/java/client/example/src/main/java/org/apache/qpid/example/shared/InitialContextHelper.java b/qpid/java/client/example/src/main/java/org/apache/qpid/example/shared/InitialContextHelper.java index 1328816602..16a185133a 100644 --- a/qpid/java/client/example/src/main/java/org/apache/qpid/example/shared/InitialContextHelper.java +++ b/qpid/java/client/example/src/main/java/org/apache/qpid/example/shared/InitialContextHelper.java @@ -37,8 +37,8 @@ public class InitialContextHelper { public static final String _defaultPropertiesName = "example.properties"; - protected static Properties _fileProperties; - protected static InitialContext _initialContext; + protected Properties _fileProperties; + protected InitialContext _initialContext; protected static final Logger _log = LoggerFactory.getLogger(InitialContextHelper.class); public InitialContextHelper(String propertiesName) throws ContextException diff --git a/qpid/java/client/example/src/main/java/org/apache/qpid/example/subscriber/MonitoredSubscriber.java b/qpid/java/client/example/src/main/java/org/apache/qpid/example/subscriber/MonitoredSubscriber.java index d43b823a13..e4eb5ac7f5 100644 --- a/qpid/java/client/example/src/main/java/org/apache/qpid/example/subscriber/MonitoredSubscriber.java +++ b/qpid/java/client/example/src/main/java/org/apache/qpid/example/subscriber/MonitoredSubscriber.java @@ -33,7 +33,7 @@ public class MonitoredSubscriber extends Subscriber private static final Logger _logger = LoggerFactory.getLogger(MonitoredSubscriber.class); - private static MessageConsumer _monitorConsumer; + private MessageConsumer _monitorConsumer; public MonitoredSubscriber() { @@ -107,7 +107,7 @@ public class MonitoredSubscriber extends Subscriber MonitoredSubscriber._logger.info("Starting monitored subscription ..."); - MonitoredSubscriber._connection.start(); + _connection.start(); //and now start ordinary consumption too subscribe(); diff --git a/qpid/java/client/example/src/main/java/org/apache/qpid/example/subscriber/Subscriber.java b/qpid/java/client/example/src/main/java/org/apache/qpid/example/subscriber/Subscriber.java index f75558299c..c36668575f 100644 --- a/qpid/java/client/example/src/main/java/org/apache/qpid/example/subscriber/Subscriber.java +++ b/qpid/java/client/example/src/main/java/org/apache/qpid/example/subscriber/Subscriber.java @@ -38,13 +38,13 @@ public class Subscriber { private static final Logger _log = LoggerFactory.getLogger(Subscriber.class); - protected static Connection _connection; + protected Connection _connection; - protected static MessageConsumer _consumer; + protected MessageConsumer _consumer; - protected static InitialContextHelper _contextHelper; + protected InitialContextHelper _contextHelper; - protected static AMQConnectionFactory _connectionFactory; + protected AMQConnectionFactory _connectionFactory; protected Destination _destination; diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java index 6b5673509e..ee52cd50af 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java @@ -93,8 +93,8 @@ public class AMQBrokerDetails implements BrokerDetails if (transport == null) { - throw URLHelper.parseError(-1, "Unknown transport:'" + transport + "'" + - " In broker URL:'" + url + "' Format: " + URL_FORMAT_EXAMPLE, ""); + throw URLHelper.parseError(-1, "Unknown transport in broker URL:'" + + url + "' Format: " + URL_FORMAT_EXAMPLE, ""); } setTransport(transport); @@ -319,6 +319,15 @@ public class AMQBrokerDetails implements BrokerDetails //todo do we need to compare all the options as well? } + @Override + public int hashCode() + { + int result = _host != null ? _host.hashCode() : 0; + result = 31 * result + _port; + result = 31 * result + (_transport != null ? _transport.hashCode() : 0); + return result; + } + private String printOptionsURL() { StringBuffer optionsURL = new StringBuffer(); diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java index c6bc1bd622..3a2910732f 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java @@ -123,7 +123,7 @@ public abstract class AMQDestination implements Destination, Referenceable } } - protected static DestSyntax defaultDestSyntax; + protected final static DestSyntax defaultDestSyntax; protected DestSyntax _destSyntax; diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java index 0f7e0b0812..f54189db6d 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java @@ -150,7 +150,7 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic oldVal = _slowAccessConsumers.put(id, consumer); } - return consumer; + return oldVal; } @@ -1959,7 +1959,6 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic AMQDestination amqd = (AMQDestination) destination; - final AMQProtocolHandler protocolHandler = getProtocolHandler(); // TODO: Define selectors in AMQP // TODO: construct the rawSelector from the selector string if rawSelector == null final FieldTable ft = FieldTableFactory.newFieldTable(); diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java b/qpid/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java index c9212a54c1..c81ad6422f 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/handler/ConnectionStartMethodHandler.java @@ -138,10 +138,9 @@ public class ConnectionStartMethodHandler implements StateAwareMethodListener<Co final String locales = new String(body.getLocales(), "utf8"); final StringTokenizer tokenizer = new StringTokenizer(locales, " "); - String selectedLocale = null; if (tokenizer.hasMoreTokens()) { - selectedLocale = tokenizer.nextToken(); + tokenizer.nextToken(); } else { diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java b/qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java index 5145c01054..08dd256512 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_10.java @@ -579,7 +579,7 @@ public class AMQMessageDelegate_0_10 extends AbstractAMQMessageDelegate } else { - return Float.valueOf(null); + throw new NullPointerException("No such property: " + propertyName); } } diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java b/qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java index 1d415b3c5f..cec4268a7b 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/message/AMQMessageDelegate_0_8.java @@ -70,7 +70,8 @@ public class AMQMessageDelegate_0_8 extends AbstractAMQMessageDelegate _contentHeaderProperties = properties; _deliveryTag = deliveryTag; _readableProperties = (_contentHeaderProperties != null); - _headerAdapter = new JMSHeaderAdapter(((BasicContentHeaderProperties) _contentHeaderProperties).getHeaders()); + _headerAdapter = new JMSHeaderAdapter(_readableProperties ? ((BasicContentHeaderProperties) _contentHeaderProperties).getHeaders() + : (new BasicContentHeaderProperties()).getHeaders() ); } // Used for the creation of new messages diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java b/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java index 2e4a6eeb6b..e295d4a2a0 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java @@ -236,7 +236,7 @@ public final class JMSHeaderAdapter } else { - f = Float.valueOf(null); + throw new NullPointerException("No such property: " + string); } } diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolBufferMonitorFilter.java b/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolBufferMonitorFilter.java index 93cc5e7ec3..bbd0a7b144 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolBufferMonitorFilter.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/protocol/ProtocolBufferMonitorFilter.java @@ -36,9 +36,9 @@ public class ProtocolBufferMonitorFilter extends IoFilterAdapter { private static final Logger _logger = LoggerFactory.getLogger(ProtocolBufferMonitorFilter.class); - public static long DEFAULT_FREQUENCY = 5000; + public static final long DEFAULT_FREQUENCY = 5000; - public static int DEFAULT_THRESHOLD = 3000; + public static final int DEFAULT_THRESHOLD = 3000; private int _bufferedMessages = 0; diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/transport/TransportConnection.java b/qpid/java/client/src/main/java/org/apache/qpid/client/transport/TransportConnection.java index 8e4b59910c..aef3a563af 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/transport/TransportConnection.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/transport/TransportConnection.java @@ -193,11 +193,14 @@ public class TransportConnection public static void createVMBroker(int port) throws AMQVMBrokerCreationException { - if (_acceptor == null) + synchronized(TransportConnection.class) { - _acceptor = new VmPipeAcceptor(); + if (_acceptor == null) + { + _acceptor = new VmPipeAcceptor(); - IoServiceConfig config = _acceptor.getDefaultConfig(); + IoServiceConfig config = _acceptor.getDefaultConfig(); + } } synchronized (_inVmPipeAddress) { @@ -313,15 +316,18 @@ public class TransportConnection public static void killAllVMBrokers() { _logger.info("Killing all VM Brokers"); - if (_acceptor != null) - { - _acceptor.unbindAll(); - } - synchronized (_inVmPipeAddress) + synchronized(TransportConnection.class) { - _inVmPipeAddress.clear(); + if (_acceptor != null) + { + _acceptor.unbindAll(); + } + synchronized (_inVmPipeAddress) + { + _inVmPipeAddress.clear(); + } + _acceptor = null; } - _acceptor = null; _currentInstance = -1; _currentVMPort = -1; } diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java b/qpid/java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java index 504d475740..87cc2e7a5a 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/transport/VmPipeTransportConnection.java @@ -36,7 +36,7 @@ public class VmPipeTransportConnection implements ITransportConnection { private static final Logger _logger = LoggerFactory.getLogger(VmPipeTransportConnection.class); - private static int _port; + private int _port; private MINANetworkDriver _networkDriver; diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/util/BlockingWaiter.java b/qpid/java/client/src/main/java/org/apache/qpid/client/util/BlockingWaiter.java index a3d015eadc..208658a5ff 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/util/BlockingWaiter.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/util/BlockingWaiter.java @@ -242,22 +242,22 @@ public abstract class BlockingWaiter<T> _lock.lock(); - if (_closed) + try { - return; - } + if (_closed) + { + return; + } - if (_error == null) - { - _error = e; - } - else - { - System.err.println("WARNING: new error '" + e == null ? "null" : e.getMessage() + "' arrived while old one not yet processed:" + _error.getMessage()); - } + if (_error == null) + { + _error = e; + } + else + { + System.err.println("WARNING: new error '" + e == null ? "null" : e.getMessage() + "' arrived while old one not yet processed:" + _error.getMessage()); + } - try - { if (_waiting.get()) { diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/NonQpidMessage.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/NonQpidMessage.java index df53c796b2..b1cf23bb9e 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/NonQpidMessage.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/NonQpidMessage.java @@ -26,6 +26,7 @@ import java.util.Hashtable; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Message; +import javax.jms.MessageFormatException; public class NonQpidMessage implements Message { @@ -278,9 +279,17 @@ public class NonQpidMessage implements Message { return (Float) o; } + else if(o instanceof String) + { + return Float.valueOf((String)o); + } + else if(o == null) + { + throw new NullPointerException("No such property: " + string); + } else { - return Float.valueOf(null); + throw new MessageFormatException("getFloatProperty(\""+string+"\") failed as value is not a float: " + o); } } else @@ -300,7 +309,7 @@ public class NonQpidMessage implements Message } else { - return Double.valueOf(null); + return getFloatProperty(string); } } else diff --git a/qpid/java/common/src/main/java/org/apache/configuration/PropertyNameResolver.java b/qpid/java/common/src/main/java/org/apache/configuration/PropertyNameResolver.java index 2c1fb0ed67..73ee747c07 100644 --- a/qpid/java/common/src/main/java/org/apache/configuration/PropertyNameResolver.java +++ b/qpid/java/common/src/main/java/org/apache/configuration/PropertyNameResolver.java @@ -99,7 +99,7 @@ public class PropertyNameResolver return properties.get(propName).get(klass); } - class QpidProperty + static class QpidProperty { private Object defValue; private String[] names; diff --git a/qpid/java/common/src/main/java/org/apache/mina/transport/socket/nio/MultiThreadSocketConnector.java b/qpid/java/common/src/main/java/org/apache/mina/transport/socket/nio/MultiThreadSocketConnector.java index b1612840db..7344f70078 100644 --- a/qpid/java/common/src/main/java/org/apache/mina/transport/socket/nio/MultiThreadSocketConnector.java +++ b/qpid/java/common/src/main/java/org/apache/mina/transport/socket/nio/MultiThreadSocketConnector.java @@ -56,7 +56,7 @@ public class MultiThreadSocketConnector extends SocketConnector private final Object lock = new Object(); private final int id = nextId++; private final String threadName = "SocketConnector-" + id; - private SocketConnectorConfig defaultConfig = new SocketConnectorConfig(); + private final Queue connectQueue = new Queue(); private final MultiThreadSocketIoProcessor[] ioProcessors; private final int processorCount; diff --git a/qpid/java/common/src/main/java/org/apache/qpid/QpidConfig.java b/qpid/java/common/src/main/java/org/apache/qpid/QpidConfig.java index 9c8019f109..b4cad44130 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/QpidConfig.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/QpidConfig.java @@ -65,7 +65,7 @@ public class QpidConfig return saslClientFactories; } - public class SecurityMechanism + public static class SecurityMechanism { String type; String handler; @@ -87,7 +87,7 @@ public class QpidConfig } } - public class SaslClientFactory + public static class SaslClientFactory { String type; String factoryClass; diff --git a/qpid/java/common/src/main/java/org/apache/qpid/ToyBroker.java b/qpid/java/common/src/main/java/org/apache/qpid/ToyBroker.java index db84b83adb..5423bbb68f 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/ToyBroker.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/ToyBroker.java @@ -107,6 +107,7 @@ class ToyBroker extends SessionDelegate { System.out.println("received headers routing_key " + props.getRoutingKey()); } + MessageProperties mp = header.get(MessageProperties.class); System.out.println("MP: " + mp); if (mp != null) @@ -114,7 +115,7 @@ class ToyBroker extends SessionDelegate System.out.println(mp.getApplicationHeaders()); } - if (exchange.route(dest,props.getRoutingKey(),xfr)) + if (exchange.route(dest,props == null ? null : props.getRoutingKey(),xfr)) { System.out.println("queued " + xfr); dispatchMessages(ssn); @@ -165,21 +166,40 @@ class ToyBroker extends SessionDelegate // ugly, but who cares :) // assumes unit is always no of messages, not bytes // assumes it's credit mode and not window - private class Consumer + private static class Consumer { long _credit; String _queueName; } + private static final class ToyBrokerSession extends Session + { + + public ToyBrokerSession(Connection connection, Binary name, long expiry, ToyExchange exchange) + { + super(connection, new ToyBroker(exchange), name, expiry); + } + } + public static final void main(String[] args) throws IOException { final ToyExchange exchange = new ToyExchange(); ConnectionDelegate delegate = new ServerDelegate() { - public SessionDelegate getSessionDelegate() + @Override + public void init(Connection conn, ProtocolHeader hdr) { - return new ToyBroker(exchange); + conn.setSessionFactory(new Connection.SessionFactory() + { + public Session newSession(Connection conn, Binary name, long expiry) + { + return new ToyBrokerSession(conn, name, expiry, exchange); + } + }); + + super.init(conn, hdr); //To change body of overridden methods use File | Settings | File Templates. } + }; MinaHandler.accept("0.0.0.0", 5672, delegate); diff --git a/qpid/java/common/src/main/java/org/apache/qpid/configuration/Accessor.java b/qpid/java/common/src/main/java/org/apache/qpid/configuration/Accessor.java index c9d386607d..dc5b69dc89 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/configuration/Accessor.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/configuration/Accessor.java @@ -152,7 +152,15 @@ public interface Accessor { super(null); Properties props = new Properties(); - props.load(new FileInputStream(fileName)); + FileInputStream inStream = new FileInputStream(fileName); + try + { + props.load(inStream); + } + finally + { + inStream.close(); + } source = props; } } diff --git a/qpid/java/common/src/main/java/org/apache/qpid/dtx/XidImpl.java b/qpid/java/common/src/main/java/org/apache/qpid/dtx/XidImpl.java index 69ccef7c29..69457ca4a9 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/dtx/XidImpl.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/dtx/XidImpl.java @@ -24,6 +24,7 @@ import org.apache.qpid.AMQInvalidArgumentException; import javax.transaction.xa.Xid; import java.io.*; +import java.util.Arrays; /** * Implements javax.transaction.dtx.Xid @@ -217,6 +218,15 @@ public class XidImpl implements Xid return false; } + @Override + public int hashCode() + { + int result = _branchQualifier != null ? Arrays.hashCode(_branchQualifier) : 0; + result = 31 * result + _formatID; + result = 31 * result + (_globalTransactionID != null ? Arrays.hashCode(_globalTransactionID) : 0); + return result; + } + //-- Static helper method /** * Convert an Xid into the AMQP String format. diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypeMap.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypeMap.java index a16e137466..a07fd78c8c 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypeMap.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypeMap.java @@ -25,7 +25,7 @@ import java.util.Map; public class AMQTypeMap { - public static Map<Byte, AMQType> _reverseTypeMap = new HashMap<Byte, AMQType>(); + public static final Map<Byte, AMQType> _reverseTypeMap = new HashMap<Byte, AMQType>(); static { diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java index 15a43345b5..18ab05ffa1 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java @@ -27,7 +27,7 @@ import org.apache.qpid.AMQException; public class HeartbeatBody implements AMQBody { public static final byte TYPE = 8; - public static AMQFrame FRAME = new HeartbeatBody().toFrame(); + public static final AMQFrame FRAME = new HeartbeatBody().toFrame(); public HeartbeatBody() { diff --git a/qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java b/qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java index ac21fe4243..fb3dd89717 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java @@ -24,12 +24,13 @@ import org.apache.qpid.AMQException; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.util.Arrays; public class ProtocolInitiation extends AMQDataBlock implements EncodableAMQDataBlock { // TODO: generate these constants automatically from the xml protocol spec file - public static final byte[] AMQP_HEADER = new byte[]{(byte)'A',(byte)'M',(byte)'Q',(byte)'P'}; + private static final byte[] AMQP_HEADER = new byte[]{(byte)'A',(byte)'M',(byte)'Q',(byte)'P'}; private static final byte CURRENT_PROTOCOL_CLASS = 1; private static final byte TCP_PROTOCOL_INSTANCE = 1; @@ -124,6 +125,17 @@ public class ProtocolInitiation extends AMQDataBlock implements EncodableAMQData _protocolMinor == pi._protocolMinor); } + @Override + public int hashCode() + { + int result = _protocolHeader != null ? Arrays.hashCode(_protocolHeader) : 0; + result = 31 * result + (int) _protocolClass; + result = 31 * result + (int) _protocolInstance; + result = 31 * result + (int) _protocolMajor; + result = 31 * result + (int) _protocolMinor; + return result; + } + public static class Decoder //implements MessageDecoder { /** diff --git a/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/Lexicon.java b/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/Lexicon.java index c09eb7ef84..9ab610f37a 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/Lexicon.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/messaging/util/Lexicon.java @@ -58,30 +58,30 @@ public class Lexicon public Lexer compile() { - String joined = ""; + StringBuilder joined = new StringBuilder(); for (Token.Type t : types) { if (joined.length() > 0) { - joined += "|"; + joined.append('|'); } - joined += "(" + t.getPattern() + ")"; + joined.append('(').append(t.getPattern()).append(')'); } - Pattern rexp = Pattern.compile(joined); + Pattern rexp = Pattern.compile(joined.toString()); return new Lexer(new ArrayList<Token.Type>(types), eof, rexp); } public static final void main(String[] args) { - String input = ""; + StringBuilder input = new StringBuilder(); for (String a : args) { if (input.length() > 0) { - input += " "; + input.append(" "); } - input += a; + input.append(a); } Lexicon lxi = new Lexicon(); @@ -94,7 +94,7 @@ public class Lexicon lxi.eof("EOF"); Lexer lx = lxi.compile(); - for (Token t : lx.lex(input)) + for (Token t : lx.lex(input.toString())) { System.out.println(t); } diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java index d5f97f48a8..82fb57eb7d 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/ClientDelegate.java @@ -52,14 +52,21 @@ public class ClientDelegate extends ConnectionDelegate private static final Logger log = Logger.get(ClientDelegate.class); private static final String KRB5_OID_STR = "1.2.840.113554.1.2.2"; - protected static Oid KRB5_OID; + protected static final Oid KRB5_OID; static { + Oid oid; try { - KRB5_OID = new Oid(KRB5_OID_STR); - } catch (GSSException ignore) {} + oid = new Oid(KRB5_OID_STR); + } + catch (GSSException ignore) + { + oid = null; + } + + KRB5_OID = oid; } private List<String> clientMechs; diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/Connection.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/Connection.java index 13b8e461d4..3c56aa22bd 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/transport/Connection.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/Connection.java @@ -61,7 +61,7 @@ public class Connection extends ConnectionInvoker public enum State { NEW, CLOSED, OPENING, OPEN, CLOSING, CLOSE_RCVD } - class DefaultConnectionListener implements ConnectionListener + static class DefaultConnectionListener implements ConnectionListener { public void opened(Connection conn) {} public void exception(Connection conn, ConnectionException exception) diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java index e989849477..52e0026f29 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/Session.java @@ -60,7 +60,7 @@ public class Session extends SessionInvoker enum State { NEW, DETACHED, RESUMING, OPEN, CLOSING, CLOSED } - class DefaultSessionListener implements SessionListener + static class DefaultSessionListener implements SessionListener { public void opened(Session ssn) {} diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/TransportBuilder.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/TransportBuilder.java index d1ae95a3bb..c08909c6e4 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/transport/TransportBuilder.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/TransportBuilder.java @@ -61,8 +61,6 @@ public class TransportBuilder public void buildReceiverPipe(Receiver<ProtocolEvent> delegate) { - ConnectionSettings settings = con.getConnectionSettings(); - Receiver<ByteBuffer> receiver = new InputHandler(new Assembler(delegate)); // Security layer diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/sasl/SASLReceiver.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/sasl/SASLReceiver.java index a9e8566d01..86106318ef 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/sasl/SASLReceiver.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/sasl/SASLReceiver.java @@ -41,20 +41,18 @@ public class SASLReceiver extends SASLEncryptor implements Receiver<ByteBuffer> this.delegate = delegate; } - @Override public void closed() { delegate.closed(); } - @Override + public void exception(Throwable t) { - delegate.equals(t); + delegate.exception(t); } - @Override - public void received(ByteBuffer buf) + public void received(ByteBuffer buf) { if (isSecurityLayerEstablished()) { diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLSender.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLSender.java index 3c2ad061f3..cd47a11825 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLSender.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLSender.java @@ -82,9 +82,10 @@ public class SSLSender implements Sender<ByteBuffer> throw new SenderException("Error closing SSL connection",e); } - while (!engine.isOutboundDone()) + + synchronized(engineState) { - synchronized(engineState) + while (!engine.isOutboundDone()) { try { @@ -94,6 +95,7 @@ public class SSLSender implements Sender<ByteBuffer> { // pass } + } } delegate.close(); diff --git a/qpid/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java b/qpid/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java index 998242925c..26cb56ea97 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/url/AMQBindingURL.java @@ -55,7 +55,8 @@ public class AMQBindingURL implements BindingURL private void parseBindingURL() throws URISyntaxException { - BindingURLParser parser = new BindingURLParser(_url,this); + BindingURLParser parser = new BindingURLParser(); + parser.parse(_url,this); processOptions(); _logger.debug("URL Parsed: " + this); } diff --git a/qpid/java/common/src/main/java/org/apache/qpid/url/BindingURLParser.java b/qpid/java/common/src/main/java/org/apache/qpid/url/BindingURLParser.java index 7fe7d2e1da..0ebfe0e869 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/url/BindingURLParser.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/url/BindingURLParser.java @@ -52,15 +52,24 @@ public class BindingURLParser private String _error; private int _index = 0; private String _currentPropName; - private Map<String,Object> _options = new HashMap<String,Object>(); + private Map<String,Object> _options; + + + public BindingURLParser() + { + } //<exch_class>://<exch_name>/[<destination>]/[<queue>]?<option>='<value>'[,<option>='<value>']* - public BindingURLParser(String url,AMQBindingURL bindingURL) throws URISyntaxException + public synchronized void parse(String url,AMQBindingURL bindingURL) throws URISyntaxException { _url = (url + END_OF_URL_MARKER_CHAR).toCharArray(); _bindingURL = bindingURL; _currentParserState = BindingURLParserState.BINDING_URL_START; BindingURLParserState prevState = _currentParserState; + _index = 0; + _currentPropName = null; + _error = null; + _options = new HashMap<String,Object>(); try { @@ -432,6 +441,7 @@ public class BindingURLParser public static void main(String[] args) { + String[] urls = new String[] { "topic://amq.topic//myTopic?routingkey='stocks.#'", @@ -447,11 +457,13 @@ public class BindingURLParser try { + BindingURLParser parser = new BindingURLParser(); + for (String url: urls) { System.out.println("URL " + url); AMQBindingURL bindingURL = new AMQBindingURL(url); - BindingURLParser parser = new BindingURLParser(url,bindingURL); + parser.parse(url,bindingURL); System.out.println("\nX " + bindingURL.toString() + " \n"); } diff --git a/qpid/java/common/src/main/java/org/apache/qpid/url/URLHelper.java b/qpid/java/common/src/main/java/org/apache/qpid/url/URLHelper.java index 2d496d2d54..6f21c327e7 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/url/URLHelper.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/url/URLHelper.java @@ -25,9 +25,9 @@ import java.util.Map; public class URLHelper { - public static char DEFAULT_OPTION_SEPERATOR = '&'; - public static char ALTERNATIVE_OPTION_SEPARATOR = ','; - public static char BROKER_SEPARATOR = ';'; + public static final char DEFAULT_OPTION_SEPERATOR = '&'; + public static final char ALTERNATIVE_OPTION_SEPARATOR = ','; + public static final char BROKER_SEPARATOR = ';'; public static void parseOptions(Map<String, String> optionMap, String options) throws URLSyntaxException { diff --git a/qpid/java/common/src/main/java/org/apache/qpid/util/CommandLineParser.java b/qpid/java/common/src/main/java/org/apache/qpid/util/CommandLineParser.java index 0281506037..09478d4157 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/util/CommandLineParser.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/util/CommandLineParser.java @@ -160,14 +160,14 @@ public class CommandLineParser } // Concatenate all the parsing errors together. - String result = ""; + StringBuilder result = new StringBuilder(); for (String s : parsingErrors) { - result += s; + result.append(s); } - return result; + return result.toString(); } /** @@ -184,14 +184,17 @@ public class CommandLineParser } // List all the properties. - String result = "Options in force:\n"; + StringBuilder result = new StringBuilder("Options in force:\n"); for (Map.Entry<Object, Object> property : parsedProperties.entrySet()) { - result += property.getKey() + " = " + property.getValue() + "\n"; + result.append(property.getKey()) + .append(" = ") + .append(property.getValue()) + .append('\n'); } - return result; + return result.toString(); } /** @@ -257,7 +260,7 @@ public class CommandLineParser boolean ignore = false; // Create the regular expression matcher for the command line options. - String regexp = "^("; + StringBuilder regexp = new StringBuilder("^("); int optionsAdded = 0; for (Iterator<String> i = optionMap.keySet().iterator(); i.hasNext();) @@ -279,15 +282,18 @@ public class CommandLineParser // Add the option to the regular expression matcher if it is not a free argument definition. if (notFree) { - regexp += nextOption + (i.hasNext() ? "|" : ""); + regexp.append(nextOption) + .append(i.hasNext() ? "|" : ""); optionsAdded++; } } // There has to be more that one option in the regular expression or else the compiler complains that the close // cannot be nullable if the '?' token is used to make the matched option string optional. - regexp += ")" + ((optionsAdded > 0) ? "?" : "") + "(.*)"; - Pattern pattern = Pattern.compile(regexp); + regexp.append(')') + .append(((optionsAdded > 0) ? "?" : "")) + .append("(.*)"); + Pattern pattern = Pattern.compile(regexp.toString()); // Loop through all the command line arguments. for (int i = 0; i < args.length; i++) @@ -645,7 +651,7 @@ public class CommandLineParser * <tr><td> Hold details of a command line option. * </table> */ - protected class CommandLineOption + protected static class CommandLineOption { /** Holds the text for the flag to match this argument with. */ public String option = null; diff --git a/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java index 7ba38f4743..fa26786ec4 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java @@ -215,23 +215,34 @@ public class FileUtils public static void copyCheckedEx(File src, File dst) throws IOException { InputStream in = new FileInputStream(src); - if (!dst.exists()) + try { - dst.createNewFile(); - } - - OutputStream out = new FileOutputStream(dst); + if (!dst.exists()) + { + dst.createNewFile(); + } - // Transfer bytes from in to out - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) + OutputStream out = new FileOutputStream(dst); + + try + { + // Transfer bytes from in to out + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) + { + out.write(buf, 0, len); + } + } + finally + { + out.close(); + } + } + finally { - out.write(buf, 0, len); + in.close(); } - - in.close(); - out.close(); } /* diff --git a/qpid/java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java b/qpid/java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java index 4677713dc9..93266f2486 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/util/PrettyPrintingUtils.java @@ -40,16 +40,16 @@ public class PrettyPrintingUtils */ public static String printArray(int[] array) { - String result = "["; + StringBuilder result = new StringBuilder("["); for (int i = 0; i < array.length; i++) { - result += array[i]; - result += (i < (array.length - 1)) ? ", " : ""; + result.append(array[i]) + .append((i < (array.length - 1)) ? ", " : ""); } - result += "]"; + result.append(']'); - return result; + return result.toString(); } /** diff --git a/qpid/java/common/templates/method/version/MethodBodyClass.vm b/qpid/java/common/templates/method/version/MethodBodyClass.vm index 9b2ba0fa39..a739110d70 100644 --- a/qpid/java/common/templates/method/version/MethodBodyClass.vm +++ b/qpid/java/common/templates/method/version/MethodBodyClass.vm @@ -70,9 +70,9 @@ public class ${javaClassName} extends AMQMethodBody_$version.getMajor()_$version return FACTORY_INSTANCE; } - public static int CLASS_ID = $clazz.ClassId; + public static final int CLASS_ID = $clazz.ClassId; - public static int METHOD_ID = $method.MethodId; + public static final int METHOD_ID = $method.MethodId; @@ -196,7 +196,11 @@ public class ${javaClassName} extends AMQMethodBody_$version.getMajor()_$version StringBuilder buf = new StringBuilder("[$javaClassName: "); #foreach( $field in $method.FieldList ) buf.append( "$field.Name=" ); - buf.append( get#toUpperCamel( $field.Name )() ); +#if( $field.NativeType == "byte[]" ) + buf.append( get#toUpperCamel( $field.Name )() == null ? "null" : java.util.Arrays.toString( get#toUpperCamel( $field.Name )() ) ); +#else + buf.append( get#toUpperCamel( $field.Name )() ); +#end #if( $velocityCount != $method.FieldList.size() ) buf.append( ", " ); #end diff --git a/qpid/java/junit-toolkit/src/main/org/apache/qpid/junit/extensions/AsymptoticTestDecorator.java b/qpid/java/junit-toolkit/src/main/org/apache/qpid/junit/extensions/AsymptoticTestDecorator.java index 4faa58688f..8869d25be3 100644 --- a/qpid/java/junit-toolkit/src/main/org/apache/qpid/junit/extensions/AsymptoticTestDecorator.java +++ b/qpid/java/junit-toolkit/src/main/org/apache/qpid/junit/extensions/AsymptoticTestDecorator.java @@ -136,24 +136,27 @@ public class AsymptoticTestDecorator extends WrappedSuiteTestDecorator log.debug("params = " + ((params == null) ? null : MathUtils.printArray(params))); log.debug("repeat = " + repeat); - for (int n : params) + if(params != null) { - for (int j = 0; j < repeat; j++) + for (int n : params) { - log.debug("n = " + n); + for (int j = 0; j < repeat; j++) + { + log.debug("n = " + n); - // Set the integer parameter in the TKTestResult to be passed to the tests. - tkResult.setN(n); + // Set the integer parameter in the TKTestResult to be passed to the tests. + tkResult.setN(n); - if (tkResult.shouldStop()) - { - log.debug("tkResult.shouldStop = " + true); + if (tkResult.shouldStop()) + { + log.debug("tkResult.shouldStop = " + true); - break; - } + break; + } - log.debug("Calling super#run"); - super.run(tkResult); + log.debug("Calling super#run"); + super.run(tkResult); + } } } } diff --git a/qpid/java/junit-toolkit/src/main/org/apache/qpid/junit/extensions/ParameterVariationTestDecorator.java b/qpid/java/junit-toolkit/src/main/org/apache/qpid/junit/extensions/ParameterVariationTestDecorator.java index 2c207635c7..7da4667928 100644 --- a/qpid/java/junit-toolkit/src/main/org/apache/qpid/junit/extensions/ParameterVariationTestDecorator.java +++ b/qpid/java/junit-toolkit/src/main/org/apache/qpid/junit/extensions/ParameterVariationTestDecorator.java @@ -138,24 +138,27 @@ public class ParameterVariationTestDecorator extends WrappedSuiteTestDecorator log.debug("params = " + ((params == null) ? null : MathUtils.printArray(params))); log.debug("repeat = " + repeat); - for (int n : params) + if(params != null) { - for (int j = 0; j < repeat; j++) + for (int n : params) { - log.debug("n = " + n); + for (int j = 0; j < repeat; j++) + { + log.debug("n = " + n); - // Set the integer parameter in the TKTestResult to be passed to the tests. - tkResult.setN(n); + // Set the integer parameter in the TKTestResult to be passed to the tests. + tkResult.setN(n); - if (tkResult.shouldStop()) - { - log.debug("tkResult.shouldStop = " + true); + if (tkResult.shouldStop()) + { + log.debug("tkResult.shouldStop = " + true); - break; - } + break; + } - log.debug("Calling super#run"); - super.run(tkResult); + log.debug("Calling super#run"); + super.run(tkResult); + } } } } diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java index d3ce711d5d..b60867d9ff 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java @@ -28,39 +28,39 @@ import javax.xml.namespace.QName; */ public abstract class Names { - public static String MANAGEMENT_EXCHANGE = "qpid.management"; - public static String MANAGEMENT_ROUTING_KEY = "console.#"; + public static final String MANAGEMENT_EXCHANGE = "qpid.management"; + public static final String MANAGEMENT_ROUTING_KEY = "console.#"; - public static String MANAGEMENT_QUEUE_PREFIX = "management."; - public static String METHOD_REPLY_QUEUE_PREFIX = "reply."; + public static final String MANAGEMENT_QUEUE_PREFIX = "management."; + public static final String METHOD_REPLY_QUEUE_PREFIX = "reply."; - public static String AMQ_DIRECT_QUEUE = "amq.direct"; - public static String AGENT_ROUTING_KEY_PREFIX = "agent."; - public static String AGENT_ROUTING_KEY = AGENT_ROUTING_KEY_PREFIX+"1.0"; + public static final String AMQ_DIRECT_QUEUE = "amq.direct"; + public static final String AGENT_ROUTING_KEY_PREFIX = "agent."; + public static final String AGENT_ROUTING_KEY = AGENT_ROUTING_KEY_PREFIX+"1.0"; - public static String APPLICATION_NAME ="Q-Man"; + public static final String APPLICATION_NAME ="Q-Man"; // Attributes - public static String PACKAGE = "package"; - public static String CLASS = "class"; - public static String EVENT = "event"; - public static String OBJECT_ID="objectId"; - public static String BROKER_ID = "brokerId"; - public static String DOMAIN_NAME = "Q-MAN"; + public static final String PACKAGE = "package"; + public static final String CLASS = "class"; + public static final String EVENT = "event"; + public static final String OBJECT_ID="objectId"; + public static final String BROKER_ID = "brokerId"; + public static final String DOMAIN_NAME = "Q-MAN"; - public static String ARG_COUNT_PARAM_NAME = "argCount"; - public static String DEFAULT_PARAM_NAME ="default"; + public static final String ARG_COUNT_PARAM_NAME = "argCount"; + public static final String DEFAULT_PARAM_NAME ="default"; - public static String NUMBER_VALIDATOR = "org.apache.qpid.management.domain.model.QpidProperty$NumberValidator"; - public static String STRING_VALIDATOR = "org.apache.qpid.management.domain.model.QpidProperty$StringValidator"; + public static final String NUMBER_VALIDATOR = "org.apache.qpid.management.domain.model.QpidProperty$NumberValidator"; + public static final String STRING_VALIDATOR = "org.apache.qpid.management.domain.model.QpidProperty$StringValidator"; - public static String QMAN_CONFIG_OPTION_NAME = "qman-config"; + public static final String QMAN_CONFIG_OPTION_NAME = "qman-config"; - public static String ADD_BROKER_OPERATION_NAME = "addBroker"; + public static final String ADD_BROKER_OPERATION_NAME = "addBroker"; - public static String NOT_AVAILABLE = "N.A."; + public static final String NOT_AVAILABLE = "N.A."; - public static ObjectName QPID_EMULATOR_OBJECT_NAME; + public static final ObjectName QPID_EMULATOR_OBJECT_NAME; static { try @@ -77,7 +77,7 @@ public abstract class Names } } - public static ObjectName QMAN_OBJECT_NAME; + public static final ObjectName QMAN_OBJECT_NAME; static { try @@ -95,11 +95,11 @@ public abstract class Names } // WSDM Stuff - public static String NAMESPACE_URI = "http://amqp.apache.org/qpid/management/qman"; + public static final String NAMESPACE_URI = "http://amqp.apache.org/qpid/management/qman"; public final static String PREFIX = "qman"; - public static String ADDRESSING_URI = "http://amqp.apache.org/qpid/management/qman/addressing"; - public static String ADDRESSING_PREFIX = "qman-wsa"; + public static final String ADDRESSING_URI = "http://amqp.apache.org/qpid/management/qman/addressing"; + public static final String ADDRESSING_PREFIX = "qman-wsa"; public static final QName RESOURCE_ID_QNAME = new QName( ADDRESSING_URI, diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java index b796620747..a64659b17c 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java @@ -251,16 +251,26 @@ public class BrokerConnectionData } @Override - public boolean equals(Object object) { - try - { - BrokerConnectionData connectionData = (BrokerConnectionData) object; - return (_host.equals(connectionData._host) ) - && (_port == connectionData._port) - && (_virtualHost.equals(connectionData._virtualHost)); - } catch (Exception exception) { - return false; - } + public boolean equals(Object object) + { + if(object instanceof BrokerConnectionData) + { + try + { + BrokerConnectionData connectionData = (BrokerConnectionData) object; + return (_host.equals(connectionData._host) ) + && (_port == connectionData._port) + && (_virtualHost.equals(connectionData._virtualHost)); + } + catch (Exception exception) + { + return false; + } + } + else + { + return false; + } } @Override diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java index 51dc62f4fa..ab90ec294b 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/Configuration.java @@ -88,10 +88,6 @@ public final class Configuration addTypeMappings(); } - void clean() - { - INSTANCE = new Configuration(); - } /** * Returns the singleton instance. diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/WorkerManagerConfigurationParser.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/WorkerManagerConfigurationParser.java index b99f272053..4e68b54b12 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/WorkerManagerConfigurationParser.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/WorkerManagerConfigurationParser.java @@ -71,6 +71,7 @@ class WorkerManagerConfigurationParser implements IParser case MAX_POOL_CAPACITY : { _maxPoolSizeAsString = _currentValue; + break; } case KEEP_ALIVE_TIME: { diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidPackage.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidPackage.java index e9799cb147..c25a5d7d1c 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidPackage.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/QpidPackage.java @@ -71,8 +71,15 @@ final class QpidPackage @Override public boolean equals (Object obj) { - QpidClassIdentity identity = (QpidClassIdentity) obj; - return name.equals(identity.name) && hash.equals(identity.hash); + if(obj instanceof QpidClassIdentity) + { + QpidClassIdentity identity = (QpidClassIdentity) obj; + return name.equals(identity.name) && hash.equals(identity.hash); + } + else + { + return false; + } } } diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Binary.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Binary.java index 343280ca4b..95cb03b04b 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Binary.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Binary.java @@ -102,11 +102,18 @@ public final class Binary implements Serializable @Override public boolean equals (Object obj) { - try + if(obj instanceof Binary) { - Binary binary = (Binary)obj; - return Arrays.equals(_bytes, binary._bytes); - } catch (Exception exception) + try + { + Binary binary = (Binary)obj; + return Arrays.equals(_bytes, binary._bytes); + } catch (Exception exception) + { + return false; + } + } + else { return false; } diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Type.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Type.java index c455faaf2c..7f92ec82b0 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Type.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/model/type/Type.java @@ -82,13 +82,13 @@ public abstract class Type @Override public boolean equals (Object obj) { - return getClass() == obj.getClass(); + return (obj instanceof Type) && getJavaType() == ((Type)obj).getJavaType(); } @Override public int hashCode () { - return getClass().hashCode(); + return getJavaType().hashCode(); } /** diff --git a/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedQueue.java b/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedQueue.java index 20e97adf8c..7d61d32f71 100644 --- a/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedQueue.java +++ b/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedQueue.java @@ -21,6 +21,7 @@ package org.apache.qpid.management.common.mbeans; import java.io.IOException; +import java.util.*; import javax.management.JMException; import javax.management.MBeanOperationInfo; @@ -54,45 +55,48 @@ public interface ManagedQueue String[] VIEW_MSG_CONTENT_COMPOSITE_ITEM_DESCRIPTIONS = { "AMQ MessageId", "MimeType", "Encoding", "Content" }; //Individual attribute name constants - String ATTR_NAME = "Name"; - String ATTR_OWNER = "Owner"; - String ATTR_MAX_MSG_AGE = "MaximumMessageAge"; - String ATTR_MAX_MSG_COUNT = "MaximumMessageCount"; - String ATTR_MAX_QUEUE_DEPTH = "MaximumQueueDepth"; - String ATTR_MAX_MSG_SIZE = "MaximumMessageSize"; - String ATTR_DURABLE = "Durable"; - String ATTR_AUTODELETE = "AutoDelete"; - String ATTR_CONSUMER_COUNT = "ConsumerCount"; - String ATTR_ACTIVE_CONSUMER_COUNT = "ActiveConsumerCount"; - String ATTR_MSG_COUNT = "MessageCount"; - String ATTR_QUEUE_DEPTH = "QueueDepth"; - String ATTR_RCVD_MSG_COUNT = "ReceivedMessageCount"; - String ATTR_CAPACITY = "Capacity"; - String ATTR_FLOW_OVERFULL = "FlowOverfull"; - String ATTR_FLOW_RESUME_CAPACITY = "FlowResumeCapacity"; - String ATTR_EXCLUSIVE = "Exclusive"; + static final String ATTR_NAME = "Name"; + static final String ATTR_OWNER = "Owner"; + static final String ATTR_MAX_MSG_AGE = "MaximumMessageAge"; + static final String ATTR_MAX_MSG_COUNT = "MaximumMessageCount"; + static final String ATTR_MAX_QUEUE_DEPTH = "MaximumQueueDepth"; + static final String ATTR_MAX_MSG_SIZE = "MaximumMessageSize"; + static final String ATTR_DURABLE = "Durable"; + static final String ATTR_AUTODELETE = "AutoDelete"; + static final String ATTR_CONSUMER_COUNT = "ConsumerCount"; + static final String ATTR_ACTIVE_CONSUMER_COUNT = "ActiveConsumerCount"; + static final String ATTR_MSG_COUNT = "MessageCount"; + static final String ATTR_QUEUE_DEPTH = "QueueDepth"; + static final String ATTR_RCVD_MSG_COUNT = "ReceivedMessageCount"; + static final String ATTR_CAPACITY = "Capacity"; + static final String ATTR_FLOW_OVERFULL = "FlowOverfull"; + static final String ATTR_FLOW_RESUME_CAPACITY = "FlowResumeCapacity"; + static final String ATTR_EXCLUSIVE = "Exclusive"; //All attribute names constant - String[] QUEUE_ATTRIBUTES = new String[]{ - ATTR_NAME, - ATTR_OWNER, - ATTR_MAX_MSG_AGE, - ATTR_MAX_MSG_COUNT, - ATTR_MAX_QUEUE_DEPTH, - ATTR_MAX_MSG_SIZE, - ATTR_DURABLE, - ATTR_AUTODELETE, - ATTR_CONSUMER_COUNT, - ATTR_ACTIVE_CONSUMER_COUNT, - ATTR_MSG_COUNT, - ATTR_QUEUE_DEPTH, - ATTR_RCVD_MSG_COUNT, - ATTR_CAPACITY, - ATTR_FLOW_OVERFULL, - ATTR_FLOW_RESUME_CAPACITY, - ATTR_EXCLUSIVE - }; - + static final List<String> QUEUE_ATTRIBUTES + = Collections.unmodifiableList( + new ArrayList<String>( + new HashSet<String>( + Arrays.asList( + ATTR_NAME, + ATTR_OWNER, + ATTR_MAX_MSG_AGE, + ATTR_MAX_MSG_COUNT, + ATTR_MAX_QUEUE_DEPTH, + ATTR_MAX_MSG_SIZE, + ATTR_DURABLE, + ATTR_AUTODELETE, + ATTR_CONSUMER_COUNT, + ATTR_ACTIVE_CONSUMER_COUNT, + ATTR_MSG_COUNT, + ATTR_QUEUE_DEPTH, + ATTR_RCVD_MSG_COUNT, + ATTR_CAPACITY, + ATTR_FLOW_OVERFULL, + ATTR_FLOW_RESUME_CAPACITY, + ATTR_EXCLUSIVE)))); + /** * Returns the Name of the ManagedQueue. * @return the name of the managedQueue. diff --git a/qpid/java/management/common/src/test/java/org/apache/qpid/management/common/mbeans/ManagedQueueTest.java b/qpid/java/management/common/src/test/java/org/apache/qpid/management/common/mbeans/ManagedQueueTest.java index f449ecb7e5..1a4a73f207 100644 --- a/qpid/java/management/common/src/test/java/org/apache/qpid/management/common/mbeans/ManagedQueueTest.java +++ b/qpid/java/management/common/src/test/java/org/apache/qpid/management/common/mbeans/ManagedQueueTest.java @@ -48,12 +48,8 @@ public class ManagedQueueTest extends TestCase { StandardMBean mbean = new StandardMBean(impl, ManagedQueue.class); - List<String> attributeList = new ArrayList<String>(); - for(String attr : ManagedQueue.QUEUE_ATTRIBUTES) - { - attributeList.add(attr); - } - + List<String> attributeList = ManagedQueue.QUEUE_ATTRIBUTES; + //retrieve the attributes from the constructed MBeanInfo MBeanAttributeInfo[] attributes = mbean.getMBeanInfo().getAttributes(); diff --git a/qpid/java/management/console/src/main/java/org/apache/qpid/console/Session.java b/qpid/java/management/console/src/main/java/org/apache/qpid/console/Session.java index 822f215f4d..3bbc8ecdad 100644 --- a/qpid/java/management/console/src/main/java/org/apache/qpid/console/Session.java +++ b/qpid/java/management/console/src/main/java/org/apache/qpid/console/Session.java @@ -477,7 +477,7 @@ public class Session Object sClass = args.get("_schema");
Object oid = args.get("_objectID");
long[] hash = (long[]) args.get("_hash");
- if ((className == null) && (oid == null) && (oid == null))
+ if ((className == null) && (oid == null))
{
throw new ConsoleException(
"No class supplied, use '_schema', '_key', '_class', or '_objectId' argument");
diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java index fc17538cf9..c3c0277f7d 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ServerRegistry.java @@ -135,7 +135,7 @@ public abstract class ServerRegistry protected void removeVirtualHostManagerMBean(ManagedBean mbean) { - _vhostManagers.remove(mbean); + _vhostManagers.remove(mbean.getVirtualHostName()); } public ManagedBean getVirtualHostManagerMBean(String virtualHost) diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java index 655718c098..d95ca8b2e4 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java @@ -271,7 +271,7 @@ public class ViewUtility List objectData = (List)compositeHolder.getData(); if (objectData == null || objectData.isEmpty()) { - // TODO + // TODO } // Get the index of record to be shown. diff --git a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/QueueTypeTabControl.java b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/QueueTypeTabControl.java index c5ab5184ee..285dcfc0ee 100644 --- a/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/QueueTypeTabControl.java +++ b/qpid/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/type/QueueTypeTabControl.java @@ -650,7 +650,6 @@ public class QueueTypeTabControl extends MBeanTypeTabControl private class QueueLabelProviderImpl extends LabelProvider implements ITableLabelProvider { @SuppressWarnings("unchecked") - @Override public String getColumnText(Object element, int columnIndex) { List<Object> attributes = (List<Object>) element; @@ -677,8 +676,7 @@ public class QueueTypeTabControl extends MBeanTypeTabControl return String.valueOf(attributes.get(columnIndex)); } } - - @Override + public Image getColumnImage(Object element, int columnIndex) { return null; diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/ReportGenerator.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/ReportGenerator.java index cc8c16f8b0..9d14f78b42 100644 --- a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/ReportGenerator.java +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/ReportGenerator.java @@ -48,7 +48,7 @@ public class ReportGenerator implements Runnable generatereport(); try { - Thread.sleep(this.interval * 60000); + Thread.sleep((long)this.interval * 60000L); } catch (Exception ex) { diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandget.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandget.java index 8d690ac7f7..cb67edeb34 100644 --- a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandget.java +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandget.java @@ -34,7 +34,7 @@ public class Commandget extends CommandImpl private String _attributeName; private String _value; - public static String COMMAND_NAME = "get"; + public static final String COMMAND_NAME = "get"; public Commandget(JMXinfo info) { diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandset.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandset.java index b5cc9e6090..e70b7b17ad 100644 --- a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandset.java +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandset.java @@ -34,7 +34,7 @@ public class Commandset extends CommandImpl { private String _attributeName; private String _value; - public static String COMMAND_NAME = "set"; + public static final String COMMAND_NAME = "set"; public Commandset(JMXinfo info) { diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandview.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandview.java index e98cb336d8..e3bcc7e543 100644 --- a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandview.java +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandview.java @@ -58,10 +58,8 @@ public class Commandview extends CommandImpl public void viewmessages() { - Set set = null; - Object temp[] = { null }; objname.setQueryString(this.getObject(), this.getName(), this.getVirtualhost()); - set = objname.returnObjects(); + Set set = objname.returnObjects(); String header = "", temp_header = "", message_data = "", outline = ""; if (objname.getSet().size() != 0) diff --git a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandviewcontent.java b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandviewcontent.java index 0c8a4b62b4..d1ae1c1893 100644 --- a/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandviewcontent.java +++ b/qpid/java/management/tools/qpid-cli/src/org/apache/qpid/commands/Commandviewcontent.java @@ -56,10 +56,8 @@ public class Commandviewcontent extends CommandImpl public void viewcontent() { - Set set = null; - Object temp[] = { null }; objname.setQueryString(getObject(), getName(), getVirtualhost()); - set = objname.returnObjects(); + Set set = objname.returnObjects(); String temp_header = "", header = "", message_data = "", encoding = null; if (objname.getSet().size() != 0) diff --git a/qpid/java/perftests/src/main/java/org/apache/qpid/ping/PingSendOnlyClient.java b/qpid/java/perftests/src/main/java/org/apache/qpid/ping/PingSendOnlyClient.java index 04e723069a..2fe852af77 100644 --- a/qpid/java/perftests/src/main/java/org/apache/qpid/ping/PingSendOnlyClient.java +++ b/qpid/java/perftests/src/main/java/org/apache/qpid/ping/PingSendOnlyClient.java @@ -67,7 +67,7 @@ public class PingSendOnlyClient extends PingDurableClient // pingProducer.getConnection().setExceptionListener(pingProducer); // Run the test procedure. - int sent = pingProducer.send(); + pingProducer.send(); pingProducer.waitForUser("Press return to close connection and quit."); pingProducer.closeConnection(); diff --git a/qpid/java/perftests/src/main/java/org/apache/qpid/test/testcases/MessageThroughputPerf.java b/qpid/java/perftests/src/main/java/org/apache/qpid/test/testcases/MessageThroughputPerf.java index dfb82b9b2d..e2e97ab6f8 100644 --- a/qpid/java/perftests/src/main/java/org/apache/qpid/test/testcases/MessageThroughputPerf.java +++ b/qpid/java/perftests/src/main/java/org/apache/qpid/test/testcases/MessageThroughputPerf.java @@ -126,7 +126,7 @@ public class MessageThroughputPerf extends FrameworkBaseCase implements TimingCo { NDC.push(getName()); - testProps = TestContextProperties.getInstance(MessagingTestConfigProperties.defaults); + setTestProps(TestContextProperties.getInstance(MessagingTestConfigProperties.defaults)); } /** @@ -143,7 +143,7 @@ public class MessageThroughputPerf extends FrameworkBaseCase implements TimingCo public void threadSetUp() { // Run the test setup tasks. This may create an in-vm broker, if a decorator has injected a task for this. - taskHandler.runSetupTasks(); + getTaskHandler().runSetupTasks(); // Get the test parameters, any overrides on the command line will have been applied. ParsedProperties testProps = TestContextProperties.getInstance(MessagingTestConfigProperties.defaults); @@ -178,7 +178,7 @@ public class MessageThroughputPerf extends FrameworkBaseCase implements TimingCo public void threadTearDown() { // Run the test teardown tasks. This may destroy the in-vm broker, if a decorator has injected a task for this. - taskHandler.runSetupTasks(); + getTaskHandler().runSetupTasks(); } /** diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/client/DispatcherTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/client/DispatcherTest.java index 98517d0687..a8a23c2c41 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/client/DispatcherTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/client/DispatcherTest.java @@ -77,10 +77,6 @@ public class DispatcherTest extends QpidBrokerTestCase { super.setUp(); - InitialContextFactory factory = new PropertiesFileInitialContextFactory(); - - Hashtable<String, String> env = new Hashtable<String, String>(); - // Create Client 1 _clientConnection = getConnection(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java index f66ee38139..7b59266eb3 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java @@ -71,17 +71,17 @@ public class AbstractTestLogging extends QpidBrokerTestCase @Override protected void createBroker() throws Exception { - _started = true; + setStarted(true); CurrentActor.set(new TestLogActor(new SystemOutMessageLogger())); // Prevent the InVM broker from logging and spoiling tests. _serverConfiguration.getConfig().setProperty(ServerConfiguration.STATUS_UPDATES, "off"); - _configuration = _serverConfiguration; - _registry = new TestApplicationRegistry(_configuration) + setConfiguration(_serverConfiguration); + setRegistry(new TestApplicationRegistry(getConfiguration()) { /** - * Create a virtualhost with a {@link SkeletonMessageStore} instead + * Create a virtualhost with a {@link org.apache.qpid.server.store.SkeletonMessageStore} instead * of the configured one, but remember the original configuration. */ @Override @@ -93,8 +93,8 @@ public class AbstractTestLogging extends QpidBrokerTestCase vhostConfig.setMessageStoreClass(oldClass); return host; } - }; - ApplicationRegistry.initialise(_registry); + }); + ApplicationRegistry.initialise(getRegistry()); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java index b2e35ea8d7..2629e82831 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AccessControlLoggingTest.java @@ -55,7 +55,7 @@ public class AccessControlLoggingTest extends AbstractTestLogging super.setUp(); } - /** FIXME This comes from {@link SimpleACLTest} and makes me suspicious. */ + /** FIXME This comes from SimpleACLTest and makes me suspicious. */ @Override public void tearDown() throws Exception { @@ -135,7 +135,7 @@ public class AccessControlLoggingTest extends AbstractTestLogging assertEquals("Should only be one ACL log message", 1, matches.size()); - String log = getLogMessage(matches, 0);; + String log = getLogMessage(matches, 0); String actor = fromActor(log); String subject = fromSubject(log); String message = getMessageString(fromMessage(log)); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/SimpleACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/SimpleACLTest.java index 28125f2f19..a50817e659 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/SimpleACLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/SimpleACLTest.java @@ -46,7 +46,7 @@ import org.apache.qpid.url.URLSyntaxException; * * These tests require an access control security plugin to be configured in the broker, and carry out various broker * operations that will succeed or fail depending on the user and virtual host. See the {@code config-systests-acl-setup.xml} - * configuration file for the {@link SimpleXML} version of the ACLs used by the Java broker only, or the various {@code .txt} + * configuration file for the SimpleXML version of the ACLs used by the Java broker only, or the various {@code .txt} * files in the system tests directory for the external version 3 ACL files used by both the Java and C++ brokers. * <p> * This class can be extended and the {@link #getConfig()} method overridden to run the same tests with a different type diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java index f9cf48a2b1..f54b022c09 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java @@ -265,8 +265,8 @@ public class QueueBrowserAutoAckTest extends FailoverBaseCase protected void checkOverlappingMultipleGetEnum(int expectedMessages, int browserEnumerationCount, String selector) throws JMSException { QueueBrowser queueBrowser = selector == null ? - _clientSession.createBrowser(_queue, selector) : - _clientSession.createBrowser(_queue); + _clientSession.createBrowser(_queue) : _clientSession.createBrowser(_queue); +// _clientSession.createBrowser(_queue) : _clientSession.createBrowser(_queue, selector); Enumeration[] msgs = new Enumeration[browserEnumerationCount]; int[] msgCount = new int[browserEnumerationCount]; diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java index 2fbac83eb4..fcbab273e5 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java @@ -306,7 +306,7 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener //Start the connection connection.start(); - long FAILOVER_DELAY = (RETRIES * DELAY); + long FAILOVER_DELAY = ((long)RETRIES * (long)DELAY); // Use Nano seconds as it is more accurate for comparision. long failTime = System.nanoTime() + FAILOVER_DELAY * 1000000; diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java index ddffc4cabf..f866cd572f 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java @@ -53,20 +53,15 @@ public class FrameworkBaseCase extends QpidBrokerTestCase implements FrameworkTe /** Used for debugging purposes. */ private static final Logger log = Logger.getLogger(FrameworkBaseCase.class); - /** Holds the test sequencer to create and run test circuits with. */ - protected CircuitFactory circuitFactory = new LocalAMQPCircuitFactory(); + private CircuitFactory circuitFactory = new LocalAMQPCircuitFactory(); - /** Used to read the tests configurable properties through. */ - protected ParsedProperties testProps; + private ParsedProperties testProps; - /** A default setup task processor to delegate setup tasks to. */ - protected SetupTaskHandler taskHandler = new SetupTaskHandler(); + private SetupTaskHandler taskHandler = new SetupTaskHandler(); - /** Flag used to track whether the test is in-vm or not. */ - protected boolean isUsingInVM; + private boolean isUsingInVM; - /** Holds the failure mechanism. */ - protected CauseFailure failureMechanism = new CauseFailureUserPrompt(); + private CauseFailure failureMechanism = new CauseFailureUserPrompt(); /** * Creates a new test case with the specified name. @@ -78,7 +73,7 @@ public class FrameworkBaseCase extends QpidBrokerTestCase implements FrameworkTe super(name); } - /** + /** Holds the test sequencer to create and run test circuits with. */ /** * Returns the test case sequencer that provides test circuit, and test sequence implementations. The sequencer * that this base case returns by default is suitable for running a test circuit with both circuit ends colocated * on the same JVM. @@ -283,4 +278,24 @@ public class FrameworkBaseCase extends QpidBrokerTestCase implements FrameworkTe { this.failureMechanism = failureMechanism; } + + protected ParsedProperties getTestProps() + { + return testProps; + } + + protected void setTestProps(ParsedProperties testProps) + { + this.testProps = testProps; + } + + protected SetupTaskHandler getTaskHandler() + { + return taskHandler; + } + + protected CauseFailure getFailureMechanism() + { + return failureMechanism; + } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/framework/LocalAMQPCircuitFactory.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/framework/LocalAMQPCircuitFactory.java index 7fbef06265..4c8f301d1c 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/framework/LocalAMQPCircuitFactory.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/framework/LocalAMQPCircuitFactory.java @@ -75,7 +75,7 @@ public class LocalAMQPCircuitFactory extends LocalCircuitFactory MessageProducer producer = props.getPublisherProducerBind() - ? ((props.getImmediate() | props.getMandatory()) + ? ((props.getImmediate() || props.getMandatory()) ? ((AMQSession) session).createProducer(destination, props.getMandatory(), props.getImmediate()) : session.createProducer(destination)) : null; diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/FailoverTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/FailoverTest.java index a0a8894874..a5a0d4e41f 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/FailoverTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/FailoverTest.java @@ -76,18 +76,18 @@ public class FailoverTest extends FrameworkBaseCase public void testTxP2PFailover() throws Exception { // Set up the test properties to match the test cases requirements. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); - testProps.setProperty(ACK_MODE_PROPNAME, Session.AUTO_ACKNOWLEDGE); - testProps.setProperty(PUBSUB_PROPNAME, false); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); + getTestProps().setProperty(ACK_MODE_PROPNAME, Session.AUTO_ACKNOWLEDGE); + getTestProps().setProperty(PUBSUB_PROPNAME, false); // MessagingTestConfigProperties props = this.getTestParameters(); // Create the test circuit from the test configuration parameters. CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); // Create an assertion that all messages are received. - Assertion allMessagesReceived = testCircuit.getReceiver().allMessagesReceivedAssertion(testProps); + Assertion allMessagesReceived = testCircuit.getReceiver().allMessagesReceivedAssertion(getTestProps()); // This test case assumes it is using a local circuit. LocalCircuitImpl localCircuit = (LocalCircuitImpl) testCircuit; @@ -105,7 +105,7 @@ public class FailoverTest extends FrameworkBaseCase // Cause a failover. if (i == 50) { - failureMechanism.causeFailure(); + getFailureMechanism().causeFailure(); } // Wait for the reconnection to complete. diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/ImmediateMessageTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/ImmediateMessageTest.java index 69aa6a52ae..3001211eae 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/ImmediateMessageTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/ImmediateMessageTest.java @@ -78,226 +78,226 @@ public class ImmediateMessageTest extends FrameworkBaseCase public void test_QPID_517_ImmediateOkNoTxP2P() throws Exception { // Ensure transactional sessions are off. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false); - testProps.setProperty(PUBSUB_PROPNAME, false); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, false); + getTestProps().setProperty(PUBSUB_PROPNAME, false); // Run the default test sequence over the test circuit checking for no errors. CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); - assertNoFailures(testCircuit.test(1, assertionList(testCircuit.getPublisher().noExceptionsAssertion(testProps)))); + assertNoFailures(testCircuit.test(1, assertionList(testCircuit.getPublisher().noExceptionsAssertion(getTestProps())))); } /** Check that an immediate message is committed succesfully in a transaction when a consumer is connected. */ public void test_QPID_517_ImmediateOkTxP2P() throws Exception { // Ensure transactional sessions are off. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); - testProps.setProperty(PUBSUB_PROPNAME, false); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); + getTestProps().setProperty(PUBSUB_PROPNAME, false); // Send one message with no errors. CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); - assertNoFailures(testCircuit.test(1, assertionList(testCircuit.getPublisher().noExceptionsAssertion(testProps)))); + assertNoFailures(testCircuit.test(1, assertionList(testCircuit.getPublisher().noExceptionsAssertion(getTestProps())))); } /** Check that an immediate message results in no consumers code, not using transactions, when a consumer is disconnected. */ public void test_QPID_517_ImmediateFailsConsumerDisconnectedNoTxP2P() throws Exception { // Ensure transactional sessions are off. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false); - testProps.setProperty(PUBSUB_PROPNAME, false); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, false); + getTestProps().setProperty(PUBSUB_PROPNAME, false); // Disconnect the consumer. - testProps.setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, false); + getTestProps().setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, false); CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); // Send one message and get a linked no consumers exception. assertNoFailures(testCircuit.test(1, - assertionList(((AMQPPublisher) testCircuit.getPublisher()).noConsumersAssertion(testProps)))); + assertionList(((AMQPPublisher) testCircuit.getPublisher()).noConsumersAssertion(getTestProps())))); } /** Check that an immediate message results in no consumers code, in a transaction, when a consumer is disconnected. */ public void test_QPID_517_ImmediateFailsConsumerDisconnectedTxP2P() throws Exception { // Ensure transactional sessions are on. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); - testProps.setProperty(PUBSUB_PROPNAME, false); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); + getTestProps().setProperty(PUBSUB_PROPNAME, false); // Disconnect the consumer. - testProps.setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, false); + getTestProps().setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, false); CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); // Send one message and get a linked no consumers exception. assertNoFailures(testCircuit.test(1, - assertionList(((AMQPPublisher) testCircuit.getPublisher()).noConsumersAssertion(testProps)))); + assertionList(((AMQPPublisher) testCircuit.getPublisher()).noConsumersAssertion(getTestProps())))); } /** Check that an immediate message results in no route code, not using transactions, when no outgoing route is connected. */ public void test_QPID_517_ImmediateFailsNoRouteNoTxP2P() throws Exception { // Ensure transactional sessions are off. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false); - testProps.setProperty(PUBSUB_PROPNAME, false); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, false); + getTestProps().setProperty(PUBSUB_PROPNAME, false); // Set up the messaging topology so that only the publishers producer is bound (do not set up the receivers to // collect its messages). - testProps.setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false); + getTestProps().setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false); // Send one message and get a linked no route exception. CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); assertNoFailures(testCircuit.test(1, - assertionList(((AMQPPublisher) testCircuit.getPublisher()).noRouteAssertion(testProps)))); + assertionList(((AMQPPublisher) testCircuit.getPublisher()).noRouteAssertion(getTestProps())))); } /** Check that an immediate message results in no route code, upon transaction commit, when no outgoing route is connected. */ public void test_QPID_517_ImmediateFailsNoRouteTxP2P() throws Exception { // Ensure transactional sessions are on. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); - testProps.setProperty(PUBSUB_PROPNAME, false); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); + getTestProps().setProperty(PUBSUB_PROPNAME, false); // Set up the messaging topology so that only the publishers producer is bound (do not set up the receivers to // collect its messages). - testProps.setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false); + getTestProps().setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false); // Send one message and get a linked no route exception. CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); assertNoFailures(testCircuit.test(1, - assertionList(((AMQPPublisher) testCircuit.getPublisher()).noRouteAssertion(testProps)))); + assertionList(((AMQPPublisher) testCircuit.getPublisher()).noRouteAssertion(getTestProps())))); } /** Check that an immediate message is sent succesfully not using transactions when a consumer is connected. */ public void test_QPID_517_ImmediateOkNoTxPubSub() throws Exception { // Ensure transactional sessions are off. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false); - testProps.setProperty(PUBSUB_PROPNAME, true); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, false); + getTestProps().setProperty(PUBSUB_PROPNAME, true); // Send one message with no errors. CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); assertNoFailures(testCircuit.test(1, - assertionList(((AMQPPublisher) testCircuit.getPublisher()).noExceptionsAssertion(testProps)))); + assertionList(((AMQPPublisher) testCircuit.getPublisher()).noExceptionsAssertion(getTestProps())))); } /** Check that an immediate message is committed succesfully in a transaction when a consumer is connected. */ public void test_QPID_517_ImmediateOkTxPubSub() throws Exception { // Ensure transactional sessions are off. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); - testProps.setProperty(PUBSUB_PROPNAME, true); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); + getTestProps().setProperty(PUBSUB_PROPNAME, true); // Send one message with no errors. CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); assertNoFailures(testCircuit.test(1, - assertionList(((AMQPPublisher) testCircuit.getPublisher()).noExceptionsAssertion(testProps)))); + assertionList(((AMQPPublisher) testCircuit.getPublisher()).noExceptionsAssertion(getTestProps())))); } /** Check that an immediate message results in no consumers code, not using transactions, when a consumer is disconnected. */ public void test_QPID_517_ImmediateFailsConsumerDisconnectedNoTxPubSub() throws Exception { // Ensure transactional sessions are off. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false); - testProps.setProperty(PUBSUB_PROPNAME, true); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, false); + getTestProps().setProperty(PUBSUB_PROPNAME, true); // Use durable subscriptions, so that the route remains open with no subscribers. - testProps.setProperty(DURABLE_SUBSCRIPTION_PROPNAME, true); + getTestProps().setProperty(DURABLE_SUBSCRIPTION_PROPNAME, true); // Disconnect the consumer. - testProps.setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, false); + getTestProps().setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, false); CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); // Send one message and get a linked no consumers exception. assertNoFailures(testCircuit.test(1, - assertionList(((AMQPPublisher) testCircuit.getPublisher()).noConsumersAssertion(testProps)))); + assertionList(((AMQPPublisher) testCircuit.getPublisher()).noConsumersAssertion(getTestProps())))); } /** Check that an immediate message results in no consumers code, in a transaction, when a consumer is disconnected. */ public void test_QPID_517_ImmediateFailsConsumerDisconnectedTxPubSub() throws Exception { // Ensure transactional sessions are on. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); - testProps.setProperty(PUBSUB_PROPNAME, true); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); + getTestProps().setProperty(PUBSUB_PROPNAME, true); // Use durable subscriptions, so that the route remains open with no subscribers. - testProps.setProperty(DURABLE_SUBSCRIPTION_PROPNAME, true); + getTestProps().setProperty(DURABLE_SUBSCRIPTION_PROPNAME, true); // Disconnect the consumer. - testProps.setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, false); + getTestProps().setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, false); CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); // Send one message and get a linked no consumers exception. assertNoFailures(testCircuit.test(1, - assertionList(((AMQPPublisher) testCircuit.getPublisher()).noConsumersAssertion(testProps)))); + assertionList(((AMQPPublisher) testCircuit.getPublisher()).noConsumersAssertion(getTestProps())))); } /** Check that an immediate message results in no route code, not using transactions, when no outgoing route is connected. */ public void test_QPID_517_ImmediateFailsNoRouteNoTxPubSub() throws Exception { // Ensure transactional sessions are off. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false); - testProps.setProperty(PUBSUB_PROPNAME, true); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, false); + getTestProps().setProperty(PUBSUB_PROPNAME, true); // Set up the messaging topology so that only the publishers producer is bound (do not set up the receivers to // collect its messages). - testProps.setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false); + getTestProps().setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false); // Send one message and get a linked no route exception. CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); assertNoFailures(testCircuit.test(1, - assertionList(((AMQPPublisher) testCircuit.getPublisher()).noRouteAssertion(testProps)))); + assertionList(((AMQPPublisher) testCircuit.getPublisher()).noRouteAssertion(getTestProps())))); } /** Check that an immediate message results in no route code, upon transaction commit, when no outgoing route is connected. */ public void test_QPID_517_ImmediateFailsNoRouteTxPubSub() throws Exception { // Ensure transactional sessions are on. - testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); - testProps.setProperty(PUBSUB_PROPNAME, true); + getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true); + getTestProps().setProperty(PUBSUB_PROPNAME, true); // Set up the messaging topology so that only the publishers producer is bound (do not set up the receivers to // collect its messages). - testProps.setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false); + getTestProps().setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false); // Send one message and get a linked no route exception. CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); assertNoFailures(testCircuit.test(1, - assertionList(((AMQPPublisher) testCircuit.getPublisher()).noRouteAssertion(testProps)))); + assertionList(((AMQPPublisher) testCircuit.getPublisher()).noRouteAssertion(getTestProps())))); } protected void setUp() throws Exception { super.setUp(); - testProps = TestContextProperties.getInstance(MessagingTestConfigProperties.defaults); + setTestProps(TestContextProperties.getInstance(MessagingTestConfigProperties.defaults)); /** All these tests should have the immediate flag on. */ - testProps.setProperty(IMMEDIATE_PROPNAME, true); - testProps.setProperty(MANDATORY_PROPNAME, false); + getTestProps().setProperty(IMMEDIATE_PROPNAME, true); + getTestProps().setProperty(MANDATORY_PROPNAME, false); /** Bind the receivers consumer by default. */ - testProps.setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, true); - testProps.setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, true); + getTestProps().setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, true); + getTestProps().setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, true); } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/RollbackTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/RollbackTest.java index 5c8012e700..edcde796a8 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/RollbackTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/RollbackTest.java @@ -42,7 +42,7 @@ import org.apache.qpid.junit.extensions.util.TestContextProperties; public class RollbackTest extends FrameworkBaseCase { /** Used to read the tests configurable properties through. */ - ParsedProperties testProps; + private ParsedProperties testProps; /** * Creates a new test case with the specified name. diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/TTLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/TTLTest.java index 384e3176f5..d4bab657d7 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/TTLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/TTLTest.java @@ -87,12 +87,12 @@ public class TTLTest extends FrameworkBaseCase List<Message> receivedMessages = new LinkedList<Message>(); // Set up the test properties to match the test case requirements. - testProps.setProperty(ACK_MODE_PROPNAME, Session.AUTO_ACKNOWLEDGE); - testProps.setProperty(PUBSUB_PROPNAME, false); + getTestProps().setProperty(ACK_MODE_PROPNAME, Session.AUTO_ACKNOWLEDGE); + getTestProps().setProperty(PUBSUB_PROPNAME, false); // Create the test circuit from the test configuration parameters. CircuitFactory circuitFactory = getCircuitFactory(); - Circuit testCircuit = circuitFactory.createCircuit(getConnection(), testProps); + Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps()); // This test case assumes it is using a local circuit. LocalCircuitImpl localCircuit = (LocalCircuitImpl) testCircuit; @@ -122,9 +122,12 @@ public class TTLTest extends FrameworkBaseCase // those received should have avoided being purged by the TTL. boolean timedOut = false; - while (!timedOut) + + Message testMessage = null; + + do { - Message testMessage = consumer.receive(1000); + testMessage = consumer.receive(1000); long ttl = testMessage.getLongProperty("testTTL"); long timeStamp = testMessage.getJMSTimestamp(); @@ -140,7 +143,7 @@ public class TTLTest extends FrameworkBaseCase { receivedMessages.add(testMessage); }*/ - } + } while (!timedOut && testMessage != null); // Check that the queue and message store on the broker are empty. // assertTrue("Message store is not empty.", messageStoreEmpty.apply()); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java index 8bb588a036..51fa29b36a 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java @@ -61,7 +61,10 @@ public class ConnectionTest extends QpidBrokerTestCase } finally { - conn.close(); + if(conn != null) + { + conn.close(); + } } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/ConversationFactory.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/ConversationFactory.java index 1e679af112..e153b2e0f5 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/ConversationFactory.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/ConversationFactory.java @@ -278,10 +278,6 @@ public class ConversationFactory { sendTo = sendDestination; } - else if (sendDestination != null) - { - sendTo = sendDestination; - } else { throw new JMSException("The send destination was specified, and no most recent reply-to available to use."); diff --git a/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/Client.java b/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/Client.java index 88d78ee78c..34818fcbea 100644 --- a/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/Client.java +++ b/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/Client.java @@ -32,21 +32,21 @@ import javax.jms.Session; public abstract class Client { - protected Connection con; - protected Session ssn; - protected boolean durable = false; - protected boolean transacted = false; - protected int txSize = 10; - protected int ack_mode = Session.AUTO_ACKNOWLEDGE; - protected String contentType = "application/octet-stream"; - protected Destination dest = null; - - protected long reportFrequency = 60000; // every min - protected DateFormat df = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss"); - protected NumberFormat nf = new DecimalFormat("##.00"); - - protected long startTime = System.currentTimeMillis(); - protected ErrorHandler errorHandler = null; + private Connection con; + private Session ssn; + private boolean durable = false; + private boolean transacted = false; + private int txSize = 10; + private int ack_mode = Session.AUTO_ACKNOWLEDGE; + private String contentType = "application/octet-stream"; + + private long reportFrequency = 60000; // every min + + private DateFormat df = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss"); + private NumberFormat nf = new DecimalFormat("##.00"); + + private long startTime = System.currentTimeMillis(); + private ErrorHandler errorHandler = null; public Client(Connection con) throws Exception { @@ -87,4 +87,60 @@ public abstract class Client e.printStackTrace(); } } + + protected Session getSsn() + { + return ssn; + } + + protected void setSsn(Session ssn) + { + this.ssn = ssn; + } + + protected boolean isDurable() + { + return durable; + } + + protected boolean isTransacted() + { + return transacted; + } + + protected int getTxSize() + { + return txSize; + } + + protected int getAck_mode() + { + return ack_mode; + } + + protected String getContentType() + { + return contentType; + } + + protected long getReportFrequency() + { + return reportFrequency; + } + + protected long getStartTime() + { + return startTime; + } + + protected void setStartTime(long startTime) + { + this.startTime = startTime; + } + + public DateFormat getDf() + { + return df; + } + } diff --git a/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/Receiver.java b/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/Receiver.java index 19ae325d4b..6d33a5f788 100644 --- a/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/Receiver.java +++ b/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/Receiver.java @@ -26,7 +26,6 @@ import java.util.List; import javax.jms.Connection; import javax.jms.Destination; -import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageListener; @@ -101,8 +100,8 @@ public class Receiver extends Client implements MessageListener { super(con); reliability = reliability.getReliability(System.getProperty("reliability","exactly_once")); - ssn = con.createSession(transacted,ack_mode); - consumer = ssn.createConsumer(dest); + setSsn(con.createSession(isTransacted(), getAck_mode())); + consumer = getSsn().createConsumer(dest); if (!sync_rcv) { consumer.setMessageListener(this); @@ -126,8 +125,8 @@ public class Receiver extends Client implements MessageListener Message msg = consumer.receive(); handleMessage(msg); } - Thread.sleep(reportFrequency); - System.out.println(df.format(System.currentTimeMillis()) + Thread.sleep(getReportFrequency()); + System.out.println(getDf().format(System.currentTimeMillis()) + " - messages received : " + msg_count); } } @@ -138,12 +137,12 @@ public class Receiver extends Client implements MessageListener { if (m instanceof TextMessage && ((TextMessage) m).getText().equals("End")) { - MessageProducer temp = ssn.createProducer(m.getJMSReplyTo()); - Message controlMsg = ssn.createTextMessage(); + MessageProducer temp = getSsn().createProducer(m.getJMSReplyTo()); + Message controlMsg = getSsn().createTextMessage(); temp.send(controlMsg); - if (transacted) + if (isTransacted()) { - ssn.commit(); + getSsn().commit(); } temp.close(); } @@ -182,9 +181,9 @@ public class Receiver extends Client implements MessageListener } // Please note that this test case doesn't expect duplicates // When testing for transactions. - if (transacted && msg_count % txSize == 0) + if (isTransacted() && msg_count % getTxSize() == 0) { - ssn.commit(); + getSsn().commit(); } } } diff --git a/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/Sender.java b/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/Sender.java index 4dbe278e33..de50894491 100644 --- a/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/Sender.java +++ b/qpid/java/testkit/src/main/java/org/apache/qpid/testkit/Sender.java @@ -93,10 +93,10 @@ public class Sender extends Client this.msg_count = Integer.getInteger("msg_count", 10); this.iterations = Integer.getInteger("iterations", -1); this.sleep_time = Long.getLong("sleep_time", 1000); - this.ssn = con.createSession(transacted,Session.AUTO_ACKNOWLEDGE); + this.setSsn(con.createSession(isTransacted(),Session.AUTO_ACKNOWLEDGE)); this.dest = dest; - this.producer = ssn.createProducer(dest); - this.replyTo = ssn.createTemporaryQueue(); + this.producer = getSsn().createProducer(dest); + this.replyTo = getSsn().createTemporaryQueue(); System.out.println("Sending messages to : " + dest); } @@ -108,11 +108,11 @@ public class Sender extends Client protected Message getNextMessage() throws Exception { int s = msg_size == -1 ? 500 + gen.nextInt(1000) : msg_size; - Message msg = (contentType.equals("text/plain")) ? - MessageFactory.createTextMessage(ssn, s): - MessageFactory.createBytesMessage(ssn, s); + Message msg = (getContentType().equals("text/plain")) ? + MessageFactory.createTextMessage(getSsn(), s): + MessageFactory.createBytesMessage(getSsn(), s); - msg.setJMSDeliveryMode((durable) ? DeliveryMode.PERSISTENT + msg.setJMSDeliveryMode((isDurable()) ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT); return msg; } @@ -125,10 +125,10 @@ public class Sender extends Client for (int x=0; infinite || x < iterations; x++) { long now = System.currentTimeMillis(); - if (now - startTime >= reportFrequency) + if (now - getStartTime() >= getReportFrequency()) { System.out.println(df.format(now) + " - iterations : " + x); - startTime = now; + setStartTime(now); } for (int i = 0; i < msg_count; i++) @@ -136,26 +136,26 @@ public class Sender extends Client Message msg = getNextMessage(); msg.setIntProperty("sequence",i); producer.send(msg); - if (transacted && msg_count % txSize == 0) + if (isTransacted() && msg_count % getTxSize() == 0) { - ssn.commit(); + getSsn().commit(); } } - TextMessage m = ssn.createTextMessage("End"); + TextMessage m = getSsn().createTextMessage("End"); m.setJMSReplyTo(replyTo); producer.send(m); - if (transacted) + if (isTransacted()) { - ssn.commit(); + getSsn().commit(); } - MessageConsumer feedbackConsumer = ssn.createConsumer(replyTo); + MessageConsumer feedbackConsumer = getSsn().createConsumer(replyTo); feedbackConsumer.receive(); feedbackConsumer.close(); - if (transacted) + if (isTransacted()) { - ssn.commit(); + getSsn().commit(); } Thread.sleep(sleep_time); } |