diff options
Diffstat (limited to 'java')
41 files changed, 933 insertions, 533 deletions
diff --git a/java/broker/src/main/java/org/apache/qpid/server/Main.java b/java/broker/src/main/java/org/apache/qpid/server/Main.java index 1e5f56fe3a..c345b43aeb 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/Main.java +++ b/java/broker/src/main/java/org/apache/qpid/server/Main.java @@ -373,6 +373,7 @@ public class Main } acceptor.bind(bindAddress, handler, sconfig); + //fixme qpid.AMQP should be using qpidproperties to get value _brokerLogger.info("Qpid.AMQP listening on non-SSL address " + bindAddress); } @@ -381,14 +382,21 @@ public class Main AMQPFastProtocolHandler handler = new AMQPProtocolProvider().getHandler(); try { - acceptor.bind(new InetSocketAddress(connectorConfig.sslPort), handler, sconfig); + + acceptor.bind(new InetSocketAddress(connectorConfig.sslPort), handler, sconfig); + //fixme qpid.AMQP should be using qpidproperties to get value _brokerLogger.info("Qpid.AMQP listening on SSL port " + connectorConfig.sslPort); + } catch (IOException e) { _brokerLogger.error("Unable to listen on SSL port: " + e, e); } } + + //fixme qpid.AMQP should be using qpidproperties to get value + _brokerLogger.info("Qpid Broker Ready :" + QpidProperties.getReleaseVersion() + + " build: " + QpidProperties.getBuildVersion()); } catch (Exception e) { diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/DestWildExchange.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/DestWildExchange.java index 8a50e93bf9..605a4bcb61 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/exchange/DestWildExchange.java +++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/DestWildExchange.java @@ -57,19 +57,16 @@ public class DestWildExchange extends AbstractExchange private ConcurrentHashMap<AMQShortString, List<AMQQueue>> _routingKey2queues = new ConcurrentHashMap<AMQShortString, List<AMQQueue>>(); - /** - * DestWildExchangeMBean class implements the management interface for the - * Topic exchanges. - */ + /** DestWildExchangeMBean class implements the management interface for the Topic exchanges. */ @MBeanDescription("Management Bean for Topic Exchange") private final class DestWildExchangeMBean extends ExchangeMBean { // open mbean data types for representing exchange bindings - private String[] _bindingItemNames = {"Routing Key", "Queue Names"}; - private String[] _bindingItemIndexNames = {_bindingItemNames[0]}; + private String[] _bindingItemNames = {"Routing Key", "Queue Names"}; + private String[] _bindingItemIndexNames = {_bindingItemNames[0]}; private OpenType[] _bindingItemTypes = new OpenType[2]; - private CompositeType _bindingDataType = null; - private TabularType _bindinglistDataType = null; + private CompositeType _bindingDataType = null; + private TabularType _bindinglistDataType = null; private TabularDataSupport _bindingList = null; @MBeanConstructor("Creates an MBean for AMQ topic exchange") @@ -80,22 +77,18 @@ public class DestWildExchange extends AbstractExchange init(); } - /** - * initialises the OpenType objects. - */ + /** initialises the OpenType objects. */ private void init() throws OpenDataException { _bindingItemTypes[0] = SimpleType.STRING; _bindingItemTypes[1] = new ArrayType(1, SimpleType.STRING); _bindingDataType = new CompositeType("Exchange Binding", "Routing key and Queue names", - _bindingItemNames, _bindingItemNames, _bindingItemTypes); + _bindingItemNames, _bindingItemNames, _bindingItemTypes); _bindinglistDataType = new TabularType("Exchange Bindings", "Exchange Bindings for " + getName(), - _bindingDataType, _bindingItemIndexNames); + _bindingDataType, _bindingItemIndexNames); } - /** - * returns exchange bindings in tabular form - */ + /** returns exchange bindings in tabular form */ public TabularData bindings() throws OpenDataException { _bindingList = new TabularDataSupport(_bindinglistDataType); @@ -122,7 +115,9 @@ public class DestWildExchange extends AbstractExchange { AMQQueue queue = getQueueRegistry().getQueue(new AMQShortString(queueName)); if (queue == null) + { throw new JMException("Queue \"" + queueName + "\" is not registered with the exchange."); + } try { @@ -159,7 +154,7 @@ public class DestWildExchange extends AbstractExchange { queueList.add(queue); } - else if(_logger.isDebugEnabled()) + else if (_logger.isDebugEnabled()) { _logger.debug("Queue " + queue + " is already registered with routing key " + routingKey); } @@ -176,10 +171,18 @@ public class DestWildExchange extends AbstractExchange // TODO: add support for the immediate flag if (queues == null) { - _logger.warn("No queues found for routing key " + routingKey); - _logger.warn("Routing map contains: " + _routingKey2queues); - //todo Check for valid topic - mritchie - return; + if (info.isMandatory()) + { + String msg = "Topic " + routingKey + " is not known to " + this; + throw new NoRouteException(msg, payload); + } + else + { + _logger.warn("No queues found for routing key " + routingKey); + _logger.warn("Routing map contains: " + _routingKey2queues); + //todo Check for valid topic - mritchie + return; + } } for (AMQQueue q : queues) @@ -245,7 +248,7 @@ public class DestWildExchange extends AbstractExchange } } - protected ExchangeMBean createMBean() throws AMQException + protected ExchangeMBean createMBean() throws AMQException { try { diff --git a/java/broker/src/main/java/org/apache/qpid/server/filter/ArithmeticExpression.java b/java/broker/src/main/java/org/apache/qpid/server/filter/ArithmeticExpression.java index 1b3b116fd0..138d4155b1 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/filter/ArithmeticExpression.java +++ b/java/broker/src/main/java/org/apache/qpid/server/filter/ArithmeticExpression.java @@ -1,3 +1,4 @@ +/* Copyright Rupert Smith, 2005 to 2006, all rights reserved. */ /** * * Licensed to the Apache Software Foundation (ASF) under one or more @@ -20,16 +21,14 @@ package org.apache.qpid.server.filter; // Based on like named file from r450141 of the Apache ActiveMQ project <http://www.activemq.org/site/home.html> // - import org.apache.qpid.AMQException; import org.apache.qpid.server.queue.AMQMessage; /** * An expression which performs an operation on two expression values - * - * @version $Revision$ */ -public abstract class ArithmeticExpression extends BinaryExpression { +public abstract class ArithmeticExpression extends BinaryExpression +{ protected static final int INTEGER = 1; protected static final int LONG = 2; @@ -39,156 +38,213 @@ public abstract class ArithmeticExpression extends BinaryExpression { * @param left * @param right */ - public ArithmeticExpression(Expression left, Expression right) { + public ArithmeticExpression(Expression left, Expression right) + { super(left, right); } - public static Expression createPlus(Expression left, Expression right) { - return new ArithmeticExpression(left, right) { - protected Object evaluate(Object lvalue, Object rvalue) { - if (lvalue instanceof String) { - String text = (String) lvalue; - String answer = text + rvalue; - return answer; + public static Expression createPlus(Expression left, Expression right) + { + return new ArithmeticExpression(left, right) + { + protected Object evaluate(Object lvalue, Object rvalue) + { + if (lvalue instanceof String) + { + String text = (String) lvalue; + String answer = text + rvalue; + + return answer; + } + else if (lvalue instanceof Number) + { + return plus((Number) lvalue, asNumber(rvalue)); + } + + throw new RuntimeException("Cannot call plus operation on: " + lvalue + " and: " + rvalue); } - else if (lvalue instanceof Number) { - return plus((Number) lvalue, asNumber(rvalue)); + + public String getExpressionSymbol() + { + return "+"; } - throw new RuntimeException("Cannot call plus operation on: " + lvalue + " and: " + rvalue); - } + }; + } - public String getExpressionSymbol() + public static Expression createMinus(Expression left, Expression right) + { + return new ArithmeticExpression(left, right) { - return "+"; - } - }; - } + protected Object evaluate(Object lvalue, Object rvalue) + { + if (lvalue instanceof Number) + { + return minus((Number) lvalue, asNumber(rvalue)); + } - public static Expression createMinus(Expression left, Expression right) { - return new ArithmeticExpression(left, right) { - protected Object evaluate(Object lvalue, Object rvalue) { - if (lvalue instanceof Number) { - return minus((Number) lvalue, asNumber(rvalue)); + throw new RuntimeException("Cannot call minus operation on: " + lvalue + " and: " + rvalue); } - throw new RuntimeException("Cannot call minus operation on: " + lvalue + " and: " + rvalue); - } - public String getExpressionSymbol() { - return "-"; - } - }; + public String getExpressionSymbol() + { + return "-"; + } + }; } - public static Expression createMultiply(Expression left, Expression right) { - return new ArithmeticExpression(left, right) { + public static Expression createMultiply(Expression left, Expression right) + { + return new ArithmeticExpression(left, right) + { + + protected Object evaluate(Object lvalue, Object rvalue) + { + if (lvalue instanceof Number) + { + return multiply((Number) lvalue, asNumber(rvalue)); + } - protected Object evaluate(Object lvalue, Object rvalue) { - if (lvalue instanceof Number) { - return multiply((Number) lvalue, asNumber(rvalue)); + throw new RuntimeException("Cannot call multiply operation on: " + lvalue + " and: " + rvalue); } - throw new RuntimeException("Cannot call multiply operation on: " + lvalue + " and: " + rvalue); - } - public String getExpressionSymbol() { - return "*"; - } - }; + public String getExpressionSymbol() + { + return "*"; + } + }; } - public static Expression createDivide(Expression left, Expression right) { - return new ArithmeticExpression(left, right) { + public static Expression createDivide(Expression left, Expression right) + { + return new ArithmeticExpression(left, right) + { - protected Object evaluate(Object lvalue, Object rvalue) { - if (lvalue instanceof Number) { - return divide((Number) lvalue, asNumber(rvalue)); + protected Object evaluate(Object lvalue, Object rvalue) + { + if (lvalue instanceof Number) + { + return divide((Number) lvalue, asNumber(rvalue)); + } + + throw new RuntimeException("Cannot call divide operation on: " + lvalue + " and: " + rvalue); } - throw new RuntimeException("Cannot call divide operation on: " + lvalue + " and: " + rvalue); - } - public String getExpressionSymbol() { - return "/"; - } - }; + public String getExpressionSymbol() + { + return "/"; + } + }; } - public static Expression createMod(Expression left, Expression right) { - return new ArithmeticExpression(left, right) { + public static Expression createMod(Expression left, Expression right) + { + return new ArithmeticExpression(left, right) + { + + protected Object evaluate(Object lvalue, Object rvalue) + { + if (lvalue instanceof Number) + { + return mod((Number) lvalue, asNumber(rvalue)); + } - protected Object evaluate(Object lvalue, Object rvalue) { - if (lvalue instanceof Number) { - return mod((Number) lvalue, asNumber(rvalue)); + throw new RuntimeException("Cannot call mod operation on: " + lvalue + " and: " + rvalue); } - throw new RuntimeException("Cannot call mod operation on: " + lvalue + " and: " + rvalue); - } - public String getExpressionSymbol() { - return "%"; - } - }; + public String getExpressionSymbol() + { + return "%"; + } + }; } - protected Number plus(Number left, Number right) { - switch (numberType(left, right)) { - case INTEGER: - return new Integer(left.intValue() + right.intValue()); - case LONG: - return new Long(left.longValue() + right.longValue()); - default: - return new Double(left.doubleValue() + right.doubleValue()); + protected Number plus(Number left, Number right) + { + switch (numberType(left, right)) + { + + case INTEGER: + return new Integer(left.intValue() + right.intValue()); + + case LONG: + return new Long(left.longValue() + right.longValue()); + + default: + return new Double(left.doubleValue() + right.doubleValue()); } } - protected Number minus(Number left, Number right) { - switch (numberType(left, right)) { - case INTEGER: - return new Integer(left.intValue() - right.intValue()); - case LONG: - return new Long(left.longValue() - right.longValue()); - default: - return new Double(left.doubleValue() - right.doubleValue()); + protected Number minus(Number left, Number right) + { + switch (numberType(left, right)) + { + + case INTEGER: + return new Integer(left.intValue() - right.intValue()); + + case LONG: + return new Long(left.longValue() - right.longValue()); + + default: + return new Double(left.doubleValue() - right.doubleValue()); } } - protected Number multiply(Number left, Number right) { - switch (numberType(left, right)) { - case INTEGER: - return new Integer(left.intValue() * right.intValue()); - case LONG: - return new Long(left.longValue() * right.longValue()); - default: - return new Double(left.doubleValue() * right.doubleValue()); + protected Number multiply(Number left, Number right) + { + switch (numberType(left, right)) + { + + case INTEGER: + return new Integer(left.intValue() * right.intValue()); + + case LONG: + return new Long(left.longValue() * right.longValue()); + + default: + return new Double(left.doubleValue() * right.doubleValue()); } } - protected Number divide(Number left, Number right) { + protected Number divide(Number left, Number right) + { return new Double(left.doubleValue() / right.doubleValue()); } - protected Number mod(Number left, Number right) { + protected Number mod(Number left, Number right) + { return new Double(left.doubleValue() % right.doubleValue()); } - private int numberType(Number left, Number right) { - if (isDouble(left) || isDouble(right)) { + private int numberType(Number left, Number right) + { + if (isDouble(left) || isDouble(right)) + { return DOUBLE; } - else if (left instanceof Long || right instanceof Long) { + else if ((left instanceof Long) || (right instanceof Long)) + { return LONG; } - else { + else + { return INTEGER; } } - private boolean isDouble(Number n) { - return n instanceof Float || n instanceof Double; + private boolean isDouble(Number n) + { + return (n instanceof Float) || (n instanceof Double); } - protected Number asNumber(Object value) { - if (value instanceof Number) { + protected Number asNumber(Object value) + { + if (value instanceof Number) + { return (Number) value; } - else { + else + { throw new RuntimeException("Cannot convert value: " + value + " into a number"); } } @@ -196,22 +252,25 @@ public abstract class ArithmeticExpression extends BinaryExpression { public Object evaluate(AMQMessage message) throws AMQException { Object lvalue = left.evaluate(message); - if (lvalue == null) { + if (lvalue == null) + { return null; } + Object rvalue = right.evaluate(message); - if (rvalue == null) { + if (rvalue == null) + { return null; } + return evaluate(lvalue, rvalue); } - /** * @param lvalue * @param rvalue * @return */ - abstract protected Object evaluate(Object lvalue, Object rvalue); + protected abstract Object evaluate(Object lvalue, Object rvalue); } diff --git a/java/broker/src/main/java/org/apache/qpid/server/filter/BinaryExpression.java b/java/broker/src/main/java/org/apache/qpid/server/filter/BinaryExpression.java index 4256ab9189..1a1024bd2b 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/filter/BinaryExpression.java +++ b/java/broker/src/main/java/org/apache/qpid/server/filter/BinaryExpression.java @@ -1,3 +1,4 @@ +/* Copyright Rupert Smith, 2005 to 2006, all rights reserved. */ /** * * Licensed to the Apache Software Foundation (ASF) under one or more @@ -20,35 +21,35 @@ package org.apache.qpid.server.filter; // Based on like named file from r450141 of the Apache ActiveMQ project <http://www.activemq.org/site/home.html> // - - /** * An expression which performs an operation on two expression values. - * - * @version $Revision$ */ -abstract public class BinaryExpression implements Expression { +public abstract class BinaryExpression implements Expression +{ protected Expression left; protected Expression right; - public BinaryExpression(Expression left, Expression right) { + public BinaryExpression(Expression left, Expression right) + { this.left = left; this.right = right; } - public Expression getLeft() { + public Expression getLeft() + { return left; } - public Expression getRight() { + public Expression getRight() + { return right; } - /** * @see java.lang.Object#toString() */ - public String toString() { + public String toString() + { return "(" + left.toString() + " " + getExpressionSymbol() + " " + right.toString() + ")"; } @@ -57,7 +58,8 @@ abstract public class BinaryExpression implements Expression { * * @see java.lang.Object#hashCode() */ - public int hashCode() { + public int hashCode() + { return toString().hashCode(); } @@ -66,11 +68,14 @@ abstract public class BinaryExpression implements Expression { * * @see java.lang.Object#equals(java.lang.Object) */ - public boolean equals(Object o) { + public boolean equals(Object o) + { - if (o == null || !this.getClass().equals(o.getClass())) { + if ((o == null) || !this.getClass().equals(o.getClass())) + { return false; } + return toString().equals(o.toString()); } @@ -81,20 +86,22 @@ abstract public class BinaryExpression implements Expression { * * @return */ - abstract public String getExpressionSymbol(); + public abstract String getExpressionSymbol(); /** * @param expression */ - public void setRight(Expression expression) { + public void setRight(Expression expression) + { right = expression; } /** * @param expression */ - public void setLeft(Expression expression) { + public void setLeft(Expression expression) + { left = expression; } - + } diff --git a/java/broker/src/main/java/org/apache/qpid/server/filter/BooleanExpression.java b/java/broker/src/main/java/org/apache/qpid/server/filter/BooleanExpression.java index 122527d4f3..0d5c5009f7 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/filter/BooleanExpression.java +++ b/java/broker/src/main/java/org/apache/qpid/server/filter/BooleanExpression.java @@ -1,3 +1,4 @@ +/* Copyright Rupert Smith, 2005 to 2006, all rights reserved. */ /** * * Licensed to the Apache Software Foundation (ASF) under one or more @@ -20,18 +21,12 @@ package org.apache.qpid.server.filter; // Based on like named file from r450141 of the Apache ActiveMQ project <http://www.activemq.org/site/home.html> // - import org.apache.qpid.AMQException; import org.apache.qpid.server.queue.AMQMessage; - - - /** * A BooleanExpression is an expression that always * produces a Boolean result. - * - * @version $Revision$ */ public interface BooleanExpression extends Expression { diff --git a/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java b/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java index cedb8d7ca8..606a59e0fa 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java +++ b/java/broker/src/main/java/org/apache/qpid/server/filter/ComparisonExpression.java @@ -1,3 +1,4 @@ +/* Copyright Rupert Smith, 2005 to 2006, all rights reserved. */ /* * * Licensed to the Apache Software Foundation (ASF) under one @@ -32,8 +33,6 @@ import org.apache.qpid.server.queue.AMQMessage; /** * A filter performing a comparison of two objects - * - * @version $Revision$ */ public abstract class ComparisonExpression extends BinaryExpression implements BooleanExpression { @@ -153,7 +152,7 @@ public abstract class ComparisonExpression extends BinaryExpression implements B { return Boolean.FALSE; - //throw new RuntimeException("LIKE can only operate on String identifiers. LIKE attemped on: '" + rv.getClass()); + // throw new RuntimeException("LIKE can only operate on String identifiers. LIKE attemped on: '" + rv.getClass()); } return likePattern.matcher((String) rv).matches() ? Boolean.TRUE : Boolean.FALSE; @@ -240,42 +239,42 @@ public abstract class ComparisonExpression extends BinaryExpression implements B private static BooleanExpression doCreateEqual(Expression left, Expression right) { return new ComparisonExpression(left, right) - { - - public Object evaluate(AMQMessage message) throws AMQException { - Object lv = left.evaluate(message); - Object rv = right.evaluate(message); - // Iff one of the values is null - if ((lv == null) ^ (rv == null)) + public Object evaluate(AMQMessage message) throws AMQException { + Object lv = left.evaluate(message); + Object rv = right.evaluate(message); + + // Iff one of the values is null + if ((lv == null) ^ (rv == null)) + { + return Boolean.FALSE; + } + + if ((lv == rv) || lv.equals(rv)) + { + return Boolean.TRUE; + } + + if ((lv instanceof Comparable) && (rv instanceof Comparable)) + { + return compare((Comparable) lv, (Comparable) rv); + } + return Boolean.FALSE; } - if ((lv == rv) || lv.equals(rv)) + protected boolean asBoolean(int answer) { - return Boolean.TRUE; + return answer == 0; } - if ((lv instanceof Comparable) && (rv instanceof Comparable)) + public String getExpressionSymbol() { - return compare((Comparable) lv, (Comparable) rv); + return "="; } - - return Boolean.FALSE; - } - - protected boolean asBoolean(int answer) - { - return answer == 0; - } - - public String getExpressionSymbol() - { - return "="; - } - }; + }; } public static BooleanExpression createGreaterThan(final Expression left, final Expression right) @@ -284,17 +283,17 @@ public abstract class ComparisonExpression extends BinaryExpression implements B checkLessThanOperand(right); return new ComparisonExpression(left, right) - { - protected boolean asBoolean(int answer) { - return answer > 0; - } + protected boolean asBoolean(int answer) + { + return answer > 0; + } - public String getExpressionSymbol() - { - return ">"; - } - }; + public String getExpressionSymbol() + { + return ">"; + } + }; } public static BooleanExpression createGreaterThanEqual(final Expression left, final Expression right) @@ -303,17 +302,17 @@ public abstract class ComparisonExpression extends BinaryExpression implements B checkLessThanOperand(right); return new ComparisonExpression(left, right) - { - protected boolean asBoolean(int answer) { - return answer >= 0; - } + protected boolean asBoolean(int answer) + { + return answer >= 0; + } - public String getExpressionSymbol() - { - return ">="; - } - }; + public String getExpressionSymbol() + { + return ">="; + } + }; } public static BooleanExpression createLessThan(final Expression left, final Expression right) @@ -322,19 +321,19 @@ public abstract class ComparisonExpression extends BinaryExpression implements B checkLessThanOperand(right); return new ComparisonExpression(left, right) - { - - protected boolean asBoolean(int answer) { - return answer < 0; - } - public String getExpressionSymbol() - { - return "<"; - } + protected boolean asBoolean(int answer) + { + return answer < 0; + } + + public String getExpressionSymbol() + { + return "<"; + } - }; + }; } public static BooleanExpression createLessThanEqual(final Expression left, final Expression right) @@ -343,18 +342,18 @@ public abstract class ComparisonExpression extends BinaryExpression implements B checkLessThanOperand(right); return new ComparisonExpression(left, right) - { - - protected boolean asBoolean(int answer) { - return answer <= 0; - } - public String getExpressionSymbol() - { - return "<="; - } - }; + protected boolean asBoolean(int answer) + { + return answer <= 0; + } + + public String getExpressionSymbol() + { + return "<="; + } + }; } /** diff --git a/java/broker/src/main/java/org/apache/qpid/server/filter/Expression.java b/java/broker/src/main/java/org/apache/qpid/server/filter/Expression.java index 4a2130e767..cb40a32290 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/filter/Expression.java +++ b/java/broker/src/main/java/org/apache/qpid/server/filter/Expression.java @@ -1,3 +1,4 @@ +/* Copyright Rupert Smith, 2005 to 2006, all rights reserved. */ /** * * Licensed to the Apache Software Foundation (ASF) under one or more @@ -15,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.qpid.server.filter; // // Based on like named file from r450141 of the Apache ActiveMQ project <http://www.activemq.org/site/home.html> @@ -24,11 +24,8 @@ package org.apache.qpid.server.filter; import org.apache.qpid.AMQException; import org.apache.qpid.server.queue.AMQMessage; - /** * Represents an expression - * - * @version $Revision$ */ public interface Expression { @@ -37,5 +34,5 @@ public interface Expression * @return the value of this expression */ public Object evaluate(AMQMessage message) throws AMQException; - + } diff --git a/java/broker/src/main/java/org/apache/qpid/server/filter/LogicExpression.java b/java/broker/src/main/java/org/apache/qpid/server/filter/LogicExpression.java index dea6092b8a..a90775a186 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/filter/LogicExpression.java +++ b/java/broker/src/main/java/org/apache/qpid/server/filter/LogicExpression.java @@ -1,3 +1,4 @@ +/* Copyright Rupert Smith, 2005 to 2006, all rights reserved. */ /** * * Licensed to the Apache Software Foundation (ASF) under one or more @@ -25,69 +26,86 @@ import org.apache.qpid.server.queue.AMQMessage; /** * A filter performing a comparison of two objects - * - * @version $Revision$ */ -public abstract class LogicExpression extends BinaryExpression implements BooleanExpression { - - public static BooleanExpression createOR(BooleanExpression lvalue, BooleanExpression rvalue) { - return new LogicExpression(lvalue, rvalue) { - - public Object evaluate(AMQMessage message) throws AMQException { - - Boolean lv = (Boolean) left.evaluate(message); - // Can we do an OR shortcut?? - if (lv !=null && lv.booleanValue()) { - return Boolean.TRUE; +public abstract class LogicExpression extends BinaryExpression implements BooleanExpression +{ + + public static BooleanExpression createOR(BooleanExpression lvalue, BooleanExpression rvalue) + { + return new LogicExpression(lvalue, rvalue) + { + + public Object evaluate(AMQMessage message) throws AMQException + { + + Boolean lv = (Boolean) left.evaluate(message); + // Can we do an OR shortcut?? + if ((lv != null) && lv.booleanValue()) + { + return Boolean.TRUE; + } + + Boolean rv = (Boolean) right.evaluate(message); + + return (rv == null) ? null : rv; + } + + public String getExpressionSymbol() + { + return "OR"; } - - Boolean rv = (Boolean) right.evaluate(message); - return rv==null ? null : rv; - } - - public String getExpressionSymbol() { - return "OR"; - } - }; + }; } - public static BooleanExpression createAND(BooleanExpression lvalue, BooleanExpression rvalue) { - return new LogicExpression(lvalue, rvalue) { + public static BooleanExpression createAND(BooleanExpression lvalue, BooleanExpression rvalue) + { + return new LogicExpression(lvalue, rvalue) + { - public Object evaluate(AMQMessage message) throws AMQException { + public Object evaluate(AMQMessage message) throws AMQException + { - Boolean lv = (Boolean) left.evaluate(message); + Boolean lv = (Boolean) left.evaluate(message); - // Can we do an AND shortcut?? - if (lv == null) - return null; - if (!lv.booleanValue()) { - return Boolean.FALSE; - } + // Can we do an AND shortcut?? + if (lv == null) + { + return null; + } + + if (!lv.booleanValue()) + { + return Boolean.FALSE; + } + + Boolean rv = (Boolean) right.evaluate(message); - Boolean rv = (Boolean) right.evaluate(message); - return rv == null ? null : rv; - } + return (rv == null) ? null : rv; + } - public String getExpressionSymbol() { - return "AND"; - } - }; + public String getExpressionSymbol() + { + return "AND"; + } + }; } /** * @param left * @param right */ - public LogicExpression(BooleanExpression left, BooleanExpression right) { + public LogicExpression(BooleanExpression left, BooleanExpression right) + { super(left, right); } - abstract public Object evaluate(AMQMessage message) throws AMQException; + public abstract Object evaluate(AMQMessage message) throws AMQException; - public boolean matches(AMQMessage message) throws AMQException { + public boolean matches(AMQMessage message) throws AMQException + { Object object = evaluate(message); - return object!=null && object==Boolean.TRUE; + + return (object != null) && (object == Boolean.TRUE); } } diff --git a/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java b/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java index 7d25fb8c69..3ab23e8b46 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java +++ b/java/broker/src/main/java/org/apache/qpid/server/management/MBeanInvocationHandlerImpl.java @@ -17,8 +17,7 @@ */ package org.apache.qpid.server.management; -import org.apache.qpid.AMQException; -import org.apache.qpid.server.security.access.AMQUserManagementMBean; +import org.apache.qpid.server.security.access.UserManagement; import org.apache.log4j.Logger; import javax.management.remote.MBeanServerForwarder; @@ -37,12 +36,6 @@ import java.security.Principal; import java.security.AccessControlContext; import java.util.Set; import java.util.Properties; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ConcurrentHashMap; -import java.io.File; -import java.io.InputStream; -import java.io.IOException; -import java.io.FileInputStream; /** * This class can be used by the JMXConnectorServer as an InvocationHandler for the mbean operations. This implements @@ -110,6 +103,7 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler // Restrict access to "createMBean" and "unregisterMBean" to any user if (methodName.equals("createMBean") || methodName.equals("unregisterMBean")) { + _logger.debug("User trying to create or unregister an MBean"); throw new SecurityException("Access denied"); } @@ -155,32 +149,8 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler { if (args[0] instanceof ObjectName) { - String mbeanMethod = (args.length > 1) ? (String) args[1] : null; - if (mbeanMethod == null) - { - if (args[0] instanceof ObjectName) - { - ObjectName object = (ObjectName) args[0]; - return object.getCanonicalName().contains("UserManagement"); - } - else - { - return false; - } - } - - try - { - MBeanInfo mbeanInfo = mbs.getMBeanInfo((ObjectName) args[0]); - if (mbeanInfo != null) - { - return mbeanInfo.getClassName().equals("org.apache.qpid.server.security.access.AMQUserManagementMBean"); - } - } - catch (JMException ex) - { - return false; - } + ObjectName object = (ObjectName) args[0]; + return UserManagement.TYPE.equals(object.getKeyProperty("type")); } return false; @@ -223,16 +193,16 @@ public class MBeanInvocationHandlerImpl implements InvocationHandler private boolean isReadOnlyMethod(Method method, Object[] args) { String methodName = method.getName(); - if (methodName.equals("queryMBeans") || - methodName.equals("getDefaultDomain") || - methodName.equals("getMBeanInfo") || - methodName.equals("getAttribute") || - methodName.equals("getAttributes")) + if (methodName.startsWith("query") || methodName.startsWith("get")) { return true; } + else if (methodName.startsWith("set")) + { + return false; + } - if (args[0] instanceof ObjectName) + if ((args[0] instanceof ObjectName) && (methodName.equals("invoke"))) { String mbeanMethod = (args.length > 1) ? (String) args[1] : null; if (mbeanMethod == null) diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java index 2e62c2f1e4..3162efa183 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java +++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java @@ -463,7 +463,17 @@ public class AMQMinaProtocolSession implements AMQProtocolSession, throw new AMQException("Session is marked awaiting channel close"); } - _channelMap.put(channelId, channel); + if (_channelMap.size() == _maxNoOfChannels) + { + String errorMessage = toString() + ": maximum number of channels has been reached (" + + _maxNoOfChannels + "); can't create channel"; + _logger.error(errorMessage); + throw new AMQException(AMQConstant.NOT_ALLOWED, errorMessage); + } + else + { + _channelMap.put(channel.getChannelId(), channel); + } if (((channelId & CHANNEL_CACHE_SIZE) == channelId)) { @@ -755,8 +765,9 @@ public class AMQMinaProtocolSession implements AMQProtocolSession, { return _authorizedID; } + public String getClientVersion() { - return _clientVersion == null ? null : _clientVersion.toString(); + return _clientVersion == null ? null : _clientVersion.toString(); } } diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java index e19038504f..955aaa6acb 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java +++ b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java @@ -366,7 +366,7 @@ public class AMQMessage */ public AMQMessage takeReference() { - _referenceCount.incrementAndGet(); + incrementReference();// _referenceCount.incrementAndGet(); return this; } diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java index 65d5906d05..0adf6153f8 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java +++ b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java @@ -615,7 +615,7 @@ public class AMQQueue implements Managable, Comparable } catch (MessageCleanupException e) { - //Message was dequeued, but could notthen be deleted + //Message was dequeued, but could not then be deleted //though it is no longer referenced. This should be very //rare and can be detected and cleaned up on recovery or //done through some form of manual intervention. diff --git a/java/broker/src/main/java/org/apache/qpid/server/security/access/UserManagement.java b/java/broker/src/main/java/org/apache/qpid/server/security/access/UserManagement.java index ec7031534b..b8762aa43b 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/security/access/UserManagement.java +++ b/java/broker/src/main/java/org/apache/qpid/server/security/access/UserManagement.java @@ -63,7 +63,7 @@ public interface UserManagement impact = MBeanOperationInfo.ACTION) boolean setRights(@MBeanOperationParameter(name = "username", description = "Username")String username, @MBeanOperationParameter(name = "read", description = "Administration read")boolean read, - @MBeanOperationParameter(name = "write", description = "Administration write")boolean write, + @MBeanOperationParameter(name = "readAndWrite", description = "Administration write")boolean write, @MBeanOperationParameter(name = "admin", description = "Administration rights")boolean admin); /** @@ -82,7 +82,7 @@ public interface UserManagement boolean createUser(@MBeanOperationParameter(name = "username", description = "Username")String username, @MBeanOperationParameter(name = "password", description = "Password")char[] password, @MBeanOperationParameter(name = "read", description = "Administration read")boolean read, - @MBeanOperationParameter(name = "write", description = "Administration write")boolean write, + @MBeanOperationParameter(name = "readAndWrite", description = "Administration write")boolean write, @MBeanOperationParameter(name = "admin", description = "Administration rights")boolean admin); /** diff --git a/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java b/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java index a5c5763db1..a9496d0de1 100644 --- a/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java +++ b/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueAlertTest.java @@ -106,7 +106,7 @@ public class AMQQueueAlertTest extends TestCase /** * Tests if Queue Depth alert is thrown when queue depth reaches the threshold value * - * Based on FT402 subbmitted by client + * Based on FT-402 subbmitted by client * * @throws Exception */ @@ -134,6 +134,8 @@ public class AMQQueueAlertTest extends TestCase * Tests if MESSAGE AGE alert is thrown, when a message is in the queue for time higher than threshold value of * message age * + * Alternative test to FT-401 provided by client + * * @throws Exception */ public void testMessageAgeAlert() throws Exception diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java index 7b65f279be..93724c9920 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java @@ -644,7 +644,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi } catch (AMQException e) { - throw(JMSException) (new JMSException("Failed to rollback: " + e).initCause(e)); + throw (JMSException) (new JMSException("Failed to rollback: " + e).initCause(e)); } } } diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java b/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java index ce8e14506f..f54cb782c8 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java @@ -25,9 +25,10 @@ import javax.jms.TemporaryQueue; import org.apache.qpid.framing.AMQShortString; -/** - * AMQ implementation of a TemporaryQueue. - */ +import java.util.Random; +import java.util.UUID; + +/** AMQ implementation of a TemporaryQueue. */ final class AMQTemporaryQueue extends AMQQueue implements TemporaryQueue, TemporaryDestination { @@ -35,21 +36,17 @@ final class AMQTemporaryQueue extends AMQQueue implements TemporaryQueue, Tempor private final AMQSession _session; private boolean _deleted; - /** - * Create a new instance of an AMQTemporaryQueue - */ + /** Create a new instance of an AMQTemporaryQueue */ public AMQTemporaryQueue(AMQSession session) { - super(session.getTemporaryQueueExchangeName(),new AMQShortString("TempQueue" + Long.toString(System.currentTimeMillis())), true); + super(session.getTemporaryQueueExchangeName(), new AMQShortString("TempQueue" + UUID.randomUUID()), true); _session = session; } - /** - * @see javax.jms.TemporaryQueue#delete() - */ + /** @see javax.jms.TemporaryQueue#delete() */ public synchronized void delete() throws JMSException { - if(_session.hasConsumer(this)) + if (_session.hasConsumer(this)) { throw new JMSException("Temporary Queue has consumers so cannot be deleted"); } diff --git a/java/client/src/test/java/org/apache/qpid/client/ResetMessageListenerTest.java b/java/client/src/test/java/org/apache/qpid/client/ResetMessageListenerTest.java index 42594fff8e..97fbf9876f 100644 --- a/java/client/src/test/java/org/apache/qpid/client/ResetMessageListenerTest.java +++ b/java/client/src/test/java/org/apache/qpid/client/ResetMessageListenerTest.java @@ -43,16 +43,13 @@ import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.jndi.PropertiesFileInitialContextFactory; /** - * QPID-293 Setting MessageListener after connection has started can cause messages to be "lost" on a internal delivery queue - * <p/> - * The message delivery process: - * Mina puts a message on _queue in AMQSession and the dispatcher thread take()s - * from here and dispatches to the _consumers. If the _consumer1 doesn't have a message listener set at connection start - * then messages are stored on _synchronousQueue (which needs to be > 1 to pass JMS TCK as multiple consumers on a - * session can run in any order and a synchronous put/poll will block the dispatcher). - * <p/> - * When setting the message listener later the _synchronousQueue is just poll()'ed and the first message delivered - * the remaining messages will be left on the queue and lost, subsequent messages on the session will arrive first. + * QPID-293 Setting MessageListener after connection has started can cause messages to be "lost" on a internal delivery + * queue <p/> The message delivery process: Mina puts a message on _queue in AMQSession and the dispatcher thread + * take()s from here and dispatches to the _consumers. If the _consumer1 doesn't have a message listener set at + * connection start then messages are stored on _synchronousQueue (which needs to be > 1 to pass JMS TCK as multiple + * consumers on a session can run in any order and a synchronous put/poll will block the dispatcher). <p/> When setting + * the message listener later the _synchronousQueue is just poll()'ed and the first message delivered the remaining + * messages will be left on the queue and lost, subsequent messages on the session will arrive first. */ public class ResetMessageListenerTest extends TestCase { @@ -78,6 +75,8 @@ public class ResetMessageListenerTest extends TestCase super.setUp(); TransportConnection.createVMBroker(1); + System.setProperty(AMQSession.IMMEDIATE_PREFETCH, "true"); + InitialContextFactory factory = new PropertiesFileInitialContextFactory(); Hashtable<String, String> env = new Hashtable<String, String>(); @@ -203,7 +202,7 @@ public class ResetMessageListenerTest extends TestCase try { - _clientConnection.stop(); + _clientConnection.stop(); } catch (JMSException e) { @@ -226,7 +225,7 @@ public class ResetMessageListenerTest extends TestCase } } }); - + _clientConnection.start(); } catch (javax.jms.IllegalStateException e) diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/temporaryqueue/TemporaryQueueTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/temporaryqueue/TemporaryQueueTest.java index a177cf86d3..2ba5bed0b1 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/temporaryqueue/TemporaryQueueTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/temporaryqueue/TemporaryQueueTest.java @@ -7,14 +7,20 @@ import javax.jms.MessageProducer; import javax.jms.Session;
import javax.jms.TemporaryQueue;
import javax.jms.TextMessage;
+import javax.jms.Queue;
import junit.framework.TestCase;
+import junit.framework.Assert;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.url.URLSyntaxException;
+import java.util.List;
+import java.util.LinkedList;
+
public class TemporaryQueueTest extends TestCase
{
@@ -35,7 +41,7 @@ public class TemporaryQueueTest extends TestCase protected Connection createConnection() throws AMQException, URLSyntaxException
{
return new AMQConnection(_broker, "guest", "guest",
- "fred", "test");
+ "fred", "test");
}
public void testTempoaryQueue() throws Exception
@@ -50,14 +56,14 @@ public class TemporaryQueueTest extends TestCase producer.send(session.createTextMessage("hello"));
TextMessage tm = (TextMessage) consumer.receive(2000);
assertNotNull(tm);
- assertEquals("hello",tm.getText());
+ assertEquals("hello", tm.getText());
try
{
queue.delete();
fail("Expected JMSException : should not be able to delete while there are active consumers");
}
- catch(JMSException je)
+ catch (JMSException je)
{
; //pass
}
@@ -68,7 +74,7 @@ public class TemporaryQueueTest extends TestCase {
queue.delete();
}
- catch(JMSException je)
+ catch (JMSException je)
{
fail("Unexpected Exception: " + je.getMessage());
}
@@ -76,6 +82,127 @@ public class TemporaryQueueTest extends TestCase conn.close();
}
+ public void tUniqueness() throws JMSException, AMQException, URLSyntaxException
+ {
+ int numProcs = Runtime.getRuntime().availableProcessors();
+ final int threadsProc = 5;
+
+ runUniqueness(1, 10);
+ runUniqueness(numProcs * threadsProc, 10);
+ runUniqueness(numProcs * threadsProc, 100);
+ runUniqueness(numProcs * threadsProc, 500);
+ }
+
+ void runUniqueness(int makers, int queues) throws JMSException, AMQException, URLSyntaxException
+ {
+ Connection connection = createConnection();
+
+ Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+ List<TempQueueMaker> tqList = new LinkedList<TempQueueMaker>();
+
+ //Create Makers
+ for (int m = 0; m < makers; m++)
+ {
+ tqList.add(new TempQueueMaker(session, queues));
+ }
+
+
+ List<Thread> threadList = new LinkedList<Thread>();
+
+ //Create Makers
+ for (TempQueueMaker maker : tqList)
+ {
+ threadList.add(new Thread(maker));
+ }
+
+ //Start threads
+ for (Thread thread : threadList)
+ {
+ thread.start();
+ }
+
+ // Join Threads
+ for (Thread thread : threadList)
+ {
+ try
+ {
+ thread.join();
+ }
+ catch (InterruptedException e)
+ {
+ fail("Couldn't correctly join threads");
+ }
+ }
+
+
+ List<AMQQueue> list = new LinkedList<AMQQueue>();
+
+ // Test values
+ for (TempQueueMaker maker : tqList)
+ {
+ check(maker, list);
+ }
+
+ Assert.assertEquals("Not enough queues made.", makers * queues, list.size());
+
+ connection.close();
+ }
+
+ private void check(TempQueueMaker tq, List<AMQQueue> list)
+ {
+ for (AMQQueue q : tq.getList())
+ {
+ if (list.contains(q))
+ {
+ fail(q + " already exists.");
+ }
+ else
+ {
+ list.add(q);
+ }
+ }
+ }
+
+
+ class TempQueueMaker implements Runnable
+ {
+ List<AMQQueue> _queues;
+ Session _session;
+ private int _count;
+
+
+ TempQueueMaker(Session session, int queues) throws JMSException
+ {
+ _queues = new LinkedList<AMQQueue>();
+
+ _count = queues;
+
+ _session = session;
+ }
+
+ public void run()
+ {
+ int i = 0;
+ try
+ {
+ for (; i < _count; i++)
+ {
+ _queues.add((AMQQueue) _session.createTemporaryQueue());
+ }
+ }
+ catch (JMSException jmse)
+ {
+ //stop
+ }
+ }
+
+ List<AMQQueue> getList()
+ {
+ return _queues;
+ }
+ }
+
public static junit.framework.Test suite()
{
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java index 62234ad21f..d52707d965 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java @@ -181,7 +181,9 @@ public class MessageRequeueTest extends TestCase passed = true; } - /** multiple consumers */ + /** multiple consumers + * Based on code subbmitted by client FT-304 + */ public void testTwoCompetingConsumers() { Consumer c1 = new Consumer(); diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java index efd4a7e9a6..127ae22a10 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/Constants.java @@ -20,8 +20,6 @@ */ package org.apache.qpid.management.ui; -import static org.apache.qpid.management.ui.Constants.CONNECTION_PROTOCOLS; - /** * Contains constants for the application * @author Bhupendra Bhardwaj @@ -86,6 +84,8 @@ public class Constants public final static String ACTION_ADDSERVER = "New Connection"; public final static String ACTION_RECONNECT = "Reconnect"; + public final static String ACTION_CLOSE = "Close Connection"; + public final static String ACTION_EDITATTRIBUTE = "Edit Attribute"; public final static String ACTION_LOGIN = "Login"; public final static String QUEUE_SORT_BY_NAME = "Queue Name"; @@ -125,7 +125,7 @@ public class Constants public final static int OPERATION_IMPACT_ACTIONINFO = 2; public final static int OPERATION_IMPACT_UNKNOWN = 3; - public final static String ERROR_SERVER_CONNECTION = "Server could not be connected"; + public final static String ERROR_SERVER_CONNECTION = "Server Connection Failed"; public final static String INFO_PROTOCOL = "Please select the protocol"; public final static String INFO_HOST_ADDRESS = "Please enter the host address"; public final static String INFO_HOST_PORT = "Please enter the port number"; diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AbstractAction.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AbstractAction.java new file mode 100644 index 0000000000..0101905bbf --- /dev/null +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AbstractAction.java @@ -0,0 +1,58 @@ +package org.apache.qpid.management.ui.actions; + +import static org.apache.qpid.management.ui.Constants.ERROR_SERVER_CONNECTION; + +import org.apache.qpid.management.ui.ApplicationRegistry; +import org.apache.qpid.management.ui.ApplicationWorkbenchAdvisor; +import org.apache.qpid.management.ui.Constants; +import org.apache.qpid.management.ui.jmx.MBeanUtility; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; + +public class AbstractAction +{ + protected IWorkbenchWindow _window; + + /** + * We will cache window object in order to + * be able to provide parent shell for the message dialog. + * @see IWorkbenchWindowActionDelegate#init + */ + public void init(IWorkbenchWindow window) + { + this._window = window; + if (_window.getShell() != null) + { + _window.getShell().setImage(ApplicationRegistry.getImage(Constants.CONSOLE_IMAGE)); + } + } + + protected void handleException(Exception ex, String title, String msg) + { + MBeanUtility.printStackTrace(ex); + if (msg == null) + { + msg = ex.getMessage(); + } + if ((msg == null) && (ex.getCause() != null)) + { + msg = ex.getCause().getMessage(); + } + + if (msg == null) + { + msg = ERROR_SERVER_CONNECTION; + } + + if (title == null) + { + title = ERROR_SERVER_CONNECTION; + } + IStatus status = new Status(IStatus.ERROR, ApplicationWorkbenchAdvisor.PERSPECTIVE_ID, + IStatus.OK, msg, null); + ErrorDialog.openError(_window.getShell(), "Error", title, status); + } +} diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AddServer.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AddServer.java index 0e12c59de4..ff0f42b49e 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AddServer.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/AddServer.java @@ -23,15 +23,11 @@ package org.apache.qpid.management.ui.actions; import static org.apache.qpid.management.ui.Constants.*; import org.apache.qpid.management.ui.ApplicationRegistry; -import org.apache.qpid.management.ui.ApplicationWorkbenchAdvisor; import org.apache.qpid.management.ui.exceptions.InfoRequiredException; import org.apache.qpid.management.ui.views.NavigationView; import org.apache.qpid.management.ui.views.NumberVerifyListener; import org.apache.qpid.management.ui.views.ViewUtility; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -45,12 +41,10 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; -public class AddServer/* extends Action*/ implements IWorkbenchWindowActionDelegate +public class AddServer extends AbstractAction implements IWorkbenchWindowActionDelegate { - private IWorkbenchWindow _window; private static final String[] _domains ={"org.apache.qpid"}; private NavigationView _navigationView; @@ -96,13 +90,11 @@ public class AddServer/* extends Action*/ implements IWorkbenchWindowActionDeleg } catch(InfoRequiredException ex) { - ViewUtility.popupInfoMessage("New connection", ex.getMessage()); + ViewUtility.popupInfoMessage(ACTION_ADDSERVER, ex.getMessage()); } - catch(Exception ex) + catch (Exception ex) { - IStatus status = new Status(IStatus.ERROR, ApplicationWorkbenchAdvisor.PERSPECTIVE_ID, - IStatus.OK, ex.getMessage(), ex.getCause()); - ErrorDialog.openError(_window.getShell(), "Error", ERROR_SERVER_CONNECTION, status); + handleException(ex, null, null); } } } @@ -133,15 +125,7 @@ public class AddServer/* extends Action*/ implements IWorkbenchWindowActionDeleg * @see IWorkbenchWindowActionDelegate#dispose */ public void dispose() { - } - - /** - * We will cache window object in order to - * be able to provide parent shell for the message dialog. - * @see IWorkbenchWindowActionDelegate#init - */ - public void init(IWorkbenchWindow window) { - this._window = window; + } private NavigationView getNavigationView() diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/CloseConnection.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/CloseConnection.java index 3f44274a92..3907424748 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/CloseConnection.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/CloseConnection.java @@ -20,22 +20,16 @@ */ package org.apache.qpid.management.ui.actions; -import org.apache.qpid.management.ui.ApplicationWorkbenchAdvisor; +import static org.apache.qpid.management.ui.Constants.ACTION_CLOSE; import org.apache.qpid.management.ui.exceptions.InfoRequiredException; import org.apache.qpid.management.ui.views.NavigationView; import org.apache.qpid.management.ui.views.ViewUtility; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; -public class CloseConnection implements IWorkbenchWindowActionDelegate -{ - private IWorkbenchWindow _window; - +public class CloseConnection extends AbstractAction implements IWorkbenchWindowActionDelegate +{ public CloseConnection() { @@ -52,13 +46,11 @@ public class CloseConnection implements IWorkbenchWindowActionDelegate } catch(InfoRequiredException ex) { - ViewUtility.popupInfoMessage("Close connection", ex.getMessage()); + ViewUtility.popupInfoMessage(ACTION_CLOSE, ex.getMessage()); } catch(Exception ex) { - IStatus status = new Status(IStatus.ERROR, ApplicationWorkbenchAdvisor.PERSPECTIVE_ID, - IStatus.OK, ex.getMessage(), ex.getCause()); - ErrorDialog.openError(_window.getShell(), "Error", "Server could not be removed", status); + handleException(ex, null, null); } } } @@ -79,15 +71,6 @@ public class CloseConnection implements IWorkbenchWindowActionDelegate * @see IWorkbenchWindowActionDelegate#dispose */ public void dispose() { - } - - /** - * We will cache window object in order to - * be able to provide parent shell for the message dialog. - * @see IWorkbenchWindowActionDelegate#init - */ - public void init(IWorkbenchWindow window) { - this._window = window; - } - + + } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/EditAttribute.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/EditAttribute.java index 0030330b06..69e74898ab 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/EditAttribute.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/EditAttribute.java @@ -20,22 +20,16 @@ */ package org.apache.qpid.management.ui.actions; -import org.apache.qpid.management.ui.ApplicationWorkbenchAdvisor; +import static org.apache.qpid.management.ui.Constants.ACTION_EDITATTRIBUTE; import org.apache.qpid.management.ui.exceptions.InfoRequiredException; import org.apache.qpid.management.ui.views.MBeanView; import org.apache.qpid.management.ui.views.ViewUtility; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; -public class EditAttribute implements IWorkbenchWindowActionDelegate -{ - private IWorkbenchWindow _window; - +public class EditAttribute extends AbstractAction implements IWorkbenchWindowActionDelegate +{ public void run(IAction action) { if(_window != null) @@ -47,13 +41,11 @@ public class EditAttribute implements IWorkbenchWindowActionDelegate } catch(InfoRequiredException ex) { - ViewUtility.popupInfoMessage("Edit Attribute", ex.getMessage()); + ViewUtility.popupInfoMessage(ACTION_EDITATTRIBUTE, ex.getMessage()); } catch(Exception ex) { - IStatus status = new Status(IStatus.ERROR, ApplicationWorkbenchAdvisor.PERSPECTIVE_ID, - IStatus.OK, ex.getMessage(), ex.getCause()); - ErrorDialog.openError(_window.getShell(), "Error", "Attribute could not be edited", status); + handleException(ex, "Attribute could not be edited", null); } } } @@ -74,14 +66,6 @@ public class EditAttribute implements IWorkbenchWindowActionDelegate * @see IWorkbenchWindowActionDelegate#dispose */ public void dispose() { - } - - /** - * We will cache window object in order to - * be able to provide parent shell for the message dialog. - * @see IWorkbenchWindowActionDelegate#init - */ - public void init(IWorkbenchWindow window) { - this._window = window; + } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java index 9aa265ab3c..3c0dea586e 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java @@ -20,19 +20,20 @@ */ package org.apache.qpid.management.ui.actions; -import static org.apache.qpid.management.ui.Constants.*; +import static org.apache.qpid.management.ui.Constants.ACTION_LOGIN; +import static org.apache.qpid.management.ui.Constants.CONSOLE_IMAGE; +import static org.apache.qpid.management.ui.Constants.INFO_PASSWORD; +import static org.apache.qpid.management.ui.Constants.INFO_USERNAME; +import static org.apache.qpid.management.ui.Constants.PASSWORD; +import static org.apache.qpid.management.ui.Constants.USERNAME; import org.apache.qpid.management.ui.ApplicationRegistry; -import org.apache.qpid.management.ui.ApplicationWorkbenchAdvisor; import org.apache.qpid.management.ui.Constants; import org.apache.qpid.management.ui.exceptions.InfoRequiredException; import org.apache.qpid.management.ui.views.NavigationView; import org.apache.qpid.management.ui.views.TreeObject; import org.apache.qpid.management.ui.views.ViewUtility; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; @@ -40,18 +41,15 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; -public class ReconnectServer implements IWorkbenchWindowActionDelegate +public class ReconnectServer extends AbstractAction implements IWorkbenchWindowActionDelegate { - private IWorkbenchWindow _window; private NavigationView _navigationView; private String _title; private String _serverName; @@ -80,16 +78,6 @@ public class ReconnectServer implements IWorkbenchWindowActionDelegate { } - - /** - * We will cache window object in order to - * be able to provide parent shell for the message dialog. - * @see IWorkbenchWindowActionDelegate#init - */ - public void init(IWorkbenchWindow window) - { - this._window = window; - } private NavigationView getNavigationView() { @@ -126,11 +114,9 @@ public class ReconnectServer implements IWorkbenchWindowActionDelegate { ViewUtility.popupInfoMessage("Reconnect Qpid server", ex.getMessage()); } - catch(Exception ex) + catch (Exception ex) { - IStatus status = new Status(IStatus.ERROR, ApplicationWorkbenchAdvisor.PERSPECTIVE_ID, - IStatus.OK, ex.getMessage(), ex.getCause()); - ErrorDialog.openError(_window.getShell(), "Error", ERROR_SERVER_CONNECTION, status); + handleException(ex, null, null); } } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java index a2335c5841..b76c36c649 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/Refresh.java @@ -25,17 +25,14 @@ import org.apache.qpid.management.ui.views.MBeanView; import org.apache.qpid.management.ui.views.NavigationView; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; /** * This action refreshes both the views -Navigation and MBeanView * @author Bhupendra Bhardwaj */ -public class Refresh implements IWorkbenchWindowActionDelegate +public class Refresh extends AbstractAction implements IWorkbenchWindowActionDelegate { - private IWorkbenchWindow _window; - /** * Selection in the workbench has been changed. We * can change the state of the 'real' action here @@ -57,16 +54,6 @@ public class Refresh implements IWorkbenchWindowActionDelegate { } - - /** - * We will cache window object in order to - * be able to provide parent shell for the message dialog. - * @see IWorkbenchWindowActionDelegate#init - */ - public void init(IWorkbenchWindow window) - { - this._window = window; - } public void run(IAction action) { diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/RemoveServer.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/RemoveServer.java index 189f0f811b..f8878c44a1 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/RemoveServer.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/RemoveServer.java @@ -20,22 +20,15 @@ */ package org.apache.qpid.management.ui.actions; -import org.apache.qpid.management.ui.ApplicationWorkbenchAdvisor; import org.apache.qpid.management.ui.exceptions.InfoRequiredException; import org.apache.qpid.management.ui.views.NavigationView; import org.apache.qpid.management.ui.views.ViewUtility; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; -public class RemoveServer implements IWorkbenchWindowActionDelegate -{ - private IWorkbenchWindow _window; - +public class RemoveServer extends AbstractAction implements IWorkbenchWindowActionDelegate +{ /** * Selection in the workbench has been changed. We * can change the state of the 'real' action here @@ -57,16 +50,6 @@ public class RemoveServer implements IWorkbenchWindowActionDelegate { } - - /** - * We will cache window object in order to - * be able to provide parent shell for the message dialog. - * @see IWorkbenchWindowActionDelegate#init - */ - public void init(IWorkbenchWindow window) - { - this._window = window; - } public void run(IAction action) { @@ -83,9 +66,7 @@ public class RemoveServer implements IWorkbenchWindowActionDelegate } catch(Exception ex) { - IStatus status = new Status(IStatus.ERROR, ApplicationWorkbenchAdvisor.PERSPECTIVE_ID, - IStatus.OK, ex.getMessage(), ex.getCause()); - ErrorDialog.openError(_window.getShell(), "Error", "Server could not be removed", status); + handleException(ex, "Server could not be removed", null); } } } diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/MBeanUtility.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/MBeanUtility.java index 41db11c10e..2d1883533b 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/MBeanUtility.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/jmx/MBeanUtility.java @@ -20,7 +20,6 @@ */ package org.apache.qpid.management.ui.jmx; -import java.io.IOException; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; @@ -149,11 +148,6 @@ public class MBeanUtility ViewUtility.popupErrorMessage("Error", "Managed Object is null \n" + ex.toString()); printStackTrace(ex); } - else if (ex instanceof IOException) - { - ViewUtility.popupErrorMessage(mbean.getInstanceName(), "IO Error occured \n" + ex.toString()); - printStackTrace(ex); - } else if (ex instanceof ReflectionException) { ViewUtility.popupErrorMessage(mbean.getInstanceName(), "Server has thrown error \n" + ex.toString()); @@ -462,7 +456,7 @@ public class MBeanUtility } } - private static void printStackTrace(Throwable ex) + public static void printStackTrace(Throwable ex) { if (ApplicationRegistry.debug) { diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/AttributesTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/AttributesTabControl.java index a7e8bbfc4c..1ffe34d9c5 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/AttributesTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/AttributesTabControl.java @@ -21,6 +21,7 @@ package org.apache.qpid.management.ui.views; import static org.apache.qpid.management.ui.Constants.*; + import org.apache.qpid.management.ui.ApplicationRegistry; import org.apache.qpid.management.ui.ManagedBean; import org.apache.qpid.management.ui.jmx.JMXServerRegistry; @@ -51,8 +52,6 @@ import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.VerifyEvent; -import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTypeTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTypeTabControl.java index a8a96e0b5a..31b6cc6221 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTypeTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/MBeanTypeTabControl.java @@ -1,9 +1,13 @@ package org.apache.qpid.management.ui.views; +import static org.apache.qpid.management.ui.Constants.BUTTON_REFRESH; +import static org.apache.qpid.management.ui.Constants.FONT_BOLD; +import static org.apache.qpid.management.ui.Constants.FONT_ITALIC; +import static org.apache.qpid.management.ui.Constants.FONT_NORMAL; + import java.util.Collections; import java.util.HashMap; -import static org.apache.qpid.management.ui.Constants.*; import org.apache.qpid.management.ui.ApplicationRegistry; import org.apache.qpid.management.ui.ManagedBean; import org.apache.qpid.management.ui.jmx.MBeanUtility; diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java index 68f95e01f0..e5f99c2f7b 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/NavigationView.java @@ -20,6 +20,8 @@ */ package org.apache.qpid.management.ui.views; +import static org.apache.qpid.management.ui.Constants.*; + import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -27,14 +29,12 @@ import java.util.HashMap; import java.util.List; import org.apache.qpid.management.ui.ApplicationRegistry; -import static org.apache.qpid.management.ui.Constants.*; import org.apache.qpid.management.ui.ManagedBean; import org.apache.qpid.management.ui.ManagedServer; import org.apache.qpid.management.ui.ServerRegistry; import org.apache.qpid.management.ui.exceptions.InfoRequiredException; import org.apache.qpid.management.ui.jmx.JMXServerRegistry; import org.apache.qpid.management.ui.jmx.MBeanUtility; - import org.eclipse.jface.preference.PreferenceStore; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; @@ -48,7 +48,6 @@ import org.eclipse.jface.viewers.TreeExpansionEvent; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerSorter; - import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; @@ -63,7 +62,6 @@ import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; - import org.eclipse.ui.part.ViewPart; /** @@ -216,10 +214,9 @@ public class NavigationView extends ViewPart ServerRegistry serverRegistry = new JMXServerRegistry(server); ApplicationRegistry.addServer(server, serverRegistry); } - catch (Exception ex) + catch (IOException ex) { - ex.printStackTrace(); - throw new Exception("Error in connecting to Qpid broker at " + server.getUrl(), ex); + throw (Exception)ex.getCause(); } } @@ -274,7 +271,15 @@ public class NavigationView extends ViewPart _managedServerMap.put(managedServer, serverNode); // populate the server tree - populateServer(serverNode); + try + { + populateServer(serverNode); + } + catch (SecurityException ex) + { + disconnect(managedServer); + throw ex; + } // Add the Queue/Exchanges/Connections from config file into the navigation tree addConfiguredItems(managedServer); @@ -413,38 +418,30 @@ public class NavigationView extends ViewPart * the given server node. * @param serverNode */ - private void populateServer(TreeObject serverNode) + private void populateServer(TreeObject serverNode) throws Exception { ManagedServer server = (ManagedServer) serverNode.getManagedObject(); String domain = server.getDomain(); - try + if (!domain.equals(ALL)) + { + TreeObject domainNode = new TreeObject(domain, NODE_TYPE_DOMAIN); + domainNode.setParent(serverNode); + + populateDomain(domainNode); + } + else { - if (!domain.equals(ALL)) + List<TreeObject> domainList = new ArrayList<TreeObject>(); + List<String> domains = MBeanUtility.getAllDomains(server); + + for (String domainName : domains) { - TreeObject domainNode = new TreeObject(domain, NODE_TYPE_DOMAIN); + TreeObject domainNode = new TreeObject(domainName, NODE_TYPE_DOMAIN); domainNode.setParent(serverNode); + domainList.add(domainNode); populateDomain(domainNode); } - else - { - List<TreeObject> domainList = new ArrayList<TreeObject>(); - List<String> domains = MBeanUtility.getAllDomains(server); - ; - for (String domainName : domains) - { - TreeObject domainNode = new TreeObject(domainName, NODE_TYPE_DOMAIN); - domainNode.setParent(serverNode); - - domainList.add(domainNode); - populateDomain(domainNode); - } - } - } - catch (Exception ex) - { - System.out.println("\nError in connecting to Qpid broker "); - ex.printStackTrace(); } } @@ -726,6 +723,11 @@ public class NavigationView extends ViewPart { TreeObject selectedNode = getSelectedServerNode(); ManagedServer managedServer = (ManagedServer) selectedNode.getManagedObject(); + disconnect(managedServer); + } + + private void disconnect(ManagedServer managedServer) throws Exception + { if (!_managedServerMap.containsKey(managedServer)) { return; @@ -763,8 +765,17 @@ public class NavigationView extends ViewPart // put the server in the managed server map _managedServerMap.put(managedServer, selectedNode); - // populate the server tree now - populateServer(selectedNode); + try + { + // populate the server tree now + populateServer(selectedNode); + } + catch (SecurityException ex) + { + disconnect(managedServer); + throw ex; + } + // Add the Queue/Exchanges/Connections from config file into the navigation tree addConfiguredItems(managedServer); diff --git a/java/systests/pom.xml b/java/systests/pom.xml index 614166754c..d9d07ed6f9 100644 --- a/java/systests/pom.xml +++ b/java/systests/pom.xml @@ -62,7 +62,8 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> - <skip>true</skip> + <testSourceDirectory>${basedir}/src/main</testSourceDirectory> + <testClassesDirectory>target/classes</testClassesDirectory> </configuration> </plugin> @@ -89,3 +90,4 @@ </resources> </build> </project> + diff --git a/java/systests/src/main/java/org/apache/qpid/server/ack/TxAckTest.java b/java/systests/src/main/java/org/apache/qpid/server/ack/TxAckTest.java index 9fcd88b1a8..3ee8277eba 100644 --- a/java/systests/src/main/java/org/apache/qpid/server/ack/TxAckTest.java +++ b/java/systests/src/main/java/org/apache/qpid/server/ack/TxAckTest.java @@ -24,6 +24,8 @@ import junit.framework.TestCase; import org.apache.qpid.AMQException; import org.apache.qpid.framing.BasicPublishBody; import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.framing.ContentHeaderBody; +import org.apache.qpid.framing.AMQFrameDecodingException; import org.apache.qpid.framing.abstraction.MessagePublishInfo; import org.apache.qpid.server.RequiredDeliveryException; import org.apache.qpid.server.queue.AMQMessage; @@ -102,7 +104,7 @@ public class TxAckTest extends TestCase _storeContext, null, new LinkedList<RequiredDeliveryException>(), new HashSet<Long>()); - for(int i = 0; i < messageCount; i++) + for (int i = 0; i < messageCount; i++) { long deliveryTag = i + 1; @@ -144,7 +146,7 @@ public class TxAckTest extends TestCase private void assertCount(List<Long> tags, int expected) { - for(long tag : tags) + for (long tag : tags) { UnacknowledgedMessage u = _map.get(tag); assertTrue("Message not found for tag " + tag, u != null); @@ -161,6 +163,7 @@ public class TxAckTest extends TestCase assertCount(_unacked, 0); } + void undoPrepare() { _op.consolidate(); @@ -175,7 +178,6 @@ public class TxAckTest extends TestCase _op.consolidate(); _op.commit(_storeContext); - //check acked messages are removed from map Set<Long> keys = new HashSet<Long>(_map.getDeliveryTags()); keys.retainAll(_acked); @@ -195,6 +197,20 @@ public class TxAckTest extends TestCase TestMessage(long tag, long messageId, MessagePublishInfo publishBody, TransactionalContext txnContext) { super(messageId, publishBody, txnContext); + try + { + setContentHeaderBody(new ContentHeaderBody() + { + public int getSize() + { + return 1; + } + }); + } + catch (AMQException e) + { + // won't happen + } _tag = tag; } diff --git a/java/systests/src/main/java/org/apache/qpid/server/channel/MaxChannelsTest.java b/java/systests/src/main/java/org/apache/qpid/server/channel/MaxChannelsTest.java new file mode 100644 index 0000000000..5ddccb8a7b --- /dev/null +++ b/java/systests/src/main/java/org/apache/qpid/server/channel/MaxChannelsTest.java @@ -0,0 +1,75 @@ +/* + * + * Copyright (c) 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.qpid.server.protocol; + +import junit.framework.TestCase; +import org.apache.mina.common.IoSession; +import org.apache.qpid.codec.AMQCodecFactory; +import org.apache.qpid.server.AMQChannel; +import org.apache.qpid.server.virtualhost.VirtualHost; +import org.apache.qpid.server.registry.IApplicationRegistry; +import org.apache.qpid.server.registry.ApplicationRegistry; +import org.apache.qpid.server.exchange.ExchangeRegistry; +import org.apache.qpid.server.queue.QueueRegistry; +import org.apache.qpid.server.queue.AMQQueue; +import org.apache.qpid.server.store.MessageStore; +import org.apache.qpid.server.store.SkeletonMessageStore; +import org.apache.qpid.AMQException; +import org.apache.qpid.protocol.AMQConstant; +import org.apache.qpid.framing.AMQShortString; + +import javax.management.JMException; + +/** Test class to test MBean operations for AMQMinaProtocolSession. */ +public class MaxChannelsTest extends TestCase +{ +// private MessageStore _messageStore = new SkeletonMessageStore(); + + public void testChannels() throws Exception + { + IApplicationRegistry appRegistry = ApplicationRegistry.getInstance(); + AMQMinaProtocolSession _protocolSession = new AMQMinaProtocolSession(new MockIoSession(), + appRegistry.getVirtualHostRegistry(), + new AMQCodecFactory(true), + null); + _protocolSession.setVirtualHost(appRegistry.getVirtualHostRegistry().getVirtualHost("test")); + + // check the channel count is correct + int channelCount = _protocolSession.getChannels().size(); + assertEquals("Initial channel count wrong", 0, channelCount); + + long maxChannels = 10L; + _protocolSession.setMaximumNumberOfChannels(maxChannels); + assertEquals("Number of channels not correctly set.", new Long(maxChannels), _protocolSession.getMaximumNumberOfChannels()); + + + try + { + for (long currentChannel = 0L; currentChannel < maxChannels; currentChannel++) + { + _protocolSession.addChannel(new AMQChannel(_protocolSession, (int) currentChannel, null, null)); + } + } + catch (AMQException e) + { + assertEquals("Wrong exception recevied.", e.getErrorCode(), AMQConstant.NOT_ALLOWED); + } + assertEquals("Maximum number of channels not set.", new Long(maxChannels), new Long(_protocolSession.getChannels().size())); + } + +} diff --git a/java/systests/src/main/java/org/apache/qpid/server/exchange/ReturnUnroutableMandatoryMessageTest.java b/java/systests/src/main/java/org/apache/qpid/server/exchange/ReturnUnroutableMandatoryMessageTest.java index 87491ed3d3..ca352b2fd7 100644 --- a/java/systests/src/main/java/org/apache/qpid/server/exchange/ReturnUnroutableMandatoryMessageTest.java +++ b/java/systests/src/main/java/org/apache/qpid/server/exchange/ReturnUnroutableMandatoryMessageTest.java @@ -22,6 +22,8 @@ public class ReturnUnroutableMandatoryMessageTest extends TestCase implements Ex private static final Logger _logger = Logger.getLogger(ReturnUnroutableMandatoryMessageTest.class);
private final List<Message> _bouncedMessageList = Collections.synchronizedList(new ArrayList<Message>());
+ private static final String VIRTUALHOST = "test";
+ private static final String BROKER = "vm://:1";
static
{
@@ -53,10 +55,10 @@ public class ReturnUnroutableMandatoryMessageTest extends TestCase implements Ex *
* @throws Exception
*/
- public void testReturnUnroutableMandatoryMessage() throws Exception
+ public void testReturnUnroutableMandatoryMessage_HEADERS() throws Exception
{
_bouncedMessageList.clear();
- Connection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test");
+ Connection con = new AMQConnection(BROKER, "guest", "guest", "consumer1", VIRTUALHOST);
AMQSession consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
@@ -70,7 +72,7 @@ public class ReturnUnroutableMandatoryMessageTest extends TestCase implements Ex //((AMQSession) consumerSession).declareExchangeSynch(ExchangeDefaults.HEADERS_EXCHANGE_NAME, ExchangeDefaults.HEADERS_EXCHANGE_CLASS);
// This is the default now
- Connection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "/test");
+ Connection con2 = new AMQConnection(BROKER, "guest", "guest", "producer1", VIRTUALHOST);
con2.setExceptionListener(this);
AMQSession producerSession = (AMQSession) con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
@@ -127,6 +129,138 @@ public class ReturnUnroutableMandatoryMessageTest extends TestCase implements Ex }
+ public void testReturnUnroutableMandatoryMessage_QUEUE() throws Exception
+ {
+ _bouncedMessageList.clear();
+ Connection con = new AMQConnection(BROKER, "guest", "guest", "consumer1", VIRTUALHOST);
+
+
+ AMQSession consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+ AMQQueue valid_queue = new AMQQueue(ExchangeDefaults.DIRECT_EXCHANGE_CLASS, "testReturnUnroutableMandatoryMessage_QUEUE");
+ AMQQueue invalid_queue = new AMQQueue(ExchangeDefaults.DIRECT_EXCHANGE_CLASS, "testReturnUnroutableMandatoryMessage_QUEUE_INVALID");
+ MessageConsumer consumer = consumerSession.createConsumer(valid_queue);
+
+ //force synch to ensure the consumer has resulted in a bound queue
+ //((AMQSession) consumerSession).declareExchangeSynch(ExchangeDefaults.HEADERS_EXCHANGE_NAME, ExchangeDefaults.HEADERS_EXCHANGE_CLASS);
+ // This is the default now
+
+ Connection con2 = new AMQConnection(BROKER, "guest", "guest", "producer1", VIRTUALHOST);
+
+ con2.setExceptionListener(this);
+ AMQSession producerSession = (AMQSession) con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+ // Need to start the "producer" connection in order to receive bounced messages
+ _logger.info("Starting producer connection");
+ con2.start();
+
+
+ MessageProducer nonMandatoryProducer = producerSession.createProducer(valid_queue, false, false);
+ MessageProducer mandatoryProducer = producerSession.createProducer(invalid_queue);
+
+ // First test - should be routed
+ _logger.info("Sending non-mandatory message");
+ TextMessage msg1 = producerSession.createTextMessage("msg1");
+ nonMandatoryProducer.send(msg1);
+
+ // Second test - should be bounced
+ _logger.info("Sending non-routable mandatory message");
+ TextMessage msg2 = producerSession.createTextMessage("msg2");
+ mandatoryProducer.send(msg2);
+
+
+ _logger.info("Starting consumer connection");
+ con.start();
+ TextMessage tm = (TextMessage) consumer.receive(1000L);
+
+ assertTrue("No message routed to receiver", tm != null);
+ assertTrue("Wrong message routed to receiver: " + tm.getText(), "msg1".equals(tm.getText()));
+
+ try
+ {
+ Thread.sleep(1000L);
+ }
+ catch (InterruptedException e)
+ {
+ ;
+ }
+
+ assertTrue("Wrong number of messages bounced (expect 1): " + _bouncedMessageList.size(), _bouncedMessageList.size() == 1);
+ Message m = _bouncedMessageList.get(0);
+ assertTrue("Wrong message bounced: " + m.toString(), m.toString().contains("msg2"));
+
+
+ con.close();
+ con2.close();
+ }
+
+
+ public void testReturnUnroutableMandatoryMessage_TOPIC() throws Exception
+ {
+ _bouncedMessageList.clear();
+ Connection con = new AMQConnection(BROKER, "guest", "guest", "consumer1", VIRTUALHOST);
+
+
+ AMQSession consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+ AMQTopic valid_topic = new AMQTopic(ExchangeDefaults.TOPIC_EXCHANGE_CLASS, "test.Return.Unroutable.Mandatory.Message.TOPIC");
+ AMQTopic invalid_topic = new AMQTopic(ExchangeDefaults.TOPIC_EXCHANGE_CLASS, "test.Return.Unroutable.Mandatory.Message.TOPIC.invalid");
+ MessageConsumer consumer = consumerSession.createConsumer(valid_topic);
+
+ //force synch to ensure the consumer has resulted in a bound queue
+ //((AMQSession) consumerSession).declareExchangeSynch(ExchangeDefaults.HEADERS_EXCHANGE_NAME, ExchangeDefaults.HEADERS_EXCHANGE_CLASS);
+ // This is the default now
+
+ Connection con2 = new AMQConnection(BROKER, "guest", "guest", "producer1", VIRTUALHOST);
+
+ con2.setExceptionListener(this);
+ AMQSession producerSession = (AMQSession) con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+ // Need to start the "producer" connection in order to receive bounced messages
+ _logger.info("Starting producer connection");
+ con2.start();
+
+
+ MessageProducer nonMandatoryProducer = producerSession.createProducer(valid_topic, false, false);
+ MessageProducer mandatoryProducer = producerSession.createProducer(invalid_topic);
+
+ // First test - should be routed
+ _logger.info("Sending non-mandatory message");
+ TextMessage msg1 = producerSession.createTextMessage("msg1");
+ nonMandatoryProducer.send(msg1);
+
+ // Second test - should be bounced
+ _logger.info("Sending non-routable mandatory message");
+ TextMessage msg2 = producerSession.createTextMessage("msg2");
+ mandatoryProducer.send(msg2);
+
+
+ _logger.info("Starting consumer connection");
+ con.start();
+ TextMessage tm = (TextMessage) consumer.receive(1000L);
+
+ assertTrue("No message routed to receiver", tm != null);
+ assertTrue("Wrong message routed to receiver: " + tm.getText(), "msg1".equals(tm.getText()));
+
+ try
+ {
+ Thread.sleep(1000L);
+ }
+ catch (InterruptedException e)
+ {
+ ;
+ }
+
+ assertTrue("Wrong number of messages bounced (expect 1): " + _bouncedMessageList.size(), _bouncedMessageList.size() == 1);
+ Message m = _bouncedMessageList.get(0);
+ assertTrue("Wrong message bounced: " + m.toString(), m.toString().contains("msg2"));
+
+
+ con.close();
+ con2.close();
+ }
+
+
public static junit.framework.Test suite()
{
return new junit.framework.TestSuite(ReturnUnroutableMandatoryMessageTest.class);
diff --git a/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java b/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java index 52eb5414ff..228bd1ec6f 100644 --- a/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java +++ b/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java @@ -16,7 +16,7 @@ public class HeapExhaustion extends TestCase { private static final Logger _logger = Logger.getLogger(HeapExhaustion.class); - protected QpidClientConnection conn; + protected QpidClientConnection conn; protected final String BROKER = "localhost"; protected final String vhost = "/test"; protected final String queue = "direct://amq.direct//queue"; @@ -65,7 +65,7 @@ public class HeapExhaustion extends TestCase conn.put(queue, payload, 1); copies++; total += size; - _logger.info("put copy " + copies + " OK for total bytes: " + total); + System.out.println("put copy " + copies + " OK for total bytes: " + total); } } @@ -85,7 +85,7 @@ public class HeapExhaustion extends TestCase conn.put(queue, payload, 1); copies++; total += size; - _logger.debug("put copy " + copies + " OK for total bytes: " + total); + System.out.println("put copy " + copies + " OK for total bytes: " + total); Thread.sleep(200); } } diff --git a/java/systests/src/main/java/org/apache/qpid/server/queue/ConcurrencyTest.java b/java/systests/src/main/java/org/apache/qpid/server/queue/ConcurrencyTestDisabled.java index 4971db2d28..068f37574d 100644 --- a/java/systests/src/main/java/org/apache/qpid/server/queue/ConcurrencyTest.java +++ b/java/systests/src/main/java/org/apache/qpid/server/queue/ConcurrencyTestDisabled.java @@ -34,7 +34,7 @@ import java.util.concurrent.Executor; * Tests delivery in the face of concurrent incoming _messages, subscription alterations * and attempts to asynchronously process queued _messages. */ -public class ConcurrencyTest extends MessageTestHelper +public class ConcurrencyTestDisabled extends MessageTestHelper { private final Random random = new Random(); @@ -55,7 +55,7 @@ public class ConcurrencyTest extends MessageTestHelper private boolean failed; private VirtualHost _virtualHost; - public ConcurrencyTest() throws Exception + public ConcurrencyTestDisabled() throws Exception { IApplicationRegistry applicationRegistry = ApplicationRegistry.getInstance(); @@ -259,7 +259,7 @@ public class ConcurrencyTest extends MessageTestHelper public static junit.framework.Test suite() { - return new junit.framework.TestSuite(ConcurrencyTest.class); + return new junit.framework.TestSuite(ConcurrencyTestDisabled.class); } } diff --git a/java/systests/src/main/java/org/apache/qpid/server/queue/MessageTestHelper.java b/java/systests/src/main/java/org/apache/qpid/server/queue/MessageTestHelper.java index 03a56df487..88272023e8 100644 --- a/java/systests/src/main/java/org/apache/qpid/server/queue/MessageTestHelper.java +++ b/java/systests/src/main/java/org/apache/qpid/server/queue/MessageTestHelper.java @@ -29,6 +29,7 @@ import org.apache.qpid.server.store.SkeletonMessageStore; import org.apache.qpid.server.store.StoreContext; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.util.TestApplicationRegistry; +import org.apache.qpid.server.util.NullApplicationRegistry; import org.apache.qpid.server.txn.TransactionalContext; import org.apache.qpid.server.txn.NonTransactionalContext; import org.apache.qpid.server.RequiredDeliveryException; @@ -51,7 +52,7 @@ class MessageTestHelper extends TestCase MessageTestHelper() throws Exception { - ApplicationRegistry.initialise(new TestApplicationRegistry()); + ApplicationRegistry.initialise(new NullApplicationRegistry()); } AMQMessage message() throws AMQException diff --git a/java/systests/src/main/java/org/apache/qpid/server/queue/PersistentTest.java b/java/systests/src/main/java/org/apache/qpid/server/queue/PersistentTestManual.java index 4ad10b68ff..5abbbd2aae 100644 --- a/java/systests/src/main/java/org/apache/qpid/server/queue/PersistentTest.java +++ b/java/systests/src/main/java/org/apache/qpid/server/queue/PersistentTestManual.java @@ -37,9 +37,9 @@ import javax.jms.TextMessage; import java.io.IOException; import java.util.Properties; -public class PersistentTest +public class PersistentTestManual { - private static final Logger _logger = Logger.getLogger(PersistentTest.class); + private static final Logger _logger = Logger.getLogger(PersistentTestManual.class); private static final String QUEUE = "direct://amq.direct//PersistentTest-Queue2?durable='true',exclusive='true'"; @@ -56,7 +56,7 @@ public class PersistentTest private String _password; private String _virtualpath; - public PersistentTest(Properties overrides) + public PersistentTestManual(Properties overrides) { properties = new Properties(defaults); properties.putAll(overrides); @@ -257,12 +257,12 @@ public class PersistentTest public static void main(String[] args) { - PersistentTest test; + PersistentTestManual test; Properties options = CommandLineParser.processCommandLine(args, new CommandLineParser(new String[][]{})); - test = new PersistentTest(options); + test = new PersistentTestManual(options); try { test.test(); diff --git a/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java b/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java index 31fd77691d..540c91ddaf 100644 --- a/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java +++ b/java/systests/src/main/java/org/apache/qpid/test/VMTestCase.java @@ -114,4 +114,9 @@ public class VMTestCase extends TestCase TransportConnection.killVMBroker(1); super.tearDown(); } + + public void testDummyinVMTestCase() + { + // keep maven happy + } } diff --git a/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTest.java b/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTest.java index ac65eec979..ec9df8f1b3 100644 --- a/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTest.java +++ b/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTest.java @@ -20,8 +20,8 @@ */ package org.apache.qpid.test.client; -import org.apache.qpid.test.VMTestCase; import org.apache.log4j.Logger; +import org.apache.qpid.test.VMTestCase; import javax.jms.Queue; import javax.jms.ConnectionFactory; @@ -36,6 +36,8 @@ import javax.jms.QueueReceiver; import javax.jms.Message; import java.util.Enumeration; +import junit.framework.TestCase; + public class QueueBrowserTest extends VMTestCase { private static final Logger _logger = Logger.getLogger(QueueBrowserTest.class); @@ -87,7 +89,7 @@ public class QueueBrowserTest extends VMTestCase * */ - public void queueBrowserMsgsRemainOnQueueTest() throws JMSException + public void testQueueBrowserMsgsRemainOnQueue() throws JMSException { // create QueueBrowser |
