diff options
| author | Robert Godfrey <rgodfrey@apache.org> | 2014-04-28 10:38:02 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org> | 2014-04-28 10:38:02 +0000 |
| commit | 7505243f188a9b978a472090f582baea9d96a318 (patch) | |
| tree | 80f51574d8a638345310ee239277fa00dc1913ab /qpid/java | |
| parent | e93df1d676c748f942daaf5fb0c4d4dd4ea867a2 (diff) | |
| download | qpid-python-7505243f188a9b978a472090f582baea9d96a318.tar.gz | |
QPID-5665 : Address review comments from Alex Rudyy
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1590593 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
6 files changed, 80 insertions, 140 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java index 018b72c805..95bd2f582d 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java @@ -1687,7 +1687,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im } } - protected final static class DuplicateIdException extends RuntimeException + protected final static class DuplicateIdException extends IllegalArgumentException { public DuplicateIdException(final ConfiguredObject<?> child) { @@ -1695,7 +1695,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im } } - protected final static class DuplicateNameException extends RuntimeException + protected final static class DuplicateNameException extends IllegalArgumentException { private final String _name; public DuplicateNameException(final ConfiguredObject<?> child) diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/VirtualHost.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/VirtualHost.java index 2936bc62d0..0da3ceea87 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/VirtualHost.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/VirtualHost.java @@ -137,8 +137,7 @@ public interface VirtualHost<X extends VirtualHost<X, Q, E>, Q extends Queue<?>, Collection<Q> getQueues(); Collection<E> getExchanges(); - E createExchange(String name, State initialState, boolean durable, - LifetimePolicy lifetime, String type, Map<String, Object> attributes) + E createExchange(Map<String, Object> attributes) throws AccessControlException, IllegalArgumentException; Q createQueue(Map<String, Object> attributes) diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java index d9104bfbe0..dd97b0cba9 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java @@ -98,8 +98,6 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte private static final int HOUSEKEEPING_SHUTDOWN_TIMEOUT = 5; - private final long _createTime = System.currentTimeMillis(); - private ScheduledThreadPoolExecutor _houseKeepingTasks; private final Broker<?> _broker; @@ -391,14 +389,6 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte } } - public String setType(final String currentType, final String desiredType) - throws IllegalStateException, AccessControlException - { - throw new IllegalStateException(); - } - - - @Override public State getState() { @@ -566,11 +556,6 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte return _houseKeepingTasks.getActiveCount(); } - public long getCreateTime() - { - return _createTime; - } - @Override public AMQQueue<?> getQueue(String name) { @@ -682,98 +667,6 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte return children; } - public ExchangeImpl<?> createExchange(final String name, - final State initialState, - final boolean durable, - final LifetimePolicy lifetime, - final String type, - final Map<String, Object> attributes) - throws AccessControlException, IllegalArgumentException - { - checkVHostStateIsActive(); - - try - { - String alternateExchange = null; - if(attributes.containsKey(Exchange.ALTERNATE_EXCHANGE)) - { - Object altExchangeObject = attributes.get(Exchange.ALTERNATE_EXCHANGE); - if(altExchangeObject instanceof Exchange) - { - alternateExchange = ((Exchange) altExchangeObject).getName(); - } - else if(altExchangeObject instanceof UUID) - { - for(Exchange ex : getExchanges()) - { - if(altExchangeObject.equals(ex.getId())) - { - alternateExchange = ex.getName(); - break; - } - } - } - else if(altExchangeObject instanceof String) - { - - for(Exchange ex : getExchanges()) - { - if(altExchangeObject.equals(ex.getName())) - { - alternateExchange = ex.getName(); - break; - } - } - if(alternateExchange == null) - { - try - { - UUID id = UUID.fromString(altExchangeObject.toString()); - for(Exchange ex : getExchanges()) - { - if(id.equals(ex.getId())) - { - alternateExchange = ex.getName(); - break; - } - } - } - catch(IllegalArgumentException e) - { - // ignore - } - - } - } - } - Map<String,Object> attributes1 = new HashMap<String, Object>(); - - attributes1.put(ID, null); - attributes1.put(NAME, name); - attributes1.put(Exchange.TYPE, type); - attributes1.put(Exchange.DURABLE, durable); - attributes1.put(Exchange.LIFETIME_POLICY, - lifetime != null && lifetime != LifetimePolicy.PERMANENT - ? LifetimePolicy.DELETE_ON_NO_LINKS : LifetimePolicy.PERMANENT); - attributes1.put(Exchange.ALTERNATE_EXCHANGE, alternateExchange); - ExchangeImpl exchange = createExchange(attributes1); - return exchange; - - } - catch(ExchangeExistsException e) - { - throw new IllegalArgumentException("Exchange with name '" + name + "' already exists"); - } - catch(ReservedExchangeNameException e) - { - throw new UnsupportedOperationException("'" + name + "' is a reserved exchange name"); - } - catch(AMQUnknownExchangeType e) - { - throw new IllegalArgumentException(e); - } - } - @Override public ExchangeImpl createExchange(Map<String,Object> attributes) @@ -1247,15 +1140,6 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte { return getState(); } - else if(SUPPORTED_EXCHANGE_TYPES.equals(name)) - { - return getObjectFactory().getSupportedTypes(Exchange.class); - } - else if(SUPPORTED_QUEUE_TYPES.equals(name)) - { - // TODO - } - return super.getAttribute(name); } @@ -1268,8 +1152,7 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte @Override public Collection<String> getSupportedQueueTypes() { - // TODO - return null; + return getObjectFactory().getSupportedTypes(Queue.class); } @Override diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java index 33706d093c..f7bb58c736 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java @@ -404,18 +404,6 @@ public class MockVirtualHost implements VirtualHostImpl<MockVirtualHost, AMQQueu return null; } - @Override - public ExchangeImpl<?> createExchange(final String name, - final State initialState, - final boolean durable, - final LifetimePolicy lifetime, - final String type, - final Map<String, Object> attributes) - throws AccessControlException, IllegalArgumentException - { - return null; - } - public SecurityManager getSecurityManager() { return null; diff --git a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java index a7f2ec3257..3fdee24ff8 100644 --- a/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java +++ b/qpid/java/broker-plugins/management-jmx/src/main/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBean.java @@ -42,14 +42,16 @@ import org.apache.qpid.management.common.mbeans.ManagedQueue; import org.apache.qpid.management.common.mbeans.annotations.MBeanConstructor; import org.apache.qpid.management.common.mbeans.annotations.MBeanDescription; import org.apache.qpid.management.common.mbeans.annotations.MBeanOperationParameter; +import org.apache.qpid.server.exchange.AMQUnknownExchangeType; import org.apache.qpid.server.jmx.ManagedObject; import org.apache.qpid.server.model.Exchange; import org.apache.qpid.server.model.LifetimePolicy; import org.apache.qpid.server.model.Queue; -import org.apache.qpid.server.model.State; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.queue.QueueArgumentsConverter; +import org.apache.qpid.server.virtualhost.ExchangeExistsException; import org.apache.qpid.server.virtualhost.RequiredExchangeException; +import org.apache.qpid.server.virtualhost.ReservedExchangeNameException; @MBeanDescription("This MBean exposes the broker level management features") public class VirtualHostManagerMBean extends AbstractStatisticsGatheringMBean<VirtualHost> implements ManagedBroker @@ -166,8 +168,29 @@ public class VirtualHostManagerMBean extends AbstractStatisticsGatheringMBean<Vi try { - getConfiguredObject().createExchange(name, State.ACTIVE, durable, - LifetimePolicy.PERMANENT, type, Collections.EMPTY_MAP); + Map<String,Object> attributes = new HashMap<>(); + attributes.put(Exchange.NAME, name); + attributes.put(Exchange.TYPE, type); + attributes.put(Exchange.DURABLE, durable); + attributes.put(Exchange.LIFETIME_POLICY, LifetimePolicy.PERMANENT); + + getConfiguredObject().createExchange(attributes); + } + catch(ExchangeExistsException e) + { + String message = "Exchange with name '" + name + "' already exists"; + JMException jme = new JMException(message); + throw new MBeanException(jme, "Error in creating exchange " + name); + + } + catch(ReservedExchangeNameException e) + { + throw new UnsupportedOperationException("'" + name + "' is a reserved exchange name"); + } + catch(AMQUnknownExchangeType e) + { + JMException jme = new JMException(e.getMessage()); + throw new MBeanException(jme, "Error in creating exchange " + name); } catch (IllegalArgumentException iae) { @@ -175,6 +198,7 @@ public class VirtualHostManagerMBean extends AbstractStatisticsGatheringMBean<Vi throw new MBeanException(jme, "Error in creating exchange " + name); } + } @Override diff --git a/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java b/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java index d63a3983f5..8f2418ddf3 100644 --- a/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java +++ b/qpid/java/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/VirtualHostManagerMBeanTest.java @@ -19,6 +19,7 @@ */ package org.apache.qpid.server.jmx.mbeans; +import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -32,12 +33,12 @@ import javax.management.OperationsException; import junit.framework.TestCase; import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatcher; import org.apache.qpid.server.jmx.ManagedObjectRegistry; import org.apache.qpid.server.model.Exchange; import org.apache.qpid.server.model.LifetimePolicy; import org.apache.qpid.server.model.Queue; -import org.apache.qpid.server.model.State; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.queue.QueueArgumentsConverter; @@ -150,7 +151,8 @@ public class VirtualHostManagerMBeanTest extends TestCase public void testCreateNewDurableExchange() throws Exception { _virtualHostManagerMBean.createNewExchange(TEST_EXCHANGE_NAME, TEST_EXCHANGE_TYPE, true); - verify(_mockVirtualHost).createExchange(TEST_EXCHANGE_NAME, State.ACTIVE, true, LifetimePolicy.PERMANENT, TEST_EXCHANGE_TYPE, EMPTY_ARGUMENT_MAP); + + verify(_mockVirtualHost).createExchange(matchesMap(TEST_EXCHANGE_NAME, true, LifetimePolicy.PERMANENT, TEST_EXCHANGE_TYPE)); } public void testCreateNewExchangeWithUnknownExchangeType() throws Exception @@ -165,7 +167,10 @@ public class VirtualHostManagerMBeanTest extends TestCase { // PASS } - verify(_mockVirtualHost, never()).createExchange(TEST_EXCHANGE_NAME, State.ACTIVE, true, LifetimePolicy.PERMANENT, exchangeType, EMPTY_ARGUMENT_MAP); + verify(_mockVirtualHost, never()).createExchange(matchesMap(TEST_EXCHANGE_NAME, + true, + LifetimePolicy.PERMANENT, + exchangeType)); } public void testUnregisterExchange() throws Exception @@ -200,4 +205,45 @@ public class VirtualHostManagerMBeanTest extends TestCase verify(mockExchange, never()).delete(); } + + private static Map<String,Object> matchesMap(final String name, + final boolean durable, + final LifetimePolicy lifetimePolicy, + final String exchangeType) + { + return argThat(new MapMatcher(name, durable, lifetimePolicy, exchangeType)); + } + + private static class MapMatcher extends ArgumentMatcher<Map<String,Object>> + { + + private final String _name; + private final boolean _durable; + private final LifetimePolicy _lifetimePolicy; + private final String _exchangeType; + + public MapMatcher(final String name, + final boolean durable, + final LifetimePolicy lifetimePolicy, + final String exchangeType) + { + _name = name; + _durable = durable; + _lifetimePolicy = lifetimePolicy; + _exchangeType = exchangeType; + + } + + @Override + public boolean matches(final Object o) + { + Map<String,Object> map = (Map<String,Object>)o; + + return _name.equals(map.get(Exchange.NAME)) + && _durable == (Boolean) map.get(Exchange.DURABLE) + && _lifetimePolicy == map.get(Exchange.LIFETIME_POLICY) + && _exchangeType.equals(map.get(Exchange.TYPE)); + } + } + } |
