summaryrefslogtreecommitdiff
path: root/qpid/java
diff options
context:
space:
mode:
authorRobert Godfrey <rgodfrey@apache.org = rgodfrey = Robert Godfrey rgodfrey@apache.org@apache.org>2014-04-12 23:36:11 +0000
committerRobert Godfrey <rgodfrey@apache.org = rgodfrey = Robert Godfrey rgodfrey@apache.org@apache.org>2014-04-12 23:36:11 +0000
commit3490d98ad80b047819ac5e83e17f8dd2c5ef3b3c (patch)
tree952bc4d5f186642f545e0fa68e211134c2005d1e /qpid/java
parentb36245c177e3de1aaabecd0d0a6fd94b2b4996fb (diff)
downloadqpid-python-3490d98ad80b047819ac5e83e17f8dd2c5ef3b3c.tar.gz
QPID-5686 : [Java Broker] Make handling of parents of ConfiguredObjects consistent; perform some refactoring of AbstractConfiguredObject to move functionality into helper classes
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1586910 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
-rw-r--r--qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java3
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java3
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java10
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerStoreUpgrader.java43
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java4
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java1053
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObjectTypeFactory.java10
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractUnresolvedObject.java4
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java628
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java2
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttribute.java51
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttributeOrStatistic.java155
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactory.java19
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectStatistic.java41
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Model.java243
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/SystemContext.java4
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java2
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java2
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java4
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileBasedGroupProvider.java7
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProvider.java2
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java6
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java4
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java2
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/PortFactory.java7
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/protocol/AMQConnectionModel.java13
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java3
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/QueueConsumerImpl.java4
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/FileKeyStore.java3
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/FileTrustStore.java2
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractAuthenticationManager.java6
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java2
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ScramSHA1AuthenticationManager.java46
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java7
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java2
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java2
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileKeyStoreCreationTest.java3
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java3
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java3
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java3
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/consumer/MockConsumer.java25
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java1
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java7
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java12
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java3
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java4
-rw-r--r--qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProvider.java2
-rw-r--r--qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java2
-rw-r--r--qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java2
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java4
50 files changed, 1300 insertions, 1173 deletions
diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java
index 70882ca45b..7b1355aa45 100644
--- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java
+++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java
@@ -38,6 +38,7 @@ import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.ConfiguredObjectFactory;
+import org.apache.qpid.server.model.Model;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory;
@@ -144,7 +145,7 @@ public class VirtualHostTest extends QpidTestCase
private VirtualHost<?,?,?> createHost(Map<String, Object> attributes)
{
- ConfiguredObjectFactory factory = new ConfiguredObjectFactory();
+ ConfiguredObjectFactory factory = new ConfiguredObjectFactory(Model.getInstance());
ConfiguredObjectTypeFactory vhostFactory =
factory.getConfiguredObjectTypeFactory(VirtualHost.class, attributes);
attributes = new HashMap<String, Object>(attributes);
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java
index 810f2d43c7..d58e906b0a 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java
@@ -44,6 +44,7 @@ import org.apache.qpid.server.logging.SystemOutMessageLogger;
import org.apache.qpid.server.logging.log4j.LoggingManagementFacade;
import org.apache.qpid.server.logging.messages.BrokerMessages;
import org.apache.qpid.server.model.ConfiguredObjectFactory;
+import org.apache.qpid.server.model.Model;
import org.apache.qpid.server.model.SystemContext;
import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.registry.IApplicationRegistry;
@@ -134,7 +135,7 @@ public class Broker
LogRecorder logRecorder = new LogRecorder();
TaskExecutor taskExecutor = new TaskExecutor();
taskExecutor.start();
- ConfiguredObjectFactory configuredObjectFactory = new ConfiguredObjectFactory();
+ ConfiguredObjectFactory configuredObjectFactory = new ConfiguredObjectFactory(Model.getInstance());
SystemContext systemContext = new SystemContext(taskExecutor, configuredObjectFactory, _eventLogger, logRecorder, options);
BrokerConfigurationStoreCreator storeCreator = new BrokerConfigurationStoreCreator();
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java
index ad10a75963..1355770f53 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java
@@ -37,7 +37,6 @@ import org.apache.qpid.server.logging.subjects.BindingLogSubject;
import org.apache.qpid.server.model.AbstractConfiguredObject;
import org.apache.qpid.server.model.Binding;
import org.apache.qpid.server.model.ConfiguredObject;
-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;
@@ -102,15 +101,6 @@ public class BindingImpl
}
- private static Map<Class<? extends ConfiguredObject>, ConfiguredObject<?>> parentsMap(final AMQQueue queue, final ExchangeImpl exchange)
- {
- final Map<Class<? extends ConfiguredObject>, ConfiguredObject<?>> parents = new HashMap<Class<? extends ConfiguredObject>, ConfiguredObject<?>>();
- parents.put(Queue.class, queue);
- parents.put(Exchange.class, exchange);
- return parents;
- }
-
-
public String getBindingKey()
{
return _bindingKey;
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerStoreUpgrader.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerStoreUpgrader.java
index b7b672fd58..e82a92bb83 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerStoreUpgrader.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerStoreUpgrader.java
@@ -20,6 +20,7 @@ package org.apache.qpid.server.configuration.startup;/*
*/
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -33,6 +34,7 @@ import org.apache.log4j.Logger;
import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener;
import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.Model;
import org.apache.qpid.server.model.SystemContext;
import org.apache.qpid.server.store.ConfiguredObjectRecord;
@@ -41,6 +43,7 @@ import org.apache.qpid.server.store.DurableConfigurationStore;
import org.apache.qpid.server.store.DurableConfigurationStoreUpgrader;
import org.apache.qpid.server.store.NonNullUpgrader;
import org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler;
+import org.apache.qpid.server.util.Action;
public class BrokerStoreUpgrader
{
@@ -732,11 +735,49 @@ public class BrokerStoreUpgrader
_systemContext.resolveObjects(_records.values().toArray(new ConfiguredObjectRecord[_records.size()]));
- _systemContext.getBroker().addChangeListener(new StoreConfigurationChangeListener(_store));
+ final StoreConfigurationChangeListener configChangeListener = new StoreConfigurationChangeListener(_store);
+ applyRecursively(_systemContext.getBroker(),
+ new Action<ConfiguredObject<?>>()
+ {
+ @Override
+ public void performAction(final ConfiguredObject<?> object)
+ {
+ object.addChangeListener(configChangeListener);
+ }
+
+
+ });
return _version;
}
+ private void applyRecursively(final ConfiguredObject<?> object, final Action<ConfiguredObject<?>> action)
+ {
+ applyRecursively(object, action, new HashSet<ConfiguredObject<?>>());
+ }
+
+ private void applyRecursively(final ConfiguredObject<?> object,
+ final Action<ConfiguredObject<?>> action,
+ final HashSet<ConfiguredObject<?>> visited)
+ {
+ if(!visited.contains(object))
+ {
+ visited.add(object);
+ action.performAction(object);
+ for(Class<? extends ConfiguredObject> childClass : Model.getInstance().getChildTypes(object.getCategoryClass()))
+ {
+ Collection<? extends ConfiguredObject> children = object.getChildren(childClass);
+ if(children != null)
+ {
+ for(ConfiguredObject<?> child : children)
+ {
+ applyRecursively(child, action, visited);
+ }
+ }
+ }
+ }
+ }
+
private String getCurrentVersion()
{
for(ConfiguredObjectRecord record : _records.values())
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
index 3b755a6df5..b94f73854b 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
@@ -52,7 +52,6 @@ import org.apache.qpid.server.model.Publisher;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.BaseQueue;
@@ -109,8 +108,7 @@ public abstract class AbstractExchange<T extends AbstractExchange<T>>
public AbstractExchange(VirtualHostImpl vhost, Map<String, Object> attributes) throws UnknownExchangeException
{
- super(Collections.<Class<? extends ConfiguredObject>, ConfiguredObject<?>>singletonMap(VirtualHost.class, vhost),
- attributes, vhost.getTaskExecutor());
+ super(parentsMap(vhost), attributes, vhost.getTaskExecutor());
_virtualHost = vhost;
_durable = MapValueConverter.getBooleanAttribute(org.apache.qpid.server.model.Exchange.DURABLE, attributes);
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 48b3bdfa8d..12bd2dc7f8 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
@@ -21,18 +21,13 @@
package org.apache.qpid.server.model;
import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.AbstractCollection;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -48,8 +43,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.security.auth.Subject;
-import org.apache.log4j.Logger;
-
import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.configuration.updater.ChangeAttributesTask;
import org.apache.qpid.server.configuration.updater.ChangeStateTask;
@@ -65,17 +58,16 @@ import org.apache.qpid.util.Strings;
public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> implements ConfiguredObject<X>
{
- private static final Logger LOGGER = Logger.getLogger(AbstractConfiguredObject.class);
private static final String ID = "id";
- private static final Map<Class<? extends ConfiguredObject>, Collection<Attribute<?,?>>> _allAttributes =
- Collections.synchronizedMap(new HashMap<Class<? extends ConfiguredObject>, Collection<Attribute<?, ?>>>());
+ private static final Map<Class<? extends ConfiguredObject>, Collection<ConfiguredObjectAttribute<?,?>>> _allAttributes =
+ Collections.synchronizedMap(new HashMap<Class<? extends ConfiguredObject>, Collection<ConfiguredObjectAttribute<?, ?>>>());
- private static final Map<Class<? extends ConfiguredObject>, Collection<Statistic<?,?>>> _allStatistics =
- Collections.synchronizedMap(new HashMap<Class<? extends ConfiguredObject>, Collection<Statistic<?, ?>>>());
+ private static final Map<Class<? extends ConfiguredObject>, Collection<ConfiguredObjectStatistic<?,?>>> _allStatistics =
+ Collections.synchronizedMap(new HashMap<Class<? extends ConfiguredObject>, Collection<ConfiguredObjectStatistic<?, ?>>>());
- private static final Map<Class<? extends ConfiguredObject>, Map<String, Attribute<?,?>>> _allAttributeTypes =
- Collections.synchronizedMap(new HashMap<Class<? extends ConfiguredObject>, Map<String, Attribute<?, ?>>>());
+ private static final Map<Class<? extends ConfiguredObject>, Map<String, ConfiguredObjectAttribute<?,?>>> _allAttributeTypes =
+ Collections.synchronizedMap(new HashMap<Class<? extends ConfiguredObject>, Map<String, ConfiguredObjectAttribute<?, ?>>>());
private static final Map<Class<? extends ConfiguredObject>, Map<String, Field>> _allAutomatedFields =
Collections.synchronizedMap(new HashMap<Class<? extends ConfiguredObject>, Map<String, Field>>());
@@ -134,45 +126,35 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
@ManagedAttributeField
private Map<String,String> _context;
- private final Map<String, Attribute<?,?>> _attributeTypes;
+ private final Map<String, ConfiguredObjectAttribute<?,?>> _attributeTypes;
private final Map<String, Field> _automatedFields;
@ManagedAttributeField
private String _type;
- protected AbstractConfiguredObject(UUID id,
- Map<String, Object> attributes,
- TaskExecutor taskExecutor)
- {
- this(combineIdWithAttributes(id,attributes), taskExecutor);
- }
-
- public static Map<String,Object> combineIdWithAttributes(UUID id, Map<String,Object> attributes)
+ protected static Map<String,Object> combineIdWithAttributes(UUID id, Map<String,Object> attributes)
{
Map<String,Object> combined = new HashMap<String, Object>(attributes);
combined.put(ID, id);
return combined;
}
-
- protected AbstractConfiguredObject(Map<String, Object> attributes,
- TaskExecutor taskExecutor)
+ protected static Map<Class<? extends ConfiguredObject>, ConfiguredObject<?>> parentsMap(ConfiguredObject<?>... parents)
{
- this(Collections.<Class<? extends ConfiguredObject>, ConfiguredObject<?>>emptyMap(),
- attributes, taskExecutor, true);
- }
+ final Map<Class<? extends ConfiguredObject>, ConfiguredObject<?>> parentsMap =
+ new HashMap<Class<? extends ConfiguredObject>, ConfiguredObject<?>>();
- protected AbstractConfiguredObject(final Map<Class<? extends ConfiguredObject>, ConfiguredObject<?>> parents,
- Map<String, Object> attributes,
- TaskExecutor taskExecutor)
- {
- this(parents, attributes, taskExecutor, true);
+ for(ConfiguredObject<?> parent : parents)
+ {
+ parentsMap.put(parent.getCategoryClass(), parent);
+ }
+ return parentsMap;
}
+
protected AbstractConfiguredObject(final Map<Class<? extends ConfiguredObject>, ConfiguredObject<?>> parents,
Map<String, Object> attributes,
- TaskExecutor taskExecutor,
- boolean filterAttributes)
+ TaskExecutor taskExecutor)
{
_taskExecutor = taskExecutor;
Object idObj = attributes.get(ID);
@@ -184,14 +166,14 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
}
else
{
- uuid = UUID_CONVERTER.convert(idObj, this);
+ uuid = AttributeValueConverter.UUID_CONVERTER.convert(idObj, this);
}
_id = uuid;
_attributeTypes = getAttributeTypes(getClass());
_automatedFields = getAutomatedFields(getClass());
- _type = getType(getClass());
+ _type = Model.getType(getClass());
if(attributes.get(TYPE) != null)
{
if(!_type.equals(attributes.get(TYPE)))
@@ -216,39 +198,25 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
for(Map.Entry<Class<? extends ConfiguredObject>, ConfiguredObject<?>> entry : parents.entrySet())
{
- addParent((Class<ConfiguredObject>) entry.getKey(), entry.getValue());
+ addParent((Class<ConfiguredObject<?>>) entry.getKey(), entry.getValue());
}
- _name = STRING_CONVERTER.convert(attributes.get(NAME),this);
+ _name = AttributeValueConverter.STRING_CONVERTER.convert(attributes.get(NAME),this);
Collection<String> names = getAttributeNames();
if(names!=null)
{
- if(filterAttributes)
- {
- for (String name : names)
- {
- if (attributes.containsKey(name))
- {
- final Object value = attributes.get(name);
- if(value != null)
- {
- _attributes.put(name, value);
- }
- }
- }
- }
- else
+ for (String name : names)
{
- for(Map.Entry<String, Object> entry : attributes.entrySet())
+ if (attributes.containsKey(name))
{
- if(entry.getValue()!=null)
+ final Object value = attributes.get(name);
+ if(value != null)
{
- _attributes.put(entry.getKey(),entry.getValue());
+ _attributes.put(name, value);
}
}
}
-
}
if(!_attributes.containsKey(CREATED_BY))
@@ -263,7 +231,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
{
_attributes.put(CREATED_TIME, System.currentTimeMillis());
}
- for(Attribute<?,?> attr : _attributeTypes.values())
+ for(ConfiguredObjectAttribute<?,?> attr : _attributeTypes.values())
{
if(attr.getAnnotation().mandatory() && !(_attributes.containsKey(attr.getName())
|| !"".equals(attr.getAnnotation().defaultValue())))
@@ -278,7 +246,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
{
try
{
- final Attribute attribute = _attributeTypes.get(name);
+ final ConfiguredObjectAttribute attribute = _attributeTypes.get(name);
if(value == null && !"".equals(attribute.getAnnotation().defaultValue()))
{
value = attribute.getAnnotation().defaultValue();
@@ -291,11 +259,6 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
}
}
- protected AbstractConfiguredObject(UUID id, TaskExecutor taskExecutor)
- {
- this(id, Collections.<String,Object>emptyMap(), taskExecutor);
- }
-
public void open()
{
if(_open.compareAndSet(false,true))
@@ -403,7 +366,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
protected void resolve()
{
- for (Attribute<?, ?> attr : _attributeTypes.values())
+ for (ConfiguredObjectAttribute<?, ?> attr : _attributeTypes.values())
{
String attrName = attr.getName();
ManagedAttribute attrAnnotation = attr.getAnnotation();
@@ -443,7 +406,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
public Class<? extends ConfiguredObject> getCategoryClass()
{
- return getCategory(getClass());
+ return Model.getCategory(getClass());
}
public Map<String,String> getContext()
@@ -573,7 +536,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
@Override
public Object getAttribute(String name)
{
- Attribute<X,?> attr = (Attribute<X, ?>) _attributeTypes.get(name);
+ ConfiguredObjectAttribute<X,?> attr = (ConfiguredObjectAttribute<X, ?>) _attributeTypes.get(name);
if(attr != null && attr.getAnnotation().automate())
{
Object value = attr.getValue((X)this);
@@ -601,7 +564,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
}
@Override
- public <T> T getAttribute(final Attribute<? super X, T> attr)
+ public <T> T getAttribute(final ConfiguredObjectAttribute<? super X, T> attr)
{
return (T) getAttribute(attr.getName());
}
@@ -666,7 +629,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
{
//TODO: don't put nulls
_attributes.put(name, desired);
- Attribute<?,?> attr = _attributeTypes.get(name);
+ ConfiguredObjectAttribute<?,?> attr = _attributeTypes.get(name);
if(attr != null && attr.getAnnotation().automate())
{
automatedSetValue(name, desired);
@@ -697,14 +660,6 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
}
- protected <T extends ConfiguredObject> void removeParent(Class<T> clazz)
- {
- synchronized (this)
- {
- _parents.remove(clazz);
- }
- }
-
public Collection<String> getAttributeNames()
{
synchronized(_attributes)
@@ -808,7 +763,8 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
private <C extends ConfiguredObject> void registerChild(final C child)
{
- _children.get(child.getCategoryClass()).add(child);
+ Class categoryClass = child.getCategoryClass();
+ _children.get(categoryClass).add(child);
}
@@ -1002,9 +958,9 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
@Override
public Map<String,Number> getStatistics()
{
- Collection<Statistic> stats = getStatistics(getClass());
+ Collection<ConfiguredObjectStatistic> stats = getStatistics(getClass());
Map<String,Number> map = new HashMap<String,Number>();
- for(Statistic stat : stats)
+ for(ConfiguredObjectStatistic stat : stats)
{
map.put(stat.getName(), (Number) stat.getValue(this));
}
@@ -1027,107 +983,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
//=========================================================================================
- private static abstract class AttributeOrStatistic<C extends ConfiguredObject, T>
- {
-
- protected final String _name;
- protected final Class<T> _type;
- protected final Converter<T> _converter;
- protected final Method _getter;
-
- private AttributeOrStatistic(final Method getter)
- {
-
- _getter = getter;
- _type = (Class<T>) getTypeFromMethod(getter);
- _name = getNameFromMethod(getter, _type);
- _converter = getConverter(_type, getter.getGenericReturnType());
-
- }
-
- public String getName()
- {
- return _name;
- }
-
- public Class<T> getType()
- {
- return _type;
- }
-
- public T getValue(C configuredObject)
- {
- try
- {
- return (T) _getter.invoke(configuredObject);
- }
- catch (IllegalAccessException e)
- {
- Object o = configuredObject.getAttribute(_name);
- return _converter.convert(o, configuredObject);
- }
- catch (InvocationTargetException e)
- {
- Object o = configuredObject.getAttribute(_name);
- return _converter.convert(o, configuredObject);
- }
-
- }
-
- public Method getGetter()
- {
- return _getter;
- }
- }
-
- private static final class Statistic<C extends ConfiguredObject, T extends Number> extends AttributeOrStatistic<C,T>
- {
- private Statistic(Class<C> clazz, final Method getter)
- {
- super(getter);
- if(getter.getParameterTypes().length != 0)
- {
- throw new IllegalArgumentException("ManagedStatistic annotation should only be added to no-arg getters");
- }
-
- if(!Number.class.isAssignableFrom(getType()))
- {
- throw new IllegalArgumentException("ManagedStatistic annotation should only be added to getters returning a Number type");
- }
- addToStatisticsSet(clazz, this);
- }
- }
-
- public static final class Attribute<C extends ConfiguredObject, T> extends AttributeOrStatistic<C,T>
- {
-
- private final ManagedAttribute _annotation;
-
- private Attribute(Class<C> clazz,
- final Method getter,
- final ManagedAttribute annotation)
- {
- super(getter);
- if(getter.getParameterTypes().length != 0)
- {
- throw new IllegalArgumentException("ManagedAttribute annotation should only be added to no-arg getters");
- }
- _annotation = annotation;
- addToAttributesSet(clazz, this);
- }
-
- public ManagedAttribute getAnnotation()
- {
- return _annotation;
- }
-
- public T convert(final Object value, C object)
- {
- return _converter.convert(value, object);
- }
- }
-
- private static String interpolate(ConfiguredObject<?> object, String value)
+ static String interpolate(ConfiguredObject<?> object, String value)
{
Map<String,String> inheritedContext = new HashMap<String, String>();
generateInheritedContext(object, inheritedContext);
@@ -1138,7 +994,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
new Strings.MapResolver(_defaultContext));
}
- private static void generateInheritedContext(final ConfiguredObject<?> object,
+ static void generateInheritedContext(final ConfiguredObject<?> object,
final Map<String, String> inheritedContext)
{
Collection<Class<? extends ConfiguredObject>> parents =
@@ -1157,628 +1013,16 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
}
}
- private static interface Converter<T>
- {
- T convert(Object value, final ConfiguredObject object);
- }
-
- private static final Converter<String> STRING_CONVERTER = new Converter<String>()
- {
- @Override
- public String convert(final Object value, final ConfiguredObject object)
- {
- return value == null ? null : interpolate(object, value.toString());
- }
- };
-
- private static final Converter<UUID> UUID_CONVERTER = new Converter<UUID>()
- {
- @Override
- public UUID convert(final Object value, final ConfiguredObject object)
- {
- if(value instanceof UUID)
- {
- return (UUID) value;
- }
- else if(value instanceof String)
- {
- return UUID.fromString(interpolate(object, (String) value));
- }
- else if(value == null)
- {
- return null;
- }
- else
- {
- throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a UUID");
- }
- }
- };
-
- private static final Converter<Long> LONG_CONVERTER = new Converter<Long>()
- {
-
- @Override
- public Long convert(final Object value, final ConfiguredObject object)
- {
- if(value instanceof Long)
- {
- return (Long) value;
- }
- else if(value instanceof Number)
- {
- return ((Number) value).longValue();
- }
- else if(value instanceof String)
- {
- return Long.valueOf(interpolate(object, (String) value));
- }
- else if(value == null)
- {
- return null;
- }
- else
- {
- throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a Long");
- }
- }
- };
-
- private static final Converter<Integer> INT_CONVERTER = new Converter<Integer>()
- {
-
- @Override
- public Integer convert(final Object value, final ConfiguredObject object)
- {
- if(value instanceof Integer)
- {
- return (Integer) value;
- }
- else if(value instanceof Number)
- {
- return ((Number) value).intValue();
- }
- else if(value instanceof String)
- {
- try
- {
- return Integer.valueOf(interpolate(object, (String) value));
- }
- catch (NumberFormatException e)
- {
- Map<String,String> context = new HashMap<String, String>();
- generateInheritedContext(object, context);
- LOGGER.debug(context.toString());
- throw e;
- }
- }
- else if(value == null)
- {
- return null;
- }
- else
- {
- throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to an Integer");
- }
- }
- };
-
-
- private static final Converter<Short> SHORT_CONVERTER = new Converter<Short>()
- {
-
- @Override
- public Short convert(final Object value, final ConfiguredObject object)
- {
- if(value instanceof Short)
- {
- return (Short) value;
- }
- else if(value instanceof Number)
- {
- return ((Number) value).shortValue();
- }
- else if(value instanceof String)
- {
- return Short.valueOf(interpolate(object, (String) value));
- }
- else if(value == null)
- {
- return null;
- }
- else
- {
- throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a Short");
- }
- }
- };
-
- private static final Converter<Boolean> BOOLEAN_CONVERTER = new Converter<Boolean>()
- {
-
- @Override
- public Boolean convert(final Object value, final ConfiguredObject object)
- {
- if(value instanceof Boolean)
- {
- return (Boolean) value;
- }
- else if(value instanceof String)
- {
- return Boolean.valueOf(interpolate(object, (String) value));
- }
- else if(value == null)
- {
- return null;
- }
- else
- {
- throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a Boolean");
- }
- }
- };
-
- private static final Converter<List> LIST_CONVERTER = new Converter<List>()
- {
- @Override
- public List convert(final Object value, final ConfiguredObject object)
- {
- if(value instanceof List)
- {
- return Collections.unmodifiableList((List) value);
- }
- else if(value instanceof Object[])
- {
- return convert(Arrays.asList((Object[])value),object);
- }
- else if(value == null)
- {
- return null;
- }
- else
- {
- throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a List");
- }
- }
- };
-
- public static class GenericListConverter implements Converter<List>
- {
-
- private final Converter<?> _memberConverter;
-
- public GenericListConverter(final Type genericType)
- {
- _memberConverter = getConverter(getRawType(genericType),genericType);
- }
-
- private static Class getRawType(Type t)
- {
- if(t instanceof Class)
- {
- return (Class)t;
- }
- else if(t instanceof ParameterizedType)
- {
- return (Class)((ParameterizedType)t).getRawType();
- }
- else if(t instanceof TypeVariable)
- {
- Type[] bounds = ((TypeVariable)t).getBounds();
- if(bounds.length == 1)
- {
- return getRawType(bounds[0]);
- }
- }
- throw new ServerScopedRuntimeException("Unable to process type when constructing configuration model: " + t);
- }
-
- @Override
- public List convert(final Object value, final ConfiguredObject object)
- {
- if(value instanceof Collection)
- {
- Collection original = (Collection)value;
- List converted = new ArrayList(original.size());
- for(Object member : original)
- {
- converted.add(_memberConverter.convert(member, object));
- }
- return Collections.unmodifiableList(converted);
- }
- else if(value instanceof Object[])
- {
- return convert(Arrays.asList((Object[])value),object);
- }
- else if(value == null)
- {
- return null;
- }
- else
- {
- return Collections.unmodifiableList(Collections.singletonList(_memberConverter.convert(value, object)));
- }
- }
- }
-
-
- private static final Converter<Set> SET_CONVERTER = new Converter<Set>()
- {
- @Override
- public Set convert(final Object value, final ConfiguredObject object)
- {
- if(value instanceof Set)
- {
- return Collections.unmodifiableSet((Set) value);
- }
-
- else if(value instanceof Object[])
- {
- return convert(new HashSet(Arrays.asList((Object[])value)),object);
- }
- else if(value == null)
- {
- return null;
- }
- else
- {
- throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a List");
- }
- }
- };
- public static class GenericSetConverter implements Converter<Set>
- {
-
- private final Converter<?> _memberConverter;
-
- public GenericSetConverter(final Type genericType)
- {
- _memberConverter = getConverter(getRawType(genericType),genericType);
- }
-
- private static Class getRawType(Type t)
- {
- if(t instanceof Class)
- {
- return (Class)t;
- }
- else if(t instanceof ParameterizedType)
- {
- return (Class)((ParameterizedType)t).getRawType();
- }
- else if(t instanceof TypeVariable)
- {
- Type[] bounds = ((TypeVariable)t).getBounds();
- if(bounds.length == 1)
- {
- return getRawType(bounds[0]);
- }
- }
- throw new ServerScopedRuntimeException("Unable to process type when constructing configuration model: " + t);
- }
-
- @Override
- public Set convert(final Object value, final ConfiguredObject object)
- {
- if(value instanceof Collection)
- {
- Collection original = (Collection)value;
- Set converted = new HashSet(original.size());
- for(Object member : original)
- {
- converted.add(_memberConverter.convert(member, object));
- }
- return Collections.unmodifiableSet(converted);
- }
- else if(value instanceof Object[])
- {
- return convert(new HashSet(Arrays.asList((Object[])value)),object);
- }
- else if(value == null)
- {
- return null;
- }
- else
- {
- return Collections.unmodifiableSet(Collections.singleton(_memberConverter.convert(value, object)));
- }
- }
- }
-
-
- private static final Converter<Collection> COLLECTION_CONVERTER = new Converter<Collection>()
- {
- @Override
- public Collection convert(final Object value, final ConfiguredObject object)
- {
- if(value instanceof Collection)
- {
- return Collections.unmodifiableCollection((Collection) value);
- }
- else if(value instanceof Object[])
- {
- return convert(Arrays.asList((Object[]) value), object);
- }
- else if(value == null)
- {
- return null;
- }
- else
- {
- throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a List");
- }
- }
- };
-
-
- public static class GenericCollectionConverter implements Converter<Collection>
- {
-
- private final Converter<?> _memberConverter;
-
- public GenericCollectionConverter(final Type genericType)
- {
- _memberConverter = getConverter(getRawType(genericType),genericType);
- }
-
- private static Class getRawType(Type t)
- {
- if(t instanceof Class)
- {
- return (Class)t;
- }
- else if(t instanceof ParameterizedType)
- {
- return (Class)((ParameterizedType)t).getRawType();
- }
- else if(t instanceof TypeVariable)
- {
- Type[] bounds = ((TypeVariable)t).getBounds();
- if(bounds.length == 1)
- {
- return getRawType(bounds[0]);
- }
- }
- throw new ServerScopedRuntimeException("Unable to process type when constructing configuration model: " + t);
- }
-
- @Override
- public Collection convert(final Object value, final ConfiguredObject object)
- {
- if(value instanceof Collection)
- {
- Collection original = (Collection)value;
- Collection converted = new ArrayList(original.size());
- for(Object member : original)
- {
- converted.add(_memberConverter.convert(member, object));
- }
- return Collections.unmodifiableCollection(converted);
- }
- else if(value instanceof Object[])
- {
- return convert(Arrays.asList((Object[])value),object);
- }
- else if(value == null)
- {
- return null;
- }
- else
- {
- return Collections.unmodifiableCollection(Collections.singletonList(_memberConverter.convert(value, object)));
- }
- }
- }
-
- private static final Converter<Map> MAP_CONVERTER = new Converter<Map>()
- {
- @Override
- public Map convert(final Object value, final ConfiguredObject object)
- {
- if(value instanceof Map)
- {
- Map<Object,Object> originalMap = (Map) value;
- Map resolvedMap = new LinkedHashMap(originalMap.size());
- for(Map.Entry<Object,Object> entry : originalMap.entrySet())
- {
- Object key = entry.getKey();
- Object val = entry.getValue();
- resolvedMap.put(key instanceof String ? interpolate(object, (String)key) : key,
- val instanceof String ? interpolate(object, (String)val) : val);
- }
- return Collections.unmodifiableMap(resolvedMap);
- }
- else if(value == null)
- {
- return null;
- }
- else
- {
- throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a Map");
- }
- }
- };
-
- private static final class EnumConverter<X extends Enum<X>> implements Converter<X>
- {
- private final Class<X> _klazz;
-
- private EnumConverter(final Class<X> klazz)
- {
- _klazz = klazz;
- }
-
- @Override
- public X convert(final Object value, final ConfiguredObject object)
- {
- if(value == null)
- {
- return null;
- }
- else if(_klazz.isInstance(value))
- {
- return (X) value;
- }
- else if(value instanceof String)
- {
- return Enum.valueOf(_klazz, interpolate(object, (String) value));
- }
- else
- {
- throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a " + _klazz.getName());
- }
- }
- }
-
-
- private static final class ConfiguredObjectConverter<X extends ConfiguredObject<X>> implements Converter<X>
- {
- private final Class<X> _klazz;
-
- private ConfiguredObjectConverter(final Class<X> klazz)
- {
- _klazz = klazz;
- }
-
- @Override
- public X convert(final Object value, final ConfiguredObject object)
- {
- if(value == null)
- {
- return null;
- }
- else if(_klazz.isInstance(value))
- {
- return (X) value;
- }
- else if(value instanceof UUID)
- {
- Collection<X> reachable = getReachableObjects(object,_klazz);
- for(X candidate : reachable)
- {
- if(candidate.getId().equals(value))
- {
- return candidate;
- }
- }
- throw new IllegalArgumentException("Cannot find a " + _klazz.getName() + " with id " + value);
- }
- else if(value instanceof String)
- {
- String valueStr = interpolate(object, (String) value);
- Collection<X> reachable = getReachableObjects(object,_klazz);
- for(X candidate : reachable)
- {
- if(candidate.getName().equals(valueStr))
- {
- return candidate;
- }
- }
- try
- {
- UUID id = UUID.fromString(valueStr);
- return convert(id, object);
- }
- catch (IllegalArgumentException e)
- {
- throw new IllegalArgumentException("Cannot find a " + _klazz.getSimpleName() + " with name '" + valueStr + "'");
- }
- }
- else
- {
- throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a " + _klazz.getName());
- }
- }
-
- }
-
- private static <X> Converter<X> getConverter(final Class<X> type, final Type returnType)
- {
- if(type == String.class)
- {
- return (Converter<X>) STRING_CONVERTER;
- }
- else if(type == Integer.class)
- {
- return (Converter<X>) INT_CONVERTER;
- }
- else if(type == Short.class)
- {
- return (Converter<X>) SHORT_CONVERTER;
- }
- else if(type == Long.class)
- {
- return (Converter<X>) LONG_CONVERTER;
- }
- else if(type == Boolean.class)
- {
- return (Converter<X>) BOOLEAN_CONVERTER;
- }
- else if(type == UUID.class)
- {
- return (Converter<X>) UUID_CONVERTER;
- }
- else if(Enum.class.isAssignableFrom(type))
- {
- return (Converter<X>) new EnumConverter((Class<? extends Enum>)type);
- }
- else if(List.class.isAssignableFrom(type))
- {
- if (returnType instanceof ParameterizedType)
- {
- Type parameterizedType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
- return (Converter<X>) new GenericListConverter(parameterizedType);
- }
- else
- {
- return (Converter<X>) LIST_CONVERTER;
- }
- }
- else if(Set.class.isAssignableFrom(type))
- {
- if (returnType instanceof ParameterizedType)
- {
- Type parameterizedType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
- return (Converter<X>) new GenericSetConverter(parameterizedType);
- }
- else
- {
- return (Converter<X>) SET_CONVERTER;
- }
- }
- else if(Map.class.isAssignableFrom(type))
- {
- return (Converter<X>) MAP_CONVERTER;
- }
- else if(Collection.class.isAssignableFrom(type))
- {
- if (returnType instanceof ParameterizedType)
- {
- Type parameterizedType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
- return (Converter<X>) new GenericCollectionConverter(parameterizedType);
- }
- else
- {
- return (Converter<X>) COLLECTION_CONVERTER;
- }
- }
- else if(ConfiguredObject.class.isAssignableFrom(type))
- {
- return (Converter<X>) new ConfiguredObjectConverter(type);
- }
- throw new IllegalArgumentException("Cannot create attributes of type " + type.getName());
- }
-
- private static void addToAttributesSet(final Class<? extends ConfiguredObject> clazz, final Attribute<?, ?> attribute)
+ private static void addToAttributesSet(final Class<? extends ConfiguredObject> clazz, final ConfiguredObjectAttribute<?, ?> attribute)
{
synchronized (_allAttributes)
{
- Collection<Attribute<?,?>> classAttributes = _allAttributes.get(clazz);
+ Collection<ConfiguredObjectAttribute<?,?>> classAttributes = _allAttributes.get(clazz);
if(classAttributes == null)
{
- classAttributes = new ArrayList<Attribute<?, ?>>();
- for(Map.Entry<Class<? extends ConfiguredObject>, Collection<Attribute<?,?>>> entry : _allAttributes.entrySet())
+ classAttributes = new ArrayList<ConfiguredObjectAttribute<?, ?>>();
+ for(Map.Entry<Class<? extends ConfiguredObject>, Collection<ConfiguredObjectAttribute<?,?>>> entry : _allAttributes.entrySet())
{
if(entry.getKey().isAssignableFrom(clazz))
{
@@ -1788,7 +1032,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
_allAttributes.put(clazz, classAttributes);
}
- for(Map.Entry<Class<? extends ConfiguredObject>, Collection<Attribute<?,?>>> entry : _allAttributes.entrySet())
+ for(Map.Entry<Class<? extends ConfiguredObject>, Collection<ConfiguredObjectAttribute<?,?>>> entry : _allAttributes.entrySet())
{
if(clazz.isAssignableFrom(entry.getKey()))
{
@@ -1798,15 +1042,15 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
}
}
- private static void addToStatisticsSet(final Class<? extends ConfiguredObject> clazz, final Statistic<?, ?> statistic)
+ private static void addToStatisticsSet(final Class<? extends ConfiguredObject> clazz, final ConfiguredObjectStatistic<?, ?> statistic)
{
synchronized (_allStatistics)
{
- Collection<Statistic<?,?>> classAttributes = _allStatistics.get(clazz);
+ Collection<ConfiguredObjectStatistic<?,?>> classAttributes = _allStatistics.get(clazz);
if(classAttributes == null)
{
- classAttributes = new ArrayList<Statistic<?, ?>>();
- for(Map.Entry<Class<? extends ConfiguredObject>, Collection<Statistic<?,?>>> entry : _allStatistics.entrySet())
+ classAttributes = new ArrayList<ConfiguredObjectStatistic<?, ?>>();
+ for(Map.Entry<Class<? extends ConfiguredObject>, Collection<ConfiguredObjectStatistic<?,?>>> entry : _allStatistics.entrySet())
{
if(entry.getKey().isAssignableFrom(clazz))
{
@@ -1816,7 +1060,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
_allStatistics.put(clazz, classAttributes);
}
- for(Map.Entry<Class<? extends ConfiguredObject>, Collection<Statistic<?,?>>> entry : _allStatistics.entrySet())
+ for(Map.Entry<Class<? extends ConfiguredObject>, Collection<ConfiguredObjectStatistic<?,?>>> entry : _allStatistics.entrySet())
{
if(clazz.isAssignableFrom(entry.getKey()))
{
@@ -1851,8 +1095,8 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
processAttributes((Class<? extends ConfiguredObject>) superclass);
}
- final ArrayList<Attribute<?, ?>> attributeList = new ArrayList<Attribute<?, ?>>();
- final ArrayList<Statistic<?, ?>> statisticList = new ArrayList<Statistic<?, ?>>();
+ final ArrayList<ConfiguredObjectAttribute<?, ?>> attributeList = new ArrayList<ConfiguredObjectAttribute<?, ?>>();
+ final ArrayList<ConfiguredObjectStatistic<?, ?>> statisticList = new ArrayList<ConfiguredObjectStatistic<?, ?>>();
_allAttributes.put(clazz, attributeList);
_allStatistics.put(clazz, statisticList);
@@ -1861,16 +1105,16 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
{
if(ConfiguredObject.class.isAssignableFrom(parent))
{
- Collection<Attribute<?, ?>> attrs = _allAttributes.get(parent);
- for(Attribute<?,?> attr : attrs)
+ Collection<ConfiguredObjectAttribute<?, ?>> attrs = _allAttributes.get(parent);
+ for(ConfiguredObjectAttribute<?,?> attr : attrs)
{
if(!attributeList.contains(attr))
{
attributeList.add(attr);
}
}
- Collection<Statistic<?, ?>> stats = _allStatistics.get(parent);
- for(Statistic<?,?> stat : stats)
+ Collection<ConfiguredObjectStatistic<?, ?>> stats = _allStatistics.get(parent);
+ for(ConfiguredObjectStatistic<?,?> stat : stats)
{
if(!statisticList.contains(stat))
{
@@ -1881,16 +1125,16 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
}
if(superclass != null && ConfiguredObject.class.isAssignableFrom(superclass))
{
- Collection<Attribute<?, ?>> attrs = _allAttributes.get(superclass);
- Collection<Statistic<?, ?>> stats = _allStatistics.get(superclass);
- for(Attribute<?,?> attr : attrs)
+ Collection<ConfiguredObjectAttribute<?, ?>> attrs = _allAttributes.get(superclass);
+ Collection<ConfiguredObjectStatistic<?, ?>> stats = _allStatistics.get(superclass);
+ for(ConfiguredObjectAttribute<?,?> attr : attrs)
{
if(!attributeList.contains(attr))
{
attributeList.add(attr);
}
}
- for(Statistic<?,?> stat : stats)
+ for(ConfiguredObjectStatistic<?,?> stat : stats)
{
if(!statisticList.contains(stat))
{
@@ -1905,24 +1149,24 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
ManagedAttribute annotation = m.getAnnotation(ManagedAttribute.class);
if(annotation != null)
{
- Attribute<X,?> newAttr = new Attribute(clazz, m, annotation);
+ addToAttributesSet(clazz, new ConfiguredObjectAttribute(clazz, m, annotation));
}
else
{
ManagedStatistic statAnnotation = m.getAnnotation(ManagedStatistic.class);
if(statAnnotation != null)
{
- Statistic<X,?> newStat = new Statistic(clazz,m);
+ addToStatisticsSet(clazz, new ConfiguredObjectStatistic(clazz,m));
}
}
}
- Map<String,Attribute<?,?>> attrMap = new HashMap<String, Attribute<?, ?>>();
+ Map<String,ConfiguredObjectAttribute<?,?>> attrMap = new HashMap<String, ConfiguredObjectAttribute<?, ?>>();
Map<String,Field> fieldMap = new HashMap<String, Field>();
- Collection<Attribute<?, ?>> attrCol = _allAttributes.get(clazz);
- for(Attribute<?,?> attr : attrCol)
+ Collection<ConfiguredObjectAttribute<?, ?>> attrCol = _allAttributes.get(clazz);
+ for(ConfiguredObjectAttribute<?,?> attr : attrCol)
{
attrMap.put(attr.getName(), attr);
if(attr.getAnnotation().automate())
@@ -1960,7 +1204,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
}
}
- private static Field findField(final Attribute<?, ?> attr, Class<?> objClass)
+ private static Field findField(final ConfiguredObjectAttribute<?, ?> attr, Class<?> objClass)
{
Class<?> clazz = objClass;
while(clazz != null)
@@ -1982,94 +1226,16 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
throw new ServerScopedRuntimeException("Unable to find field definition for automated field " + attr.getName() + " in class " + objClass.getName());
}
- private static String getNameFromMethod(final Method m, final Class<?> type)
- {
- String methodName = m.getName();
- String baseName;
-
- if(type == Boolean.class )
- {
- if((methodName.startsWith("get") || methodName.startsWith("has")) && methodName.length() >= 4)
- {
- baseName = methodName.substring(3);
- }
- else if(methodName.startsWith("is") && methodName.length() >= 3)
- {
- baseName = methodName.substring(2);
- }
- else
- {
- throw new IllegalArgumentException("Method name " + methodName + " does not conform to the required pattern for ManagedAttributes");
- }
- }
- else
- {
- if(methodName.startsWith("get") && methodName.length() >= 4)
- {
- baseName = methodName.substring(3);
- }
- else
- {
- throw new IllegalArgumentException("Method name " + methodName + " does not conform to the required pattern for ManagedAttributes");
- }
- }
-
- String name = baseName.length() == 1 ? baseName.toLowerCase() : baseName.substring(0,1).toLowerCase() + baseName.substring(1);
- name = name.replace('_','.');
- return name;
- }
-
- private static Class<?> getTypeFromMethod(final Method m)
- {
- Class<?> type = m.getReturnType();
- if(type.isPrimitive())
- {
- if(type == Boolean.TYPE)
- {
- type = Boolean.class;
- }
- else if(type == Byte.TYPE)
- {
- type = Byte.class;
- }
- else if(type == Short.TYPE)
- {
- type = Short.class;
- }
- else if(type == Integer.TYPE)
- {
- type = Integer.class;
- }
- else if(type == Long.TYPE)
- {
- type = Long.class;
- }
- else if(type == Float.TYPE)
- {
- type = Float.class;
- }
- else if(type == Double.TYPE)
- {
- type = Double.class;
- }
- else if(type == Character.TYPE)
- {
- type = Character.class;
- }
- }
- return type;
- }
-
public static <X extends ConfiguredObject> Collection<String> getAttributeNames(Class<X> clazz)
{
- final Collection<Attribute<? super X, ?>> attrs = getAttributes(clazz);
+ final Collection<ConfiguredObjectAttribute<? super X, ?>> attrs = getAttributes(clazz);
return new AbstractCollection<String>()
{
@Override
public Iterator<String> iterator()
{
- final Iterator<Attribute<? super X, ?>> underlyingIterator = attrs.iterator();
+ final Iterator<ConfiguredObjectAttribute<? super X, ?>> underlyingIterator = attrs.iterator();
return new Iterator<String>()
{
@Override
@@ -2101,29 +1267,29 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
}
- protected static <X extends ConfiguredObject> Collection<Attribute<? super X, ?>> getAttributes(final Class<X> clazz)
+ protected static <X extends ConfiguredObject> Collection<ConfiguredObjectAttribute<? super X, ?>> getAttributes(final Class<X> clazz)
{
if(!_allAttributes.containsKey(clazz))
{
processAttributes(clazz);
}
- final Collection<Attribute<? super X, ?>> attributes = (Collection) _allAttributes.get(clazz);
+ final Collection<ConfiguredObjectAttribute<? super X, ?>> attributes = (Collection) _allAttributes.get(clazz);
return attributes;
}
- protected static Collection<Statistic> getStatistics(final Class<? extends ConfiguredObject> clazz)
+ protected static Collection<ConfiguredObjectStatistic> getStatistics(final Class<? extends ConfiguredObject> clazz)
{
if(!_allStatistics.containsKey(clazz))
{
processAttributes(clazz);
}
- final Collection<Statistic> statistics = (Collection) _allStatistics.get(clazz);
+ final Collection<ConfiguredObjectStatistic> statistics = (Collection) _allStatistics.get(clazz);
return statistics;
}
- private static Map<String, Attribute<?, ?>> getAttributeTypes(final Class<? extends ConfiguredObject> clazz)
+ private static Map<String, ConfiguredObjectAttribute<?, ?>> getAttributeTypes(final Class<? extends ConfiguredObject> clazz)
{
if(!_allAttributeTypes.containsKey(clazz))
{
@@ -2141,10 +1307,10 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
return _allAutomatedFields.get(clazz);
}
- private static <X extends ConfiguredObject<X>> Collection<X> getReachableObjects(final ConfiguredObject<?> object,
+ static <X extends ConfiguredObject<X>> Collection<X> getReachableObjects(final ConfiguredObject<?> object,
final Class<X> clazz)
{
- Class<? extends ConfiguredObject> category = getCategory(object.getClass());
+ Class<? extends ConfiguredObject> category = Model.getCategory(object.getClass());
Class<? extends ConfiguredObject> ancestorClass = getAncestorClassWithGivenDescendant(category, clazz);
if(ancestorClass != null)
{
@@ -2259,74 +1425,5 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
return allDescendants.contains(descendantClass);
}
- static Class<? extends ConfiguredObject> getCategory(final Class<?> clazz)
- {
- ManagedObject annotation = clazz.getAnnotation(ManagedObject.class);
- if(annotation != null && annotation.category())
- {
- return (Class<? extends ConfiguredObject>) clazz;
- }
- for(Class<?> iface : clazz.getInterfaces() )
- {
- Class<? extends ConfiguredObject> cat = getCategory(iface);
- if(cat != null)
- {
- return cat;
- }
- }
- if(clazz.getSuperclass() != null)
- {
- return getCategory(clazz.getSuperclass());
- }
- return null;
- }
-
-
- protected static String getType(final Class<? extends ConfiguredObject> clazz)
- {
- ManagedObject annotation = clazz.getAnnotation(ManagedObject.class);
- if(annotation != null)
- {
- if(!"".equals(annotation.type()))
- {
- return annotation.type();
- }
- }
- if(clazz.getSuperclass() != null && ConfiguredObject.class.isAssignableFrom(clazz.getSuperclass()))
- {
- String type = getType((Class<? extends ConfiguredObject>) clazz.getSuperclass());
- if(!"".equals(type))
- {
- return type;
- }
- }
-
- for(Class<?> iface : clazz.getInterfaces() )
- {
- if(ConfiguredObject.class.isAssignableFrom(iface))
- {
- String type = getType((Class<? extends ConfiguredObject>) iface);
- if(!"".equals(type))
- {
- return type;
- }
- }
- }
- Class<? extends ConfiguredObject> category = getCategory(clazz);
- if(category == null)
- {
- return "";
- }
- annotation = category.getAnnotation(ManagedObject.class);
- if(annotation == null)
- {
- throw new NullPointerException("No definition found for category " + category.getSimpleName());
- }
- if(!"".equals(annotation.defaultType()))
- {
- return annotation.defaultType();
- }
- return category.getSimpleName();
- }
}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObjectTypeFactory.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObjectTypeFactory.java
index f8323e2b42..a965044c90 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObjectTypeFactory.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObjectTypeFactory.java
@@ -20,14 +20,14 @@
*/
package org.apache.qpid.server.model;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory;
import org.apache.qpid.server.store.ConfiguredObjectDependency;
import org.apache.qpid.server.store.ConfiguredObjectRecord;
import org.apache.qpid.server.store.UnresolvedConfiguredObject;
-import java.util.HashMap;
-import java.util.Map;
-
abstract public class AbstractConfiguredObjectTypeFactory<X extends AbstractConfiguredObject<X>> implements ConfiguredObjectTypeFactory<X>
{
private final Class<X> _clazz;
@@ -40,13 +40,13 @@ abstract public class AbstractConfiguredObjectTypeFactory<X extends AbstractConf
@Override
public final String getType()
{
- return AbstractConfiguredObject.getType(_clazz);
+ return Model.getType(_clazz);
}
@Override
public final Class<? super X> getCategoryClass()
{
- return (Class<? super X>) AbstractConfiguredObject.getCategory(_clazz);
+ return (Class<? super X>) Model.getCategory(_clazz);
}
@Override
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractUnresolvedObject.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractUnresolvedObject.java
index eff8bb30b6..617419d828 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractUnresolvedObject.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractUnresolvedObject.java
@@ -49,9 +49,9 @@ public abstract class AbstractUnresolvedObject<C extends ConfiguredObject<C>> im
_record = record;
_parents = parents;
- Collection<AbstractConfiguredObject.Attribute<? super C, ?>> attributes =
+ Collection<ConfiguredObjectAttribute<? super C, ?>> attributes =
AbstractConfiguredObject.getAttributes(clazz);
- for(AbstractConfiguredObject.Attribute<? super C, ?> attribute : attributes)
+ for(ConfiguredObjectAttribute<? super C, ?> attribute : attributes)
{
final Class<?> attributeType = attribute.getType();
if(ConfiguredObject.class.isAssignableFrom(attributeType))
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java
new file mode 100644
index 0000000000..2eaaf37a63
--- /dev/null
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java
@@ -0,0 +1,628 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.model;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.qpid.server.util.ServerScopedRuntimeException;
+
+abstract class AttributeValueConverter<T>
+{
+ static final AttributeValueConverter<String> STRING_CONVERTER = new AttributeValueConverter<String>()
+ {
+ @Override
+ public String convert(final Object value, final ConfiguredObject object)
+ {
+ return value == null ? null : AbstractConfiguredObject.interpolate(object, value.toString());
+ }
+ };
+
+ static final AttributeValueConverter<UUID> UUID_CONVERTER = new AttributeValueConverter<UUID>()
+ {
+ @Override
+ public UUID convert(final Object value, final ConfiguredObject object)
+ {
+ if(value instanceof UUID)
+ {
+ return (UUID) value;
+ }
+ else if(value instanceof String)
+ {
+ return UUID.fromString(AbstractConfiguredObject.interpolate(object, (String) value));
+ }
+ else if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a UUID");
+ }
+ }
+ };
+ static final AttributeValueConverter<Long> LONG_CONVERTER = new AttributeValueConverter<Long>()
+ {
+
+ @Override
+ public Long convert(final Object value, final ConfiguredObject object)
+ {
+ if(value instanceof Long)
+ {
+ return (Long) value;
+ }
+ else if(value instanceof Number)
+ {
+ return ((Number) value).longValue();
+ }
+ else if(value instanceof String)
+ {
+ return Long.valueOf(AbstractConfiguredObject.interpolate(object, (String) value));
+ }
+ else if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a Long");
+ }
+ }
+ };
+ static final AttributeValueConverter<Integer> INT_CONVERTER = new AttributeValueConverter<Integer>()
+ {
+
+ @Override
+ public Integer convert(final Object value, final ConfiguredObject object)
+ {
+ if(value instanceof Integer)
+ {
+ return (Integer) value;
+ }
+ else if(value instanceof Number)
+ {
+ return ((Number) value).intValue();
+ }
+ else if(value instanceof String)
+ {
+ return Integer.valueOf(AbstractConfiguredObject.interpolate(object, (String) value));
+ }
+ else if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to an Integer");
+ }
+ }
+ };
+ static final AttributeValueConverter<Short> SHORT_CONVERTER = new AttributeValueConverter<Short>()
+ {
+
+ @Override
+ public Short convert(final Object value, final ConfiguredObject object)
+ {
+ if(value instanceof Short)
+ {
+ return (Short) value;
+ }
+ else if(value instanceof Number)
+ {
+ return ((Number) value).shortValue();
+ }
+ else if(value instanceof String)
+ {
+ return Short.valueOf(AbstractConfiguredObject.interpolate(object, (String) value));
+ }
+ else if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a Short");
+ }
+ }
+ };
+ static final AttributeValueConverter<Boolean> BOOLEAN_CONVERTER = new AttributeValueConverter<Boolean>()
+ {
+
+ @Override
+ public Boolean convert(final Object value, final ConfiguredObject object)
+ {
+ if(value instanceof Boolean)
+ {
+ return (Boolean) value;
+ }
+ else if(value instanceof String)
+ {
+ return Boolean.valueOf(AbstractConfiguredObject.interpolate(object, (String) value));
+ }
+ else if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a Boolean");
+ }
+ }
+ };
+ static final AttributeValueConverter<List> LIST_CONVERTER = new AttributeValueConverter<List>()
+ {
+ @Override
+ public List convert(final Object value, final ConfiguredObject object)
+ {
+ if(value instanceof List)
+ {
+ return Collections.unmodifiableList((List) value);
+ }
+ else if(value instanceof Object[])
+ {
+ return convert(Arrays.asList((Object[]) value),object);
+ }
+ else if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a List");
+ }
+ }
+ };
+ static final AttributeValueConverter<Set> SET_CONVERTER = new AttributeValueConverter<Set>()
+ {
+ @Override
+ public Set convert(final Object value, final ConfiguredObject object)
+ {
+ if(value instanceof Set)
+ {
+ return Collections.unmodifiableSet((Set) value);
+ }
+
+ else if(value instanceof Object[])
+ {
+ return convert(new HashSet(Arrays.asList((Object[])value)),object);
+ }
+ else if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a List");
+ }
+ }
+ };
+ static final AttributeValueConverter<Collection>
+ COLLECTION_CONVERTER = new AttributeValueConverter<Collection>()
+ {
+ @Override
+ public Collection convert(final Object value, final ConfiguredObject object)
+ {
+ if(value instanceof Collection)
+ {
+ return Collections.unmodifiableCollection((Collection) value);
+ }
+ else if(value instanceof Object[])
+ {
+ return convert(Arrays.asList((Object[]) value), object);
+ }
+ else if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a List");
+ }
+ }
+ };
+ static final AttributeValueConverter<Map> MAP_CONVERTER = new AttributeValueConverter<Map>()
+ {
+ @Override
+ public Map convert(final Object value, final ConfiguredObject object)
+ {
+ if(value instanceof Map)
+ {
+ Map<Object,Object> originalMap = (Map) value;
+ Map resolvedMap = new LinkedHashMap(originalMap.size());
+ for(Map.Entry<Object,Object> entry : originalMap.entrySet())
+ {
+ Object key = entry.getKey();
+ Object val = entry.getValue();
+ resolvedMap.put(key instanceof String ? AbstractConfiguredObject.interpolate(object, (String) key) : key,
+ val instanceof String ? AbstractConfiguredObject.interpolate(object, (String) val) : val);
+ }
+ return Collections.unmodifiableMap(resolvedMap);
+ }
+ else if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a Map");
+ }
+ }
+ };
+
+ static <X> AttributeValueConverter<X> getConverter(final Class<X> type, final Type returnType)
+ {
+ if(type == String.class)
+ {
+ return (AttributeValueConverter<X>) STRING_CONVERTER;
+ }
+ else if(type == Integer.class)
+ {
+ return (AttributeValueConverter<X>) INT_CONVERTER;
+ }
+ else if(type == Short.class)
+ {
+ return (AttributeValueConverter<X>) SHORT_CONVERTER;
+ }
+ else if(type == Long.class)
+ {
+ return (AttributeValueConverter<X>) LONG_CONVERTER;
+ }
+ else if(type == Boolean.class)
+ {
+ return (AttributeValueConverter<X>) BOOLEAN_CONVERTER;
+ }
+ else if(type == UUID.class)
+ {
+ return (AttributeValueConverter<X>) UUID_CONVERTER;
+ }
+ else if(Enum.class.isAssignableFrom(type))
+ {
+ return (AttributeValueConverter<X>) new EnumConverter((Class<? extends Enum>)type);
+ }
+ else if(List.class.isAssignableFrom(type))
+ {
+ if (returnType instanceof ParameterizedType)
+ {
+ Type parameterizedType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
+ return (AttributeValueConverter<X>) new GenericListConverter(parameterizedType);
+ }
+ else
+ {
+ return (AttributeValueConverter<X>) LIST_CONVERTER;
+ }
+ }
+ else if(Set.class.isAssignableFrom(type))
+ {
+ if (returnType instanceof ParameterizedType)
+ {
+ Type parameterizedType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
+ return (AttributeValueConverter<X>) new GenericSetConverter(parameterizedType);
+ }
+ else
+ {
+ return (AttributeValueConverter<X>) SET_CONVERTER;
+ }
+ }
+ else if(Map.class.isAssignableFrom(type))
+ {
+ return (AttributeValueConverter<X>) MAP_CONVERTER;
+ }
+ else if(Collection.class.isAssignableFrom(type))
+ {
+ if (returnType instanceof ParameterizedType)
+ {
+ Type parameterizedType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
+ return (AttributeValueConverter<X>) new GenericCollectionConverter(parameterizedType);
+ }
+ else
+ {
+ return (AttributeValueConverter<X>) COLLECTION_CONVERTER;
+ }
+ }
+ else if(ConfiguredObject.class.isAssignableFrom(type))
+ {
+ return (AttributeValueConverter<X>) new ConfiguredObjectConverter(type);
+ }
+ throw new IllegalArgumentException("Cannot create attributes of type " + type.getName());
+ }
+
+ abstract T convert(Object value, final ConfiguredObject object);
+
+ public static class GenericListConverter extends AttributeValueConverter<List>
+ {
+
+ private final AttributeValueConverter<?> _memberConverter;
+
+ public GenericListConverter(final Type genericType)
+ {
+ _memberConverter = getConverter(getRawType(genericType), genericType);
+ }
+
+ private static Class getRawType(Type t)
+ {
+ if(t instanceof Class)
+ {
+ return (Class)t;
+ }
+ else if(t instanceof ParameterizedType)
+ {
+ return (Class)((ParameterizedType)t).getRawType();
+ }
+ else if(t instanceof TypeVariable)
+ {
+ Type[] bounds = ((TypeVariable)t).getBounds();
+ if(bounds.length == 1)
+ {
+ return getRawType(bounds[0]);
+ }
+ }
+ throw new ServerScopedRuntimeException("Unable to process type when constructing configuration model: " + t);
+ }
+
+ @Override
+ public List convert(final Object value, final ConfiguredObject object)
+ {
+ if(value instanceof Collection)
+ {
+ Collection original = (Collection)value;
+ List converted = new ArrayList(original.size());
+ for(Object member : original)
+ {
+ converted.add(_memberConverter.convert(member, object));
+ }
+ return Collections.unmodifiableList(converted);
+ }
+ else if(value instanceof Object[])
+ {
+ return convert(Arrays.asList((Object[])value),object);
+ }
+ else if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ return Collections.unmodifiableList(Collections.singletonList(_memberConverter.convert(value, object)));
+ }
+ }
+ }
+
+ public static class GenericSetConverter extends AttributeValueConverter<Set>
+ {
+
+ private final AttributeValueConverter<?> _memberConverter;
+
+ public GenericSetConverter(final Type genericType)
+ {
+ _memberConverter = getConverter(getRawType(genericType), genericType);
+ }
+
+ private static Class getRawType(Type t)
+ {
+ if(t instanceof Class)
+ {
+ return (Class)t;
+ }
+ else if(t instanceof ParameterizedType)
+ {
+ return (Class)((ParameterizedType)t).getRawType();
+ }
+ else if(t instanceof TypeVariable)
+ {
+ Type[] bounds = ((TypeVariable)t).getBounds();
+ if(bounds.length == 1)
+ {
+ return getRawType(bounds[0]);
+ }
+ }
+ throw new ServerScopedRuntimeException("Unable to process type when constructing configuration model: " + t);
+ }
+
+ @Override
+ public Set convert(final Object value, final ConfiguredObject object)
+ {
+ if(value instanceof Collection)
+ {
+ Collection original = (Collection)value;
+ Set converted = new HashSet(original.size());
+ for(Object member : original)
+ {
+ converted.add(_memberConverter.convert(member, object));
+ }
+ return Collections.unmodifiableSet(converted);
+ }
+ else if(value instanceof Object[])
+ {
+ return convert(new HashSet(Arrays.asList((Object[])value)),object);
+ }
+ else if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ return Collections.unmodifiableSet(Collections.singleton(_memberConverter.convert(value, object)));
+ }
+ }
+ }
+
+ public static class GenericCollectionConverter extends AttributeValueConverter<Collection>
+ {
+
+ private final AttributeValueConverter<?> _memberConverter;
+
+ public GenericCollectionConverter(final Type genericType)
+ {
+ _memberConverter = getConverter(getRawType(genericType), genericType);
+ }
+
+ private static Class getRawType(Type t)
+ {
+ if(t instanceof Class)
+ {
+ return (Class)t;
+ }
+ else if(t instanceof ParameterizedType)
+ {
+ return (Class)((ParameterizedType)t).getRawType();
+ }
+ else if(t instanceof TypeVariable)
+ {
+ Type[] bounds = ((TypeVariable)t).getBounds();
+ if(bounds.length == 1)
+ {
+ return getRawType(bounds[0]);
+ }
+ }
+ throw new ServerScopedRuntimeException("Unable to process type when constructing configuration model: " + t);
+ }
+
+ @Override
+ public Collection convert(final Object value, final ConfiguredObject object)
+ {
+ if(value instanceof Collection)
+ {
+ Collection original = (Collection)value;
+ Collection converted = new ArrayList(original.size());
+ for(Object member : original)
+ {
+ converted.add(_memberConverter.convert(member, object));
+ }
+ return Collections.unmodifiableCollection(converted);
+ }
+ else if(value instanceof Object[])
+ {
+ return convert(Arrays.asList((Object[])value),object);
+ }
+ else if(value == null)
+ {
+ return null;
+ }
+ else
+ {
+ return Collections.unmodifiableCollection(Collections.singletonList(_memberConverter.convert(value, object)));
+ }
+ }
+ }
+
+ static final class EnumConverter<X extends Enum<X>> extends AttributeValueConverter<X>
+ {
+ private final Class<X> _klazz;
+
+ private EnumConverter(final Class<X> klazz)
+ {
+ _klazz = klazz;
+ }
+
+ @Override
+ public X convert(final Object value, final ConfiguredObject object)
+ {
+ if(value == null)
+ {
+ return null;
+ }
+ else if(_klazz.isInstance(value))
+ {
+ return (X) value;
+ }
+ else if(value instanceof String)
+ {
+ return Enum.valueOf(_klazz, AbstractConfiguredObject.interpolate(object, (String) value));
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a " + _klazz.getName());
+ }
+ }
+ }
+
+ static final class ConfiguredObjectConverter<X extends ConfiguredObject<X>> extends AttributeValueConverter<X>
+ {
+ private final Class<X> _klazz;
+
+ private ConfiguredObjectConverter(final Class<X> klazz)
+ {
+ _klazz = klazz;
+ }
+
+ @Override
+ public X convert(final Object value, final ConfiguredObject object)
+ {
+ if(value == null)
+ {
+ return null;
+ }
+ else if(_klazz.isInstance(value))
+ {
+ return (X) value;
+ }
+ else if(value instanceof UUID)
+ {
+ Collection<X> reachable = AbstractConfiguredObject.getReachableObjects(object, _klazz);
+ for(X candidate : reachable)
+ {
+ if(candidate.getId().equals(value))
+ {
+ return candidate;
+ }
+ }
+ throw new IllegalArgumentException("Cannot find a " + _klazz.getName() + " with id " + value);
+ }
+ else if(value instanceof String)
+ {
+ String valueStr = AbstractConfiguredObject.interpolate(object, (String) value);
+ Collection<X> reachable = AbstractConfiguredObject.getReachableObjects(object, _klazz);
+ for(X candidate : reachable)
+ {
+ if(candidate.getName().equals(valueStr))
+ {
+ return candidate;
+ }
+ }
+ try
+ {
+ UUID id = UUID.fromString(valueStr);
+ return convert(id, object);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new IllegalArgumentException("Cannot find a " + _klazz.getSimpleName() + " with name '" + valueStr + "'");
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("Cannot convert type " + value.getClass() + " to a " + _klazz.getName());
+ }
+ }
+
+ }
+}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
index 9f0237e97a..ed7e9ac60e 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
@@ -231,7 +231,7 @@ public interface ConfiguredObject<X extends ConfiguredObject<X>>
*/
Object getAttribute(String name);
- <T> T getAttribute(AbstractConfiguredObject.Attribute<? super X, T> attr);
+ <T> T getAttribute(ConfiguredObjectAttribute<? super X, T> attr);
/**
* Return the map containing only explicitly set attributes
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttribute.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttribute.java
new file mode 100644
index 0000000000..5c4ed71902
--- /dev/null
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttribute.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.model;
+
+import java.lang.reflect.Method;
+
+public final class ConfiguredObjectAttribute<C extends ConfiguredObject, T> extends ConfiguredObjectAttributeOrStatistic<C,T>
+{
+
+ private final ManagedAttribute _annotation;
+
+ ConfiguredObjectAttribute(Class<C> clazz,
+ final Method getter,
+ final ManagedAttribute annotation)
+ {
+ super(getter);
+ if(getter.getParameterTypes().length != 0)
+ {
+ throw new IllegalArgumentException("ManagedAttribute annotation should only be added to no-arg getters");
+ }
+ _annotation = annotation;
+ }
+
+ public ManagedAttribute getAnnotation()
+ {
+ return _annotation;
+ }
+
+ public T convert(final Object value, C object)
+ {
+ return _converter.convert(value, object);
+ }
+}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttributeOrStatistic.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttributeOrStatistic.java
new file mode 100644
index 0000000000..da1edd7da2
--- /dev/null
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectAttributeOrStatistic.java
@@ -0,0 +1,155 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.model;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+abstract class ConfiguredObjectAttributeOrStatistic<C extends ConfiguredObject, T>
+{
+
+ protected final String _name;
+ protected final Class<T> _type;
+ protected final AttributeValueConverter<T> _converter;
+ protected final Method _getter;
+
+ ConfiguredObjectAttributeOrStatistic(final Method getter)
+ {
+
+ _getter = getter;
+ _type = (Class<T>) getTypeFromMethod(getter);
+ _name = getNameFromMethod(getter, _type);
+ _converter = AttributeValueConverter.getConverter(_type, getter.getGenericReturnType());
+
+ }
+
+ private static String getNameFromMethod(final Method m, final Class<?> type)
+ {
+ String methodName = m.getName();
+ String baseName;
+
+ if(type == Boolean.class )
+ {
+ if((methodName.startsWith("get") || methodName.startsWith("has")) && methodName.length() >= 4)
+ {
+ baseName = methodName.substring(3);
+ }
+ else if(methodName.startsWith("is") && methodName.length() >= 3)
+ {
+ baseName = methodName.substring(2);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Method name " + methodName + " does not conform to the required pattern for ManagedAttributes");
+ }
+ }
+ else
+ {
+ if(methodName.startsWith("get") && methodName.length() >= 4)
+ {
+ baseName = methodName.substring(3);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Method name " + methodName + " does not conform to the required pattern for ManagedAttributes");
+ }
+ }
+
+ String name = baseName.length() == 1 ? baseName.toLowerCase() : baseName.substring(0,1).toLowerCase() + baseName.substring(1);
+ name = name.replace('_','.');
+ return name;
+ }
+
+ private static Class<?> getTypeFromMethod(final Method m)
+ {
+ Class<?> type = m.getReturnType();
+ if(type.isPrimitive())
+ {
+ if(type == Boolean.TYPE)
+ {
+ type = Boolean.class;
+ }
+ else if(type == Byte.TYPE)
+ {
+ type = Byte.class;
+ }
+ else if(type == Short.TYPE)
+ {
+ type = Short.class;
+ }
+ else if(type == Integer.TYPE)
+ {
+ type = Integer.class;
+ }
+ else if(type == Long.TYPE)
+ {
+ type = Long.class;
+ }
+ else if(type == Float.TYPE)
+ {
+ type = Float.class;
+ }
+ else if(type == Double.TYPE)
+ {
+ type = Double.class;
+ }
+ else if(type == Character.TYPE)
+ {
+ type = Character.class;
+ }
+ }
+ return type;
+ }
+
+ public String getName()
+ {
+ return _name;
+ }
+
+ public Class<T> getType()
+ {
+ return _type;
+ }
+
+ public T getValue(C configuredObject)
+ {
+ try
+ {
+ return (T) _getter.invoke(configuredObject);
+ }
+ catch (IllegalAccessException e)
+ {
+ Object o = configuredObject.getAttribute(_name);
+ return _converter.convert(o, configuredObject);
+ }
+ catch (InvocationTargetException e)
+ {
+ Object o = configuredObject.getAttribute(_name);
+ return _converter.convert(o, configuredObject);
+ }
+
+ }
+
+ public Method getGetter()
+ {
+ return _getter;
+ }
+}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactory.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactory.java
index 324fc41ec1..1c5afa6175 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactory.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactory.java
@@ -39,8 +39,12 @@ public class ConfiguredObjectFactory
new HashMap<String, Map<String, ConfiguredObjectTypeFactory>>();
private final Map<String, Collection<String>> _supportedTypes = new HashMap<String, Collection<String>>();
- public ConfiguredObjectFactory()
+ private final Model _model;
+
+ public ConfiguredObjectFactory(Model model)
{
+ _model = model;
+
QpidServiceLoader<ConfiguredObjectTypeFactory> serviceLoader = new QpidServiceLoader<ConfiguredObjectTypeFactory>();
Iterable<ConfiguredObjectTypeFactory> allFactories = serviceLoader.instancesOf(ConfiguredObjectTypeFactory.class);
for(ConfiguredObjectTypeFactory factory : allFactories)
@@ -81,7 +85,7 @@ public class ConfiguredObjectFactory
String type = (String) record.getAttributes().get(ConfiguredObject.TYPE);
- ConfiguredObjectTypeFactory factory = getConfiguredObjectTypeFactory(category, type);
+ ConfiguredObjectTypeFactory<X> factory = getConfiguredObjectTypeFactory(category, type);
if(factory == null)
{
@@ -101,7 +105,7 @@ public class ConfiguredObjectFactory
}
String type = (String) attributes.get(ConfiguredObject.TYPE);
- ConfiguredObjectTypeFactory factory;
+ ConfiguredObjectTypeFactory<X> factory;
if(type != null)
{
@@ -119,7 +123,7 @@ public class ConfiguredObjectFactory
return factory;
}
- public ConfiguredObjectTypeFactory getConfiguredObjectTypeFactory(final String category, final String type)
+ public <X extends ConfiguredObject<X>> ConfiguredObjectTypeFactory<X> getConfiguredObjectTypeFactory(final String category, final String type)
{
Map<String, ConfiguredObjectTypeFactory> categoryFactories = _allFactories.get(category);
if(categoryFactories == null)
@@ -138,4 +142,11 @@ public class ConfiguredObjectFactory
{
return Collections.unmodifiableCollection(_supportedTypes.get(category.getSimpleName()));
}
+
+
+ public Model getModel()
+ {
+ return _model;
+ }
+
}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectStatistic.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectStatistic.java
new file mode 100644
index 0000000000..a5cd03d4f7
--- /dev/null
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectStatistic.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.model;
+
+import java.lang.reflect.Method;
+
+final class ConfiguredObjectStatistic<C extends ConfiguredObject, T extends Number> extends
+ ConfiguredObjectAttributeOrStatistic<C,T>
+{
+ ConfiguredObjectStatistic(Class<C> clazz, final Method getter)
+ {
+ super(getter);
+ if(getter.getParameterTypes().length != 0)
+ {
+ throw new IllegalArgumentException("ManagedStatistic annotation should only be added to no-arg getters");
+ }
+
+ if(!Number.class.isAssignableFrom(getType()))
+ {
+ throw new IllegalArgumentException("ManagedStatistic annotation should only be added to getters returning a Number type");
+ }
+ }
+}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Model.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Model.java
index 5630b1c20d..36049950e7 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Model.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Model.java
@@ -25,9 +25,11 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
-public class Model
+public abstract class Model
{
/*
* API version for the broker model
@@ -41,87 +43,208 @@ public class Model
public static final int MODEL_MINOR_VERSION = 4;
public static final String MODEL_VERSION = MODEL_MAJOR_VERSION + "." + MODEL_MINOR_VERSION;
- private static final Model MODEL_INSTANCE = new Model();
-
- private final Map<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>>
- _parents = new HashMap<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>>();
-
- private final Map<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>>
- _children = new HashMap<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>>();
+ private static final Model MODEL_INSTANCE = new ModelImpl();
public static Model getInstance()
{
return MODEL_INSTANCE;
}
- private Model()
+ public static Class<? extends ConfiguredObject> getCategory(final Class<?> clazz)
+ {
+ ManagedObject annotation = clazz.getAnnotation(ManagedObject.class);
+ if(annotation != null && annotation.category())
+ {
+ return (Class<? extends ConfiguredObject>) clazz;
+ }
+ for(Class<?> iface : clazz.getInterfaces() )
+ {
+ Class<? extends ConfiguredObject> cat = getCategory(iface);
+ if(cat != null)
+ {
+ return cat;
+ }
+ }
+ if(clazz.getSuperclass() != null)
+ {
+ return getCategory(clazz.getSuperclass());
+ }
+ return null;
+ }
+
+ public static String getType(final Class<? extends ConfiguredObject> clazz)
{
- addRelationship(SystemContext.class, Broker.class);
+ ManagedObject annotation = clazz.getAnnotation(ManagedObject.class);
+ if(annotation != null)
+ {
+ if(!"".equals(annotation.type()))
+ {
+ return annotation.type();
+ }
+ }
- addRelationship(Broker.class, VirtualHost.class);
- addRelationship(Broker.class, Port.class);
- addRelationship(Broker.class, AccessControlProvider.class);
- addRelationship(Broker.class, AuthenticationProvider.class);
- addRelationship(Broker.class, GroupProvider.class);
- addRelationship(Broker.class, TrustStore.class);
- addRelationship(Broker.class, KeyStore.class);
- addRelationship(Broker.class, Plugin.class);
+ if(clazz.getSuperclass() != null && ConfiguredObject.class.isAssignableFrom(clazz.getSuperclass()))
+ {
+ String type = getType((Class<? extends ConfiguredObject>) clazz.getSuperclass());
+ if(!"".equals(type))
+ {
+ return type;
+ }
+ }
- addRelationship(VirtualHost.class, Exchange.class);
- addRelationship(VirtualHost.class, Queue.class);
- addRelationship(VirtualHost.class, Connection.class);
- addRelationship(VirtualHost.class, VirtualHostAlias.class);
+ for(Class<?> iface : clazz.getInterfaces() )
+ {
+ if(ConfiguredObject.class.isAssignableFrom(iface))
+ {
+ String type = getType((Class<? extends ConfiguredObject>) iface);
+ if(!"".equals(type))
+ {
+ return type;
+ }
+ }
+ }
+ Class<? extends ConfiguredObject> category = getCategory(clazz);
+ if(category == null)
+ {
+ return "";
+ }
+ annotation = category.getAnnotation(ManagedObject.class);
+ if(annotation == null)
+ {
+ throw new NullPointerException("No definition found for category " + category.getSimpleName());
+ }
+ if(!"".equals(annotation.defaultType()))
+ {
+ return annotation.defaultType();
+ }
+ return category.getSimpleName();
+ }
- addRelationship(AuthenticationProvider.class, User.class);
- addRelationship(AuthenticationProvider.class, PreferencesProvider.class);
- addRelationship(User.class, GroupMember.class);
+ public abstract Collection<Class<? extends ConfiguredObject>> getSupportedCategories();
+ public abstract Collection<Class<? extends ConfiguredObject>> getChildTypes(Class<? extends ConfiguredObject> parent);
- addRelationship(GroupProvider.class, Group.class);
- addRelationship(Group.class, GroupMember.class);
+ public abstract Class<? extends ConfiguredObject<?>> getRootCategory();
- addRelationship(Connection.class, Session.class);
+ public abstract Collection<Class<? extends ConfiguredObject>> getParentTypes(Class<? extends ConfiguredObject> child);
+ public abstract int getMajorVersion();
+ public abstract int getMinorVersion();
- addRelationship(Queue.class, Binding.class);
- addRelationship(Queue.class, Consumer.class);
+ private static class ModelImpl extends Model
+ {
- addRelationship(Exchange.class, Binding.class);
- addRelationship(Exchange.class, Publisher.class);
+ private final Map<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>> _parents =
+ new HashMap<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>>();
- addRelationship(Session.class, Consumer.class);
- addRelationship(Session.class, Publisher.class);
- }
+ private final Map<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>> _children =
+ new HashMap<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>>();
- public Collection<Class<? extends ConfiguredObject>> getParentTypes(Class<? extends ConfiguredObject> child)
- {
- Collection<Class<? extends ConfiguredObject>> parentTypes = _parents.get(child);
- return parentTypes == null ? Collections.<Class<? extends ConfiguredObject>>emptyList()
- : Collections.unmodifiableCollection(parentTypes);
- }
+ private final Set<Class<? extends ConfiguredObject>> _supportedTypes =
+ new HashSet<Class<? extends ConfiguredObject>>();
- public Collection<Class<? extends ConfiguredObject>> getChildTypes(Class<? extends ConfiguredObject> parent)
- {
- Collection<Class<? extends ConfiguredObject>> childTypes = _children.get(parent);
- return childTypes == null ? Collections.<Class<? extends ConfiguredObject>>emptyList()
- : Collections.unmodifiableCollection(childTypes);
- }
+ private final Class<? extends ConfiguredObject<?>> _rootCategory;
- private void addRelationship(Class<? extends ConfiguredObject> parent, Class<? extends ConfiguredObject> child)
- {
- Collection<Class<? extends ConfiguredObject>> parents = _parents.get(child);
- if(parents == null)
+ private ModelImpl()
{
- parents = new ArrayList<Class<? extends ConfiguredObject>>();
- _parents.put(child, parents);
+ _rootCategory = SystemContext.class;
+
+ addRelationship(SystemContext.class, Broker.class);
+
+ addRelationship(Broker.class, VirtualHost.class);
+ addRelationship(Broker.class, Port.class);
+ addRelationship(Broker.class, AccessControlProvider.class);
+ addRelationship(Broker.class, AuthenticationProvider.class);
+ addRelationship(Broker.class, GroupProvider.class);
+ addRelationship(Broker.class, TrustStore.class);
+ addRelationship(Broker.class, KeyStore.class);
+ addRelationship(Broker.class, Plugin.class);
+
+ addRelationship(VirtualHost.class, Exchange.class);
+ addRelationship(VirtualHost.class, Queue.class);
+ addRelationship(VirtualHost.class, Connection.class);
+ addRelationship(VirtualHost.class, VirtualHostAlias.class);
+
+ addRelationship(Port.class, VirtualHostAlias.class);
+
+
+ addRelationship(AuthenticationProvider.class, User.class);
+ addRelationship(AuthenticationProvider.class, PreferencesProvider.class);
+ addRelationship(User.class, GroupMember.class);
+
+ addRelationship(GroupProvider.class, Group.class);
+ addRelationship(Group.class, GroupMember.class);
+
+ addRelationship(Connection.class, Session.class);
+
+ addRelationship(Queue.class, Binding.class);
+ addRelationship(Queue.class, Consumer.class);
+
+ addRelationship(Exchange.class, Binding.class);
+ addRelationship(Exchange.class, Publisher.class);
+
+ addRelationship(Session.class, Consumer.class);
+ addRelationship(Session.class, Publisher.class);
}
- parents.add(parent);
- Collection<Class<? extends ConfiguredObject>> children = _children.get(parent);
- if(children == null)
+ @Override
+ public Class<? extends ConfiguredObject<?>> getRootCategory()
{
- children = new ArrayList<Class<? extends ConfiguredObject>>();
- _children.put(parent, children);
+ return _rootCategory;
+ }
+
+ public Collection<Class<? extends ConfiguredObject>> getParentTypes(Class<? extends ConfiguredObject> child)
+ {
+ Collection<Class<? extends ConfiguredObject>> parentTypes = _parents.get(child);
+ return parentTypes == null ? Collections.<Class<? extends ConfiguredObject>>emptyList()
+ : Collections.unmodifiableCollection(parentTypes);
}
- children.add(child);
- }
+ @Override
+ public int getMajorVersion()
+ {
+ return MODEL_MAJOR_VERSION;
+ }
+
+ @Override
+ public int getMinorVersion()
+ {
+ return MODEL_MINOR_VERSION;
+ }
+
+ public Collection<Class<? extends ConfiguredObject>> getChildTypes(Class<? extends ConfiguredObject> parent)
+ {
+ Collection<Class<? extends ConfiguredObject>> childTypes = _children.get(parent);
+ return childTypes == null ? Collections.<Class<? extends ConfiguredObject>>emptyList()
+ : Collections.unmodifiableCollection(childTypes);
+ }
+
+ @Override
+ public Collection<Class<? extends ConfiguredObject>> getSupportedCategories()
+ {
+ return Collections.unmodifiableSet(_supportedTypes);
+ }
+
+ private void addRelationship(Class<? extends ConfiguredObject> parent, Class<? extends ConfiguredObject> child)
+ {
+ Collection<Class<? extends ConfiguredObject>> parents = _parents.get(child);
+ if (parents == null)
+ {
+ parents = new ArrayList<Class<? extends ConfiguredObject>>();
+ _parents.put(child, parents);
+ }
+ parents.add(parent);
+
+ Collection<Class<? extends ConfiguredObject>> children = _children.get(parent);
+ if (children == null)
+ {
+ children = new ArrayList<Class<? extends ConfiguredObject>>();
+ _children.put(parent, children);
+ }
+ children.add(child);
+
+ _supportedTypes.add(parent);
+ _supportedTypes.add(child);
+
+ }
+
+ }
}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/SystemContext.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/SystemContext.java
index 8e3a2acd79..dda65d2b3e 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/SystemContext.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/SystemContext.java
@@ -63,7 +63,9 @@ public class SystemContext extends AbstractConfiguredObject<SystemContext>
final LogRecorder logRecorder,
final BrokerOptions brokerOptions)
{
- super(SYSTEM_ID, createAttributes(brokerOptions), taskExecutor);
+ super(parentsMap(),
+ combineIdWithAttributes(SYSTEM_ID, createAttributes(brokerOptions)),
+ taskExecutor);
_eventLogger = eventLogger;
getTaskExecutor().start();
_objectFactory = configuredObjectFactory;
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java
index e08538b1ec..4502a7e53f 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/AbstractPluginAdapter.java
@@ -40,7 +40,7 @@ public abstract class AbstractPluginAdapter<X extends Plugin<X>> extends Abstrac
protected AbstractPluginAdapter(UUID id, Map<String, Object> attributes, Broker broker)
{
- super(Collections.<Class<? extends ConfiguredObject>, ConfiguredObject<?>>singletonMap(Broker.class, broker),
+ super(parentsMap(broker),
combineIdWithAttributes(id, attributes), broker.getTaskExecutor());
_broker = broker;
}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
index 019b22c84e..d8ad780be0 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
@@ -136,7 +136,7 @@ public class BrokerAdapter extends AbstractConfiguredObject<BrokerAdapter> imple
Map<String, Object> attributes,
SystemContext parent)
{
- super(Collections.<Class<? extends ConfiguredObject>, ConfiguredObject<?>>singletonMap(SystemContext.class, parent),
+ super(parentsMap(parent),
combineIdWithAttributes(id,MapValueConverter.convert(attributes, ATTRIBUTE_TYPES)), parent.getTaskExecutor());
_objectFactory = parent.getObjectFactory();
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java
index f432a540e5..25c0a97b14 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/ConnectionAdapter.java
@@ -60,7 +60,7 @@ public final class ConnectionAdapter extends AbstractConfiguredObject<Connection
public ConnectionAdapter(final AMQConnectionModel conn, TaskExecutor taskExecutor)
{
- super(createAttributes(conn), taskExecutor);
+ super(parentsMap(conn.getVirtualHost()),createAttributes(conn), taskExecutor);
_connection = conn;
open();
conn.addSessionListener(this);
@@ -344,7 +344,7 @@ public final class ConnectionAdapter extends AbstractConfiguredObject<Connection
{
if(!_sessionAdapters.containsKey(session))
{
- SessionAdapter adapter = new SessionAdapter(session, getTaskExecutor());
+ SessionAdapter adapter = new SessionAdapter(this, session, getTaskExecutor());
_sessionAdapters.put(session, adapter);
childAdded(adapter);
}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileBasedGroupProvider.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileBasedGroupProvider.java
index c28f56bfb4..3578fba7a4 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileBasedGroupProvider.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileBasedGroupProvider.java
@@ -53,7 +53,7 @@ public class FileBasedGroupProvider
Broker broker,
Map<String, Object> attributes)
{
- super(Collections.<Class<? extends ConfiguredObject>,ConfiguredObject<?>>singletonMap(Broker.class, broker),
+ super(parentsMap(broker),
combineIdWithAttributes(id, attributes), broker.getTaskExecutor());
@@ -358,7 +358,7 @@ public class FileBasedGroupProvider
public GroupAdapter(Map<String,Object> attributes, TaskExecutor taskExecutor)
{
- super(attributes, taskExecutor);
+ super(parentsMap(FileBasedGroupProvider.this), attributes, taskExecutor);
}
@@ -508,7 +508,8 @@ public class FileBasedGroupProvider
public GroupMemberAdapter(Map<String,Object> attrMap, TaskExecutor taskExecutor)
{
- super(attrMap, taskExecutor);
+ // TODO - need to relate to the User object
+ super(parentsMap(GroupAdapter.this),attrMap, taskExecutor);
}
@Override
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProvider.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProvider.java
index 521803ecda..b1df475322 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProvider.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProvider.java
@@ -85,7 +85,7 @@ public class FileSystemPreferencesProvider extends AbstractConfiguredObject<File
public FileSystemPreferencesProvider(UUID id, Map<String, Object> attributes,
AuthenticationProvider<? extends AuthenticationProvider> authenticationProvider)
{
- super(Collections.<Class<? extends ConfiguredObject>, ConfiguredObject<?>>singletonMap(AuthenticationProvider.class, authenticationProvider),
+ super(parentsMap(authenticationProvider),
combineIdWithAttributes(id,MapValueConverter.convert(attributes, ATTRIBUTE_TYPES)),
authenticationProvider.getParent(Broker.class).getTaskExecutor());
State state = MapValueConverter.getEnumAttribute(State.class, STATE, attributes, State.INITIALISING);
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java
index 0d11b6e97d..3194709743 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java
@@ -43,9 +43,11 @@ final class SessionAdapter extends AbstractConfiguredObject<SessionAdapter> impl
@ManagedAttributeField
private int _channelId;
- public SessionAdapter(final AMQSessionModel session, TaskExecutor taskExecutor)
+ public SessionAdapter(final ConnectionAdapter connectionAdapter,
+ final AMQSessionModel session,
+ TaskExecutor taskExecutor)
{
- super(createAttributes(session), taskExecutor);
+ super(parentsMap(connectionAdapter), createAttributes(session), taskExecutor);
_session = session;
_session.addConsumerListener(new ConsumerListener()
{
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java
index 15843d14fe..d9d8877d01 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAliasAdapter.java
@@ -44,8 +44,8 @@ public class VirtualHostAliasAdapter extends AbstractConfiguredObject<VirtualHos
public VirtualHostAliasAdapter(VirtualHost virtualHost, Port port)
{
- super(
- createAttributes(virtualHost, port),
+ super(parentsMap(virtualHost,port),
+ createAttributes(virtualHost, port),
virtualHost.getTaskExecutor());
_vhost = virtualHost;
_port = port;
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java
index abdd118d10..80dab3c96c 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java
@@ -88,7 +88,7 @@ abstract public class AbstractPort<X extends AbstractPort<X>> extends AbstractCo
Map<String, Object> attributes,
TaskExecutor taskExecutor)
{
- super(Collections.<Class<? extends ConfiguredObject>,ConfiguredObject<?>>singletonMap(Broker.class, broker),
+ super(parentsMap(broker),
combineIdWithAttributes(id,attributes),
taskExecutor);
_broker = broker;
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/PortFactory.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/PortFactory.java
index 0d97d10dee..be9240c64c 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/PortFactory.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/PortFactory.java
@@ -29,14 +29,11 @@ import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.ConfiguredObjectFactory;
+import org.apache.qpid.server.model.Model;
import org.apache.qpid.server.model.Port;
import org.apache.qpid.server.model.Protocol;
import org.apache.qpid.server.model.Protocol.ProtocolType;
import org.apache.qpid.server.model.Transport;
-import org.apache.qpid.server.model.port.AmqpPort;
-import org.apache.qpid.server.model.port.HttpPort;
-import org.apache.qpid.server.model.port.JmxPort;
-import org.apache.qpid.server.model.port.RmiPort;
import org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory;
import org.apache.qpid.server.store.ConfiguredObjectRecord;
import org.apache.qpid.server.store.UnresolvedConfiguredObject;
@@ -136,7 +133,7 @@ public class PortFactory<X extends Port<X>> implements ConfiguredObjectTypeFacto
{
if(_configuredObjectFactory == null)
{
- _configuredObjectFactory = new ConfiguredObjectFactory();
+ _configuredObjectFactory = new ConfiguredObjectFactory(Model.getInstance());
}
}
return _configuredObjectFactory.getConfiguredObjectTypeFactory(Port.class.getSimpleName(), type);
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/protocol/AMQConnectionModel.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/protocol/AMQConnectionModel.java
index 624e2cd280..5d898c3a36 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/protocol/AMQConnectionModel.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/protocol/AMQConnectionModel.java
@@ -20,18 +20,17 @@
*/
package org.apache.qpid.server.protocol;
+import java.net.SocketAddress;
+import java.security.Principal;
+import java.util.List;
+
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.model.Port;
import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.util.Deletable;
-import org.apache.qpid.transport.SessionListener;
-
-import java.net.SocketAddress;
-import java.security.Principal;
-import java.util.List;
-import java.util.UUID;
public interface AMQConnectionModel<T extends AMQConnectionModel<T,S>, S extends AMQSessionModel<S,T>> extends StatisticsGatherer, Deletable<T>
{
@@ -96,6 +95,8 @@ public interface AMQConnectionModel<T extends AMQConnectionModel<T,S>, S extends
boolean isStopped();
+ VirtualHost<?,?,?> getVirtualHost();
+
String getVirtualHostName();
String getRemoteContainerName();
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
index 0800dcbb57..76002970b8 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
@@ -75,7 +75,6 @@ import org.apache.qpid.server.model.ManagedAttributeField;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.QueueNotificationListener;
import org.apache.qpid.server.model.State;
-import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.protocol.AMQConnectionModel;
import org.apache.qpid.server.protocol.AMQSessionModel;
import org.apache.qpid.server.security.SecurityManager;
@@ -243,7 +242,7 @@ public abstract class AbstractQueue
Map<String, Object> attributes,
QueueEntryListFactory entryListFactory)
{
- super(Collections.<Class<? extends ConfiguredObject>, ConfiguredObject<?>>singletonMap(VirtualHost.class, virtualHost),
+ super(parentsMap(virtualHost),
attributes, virtualHost.getTaskExecutor());
_entries = entryListFactory.createQueueEntryList(this);
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/QueueConsumerImpl.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/QueueConsumerImpl.java
index 8910a7ef60..fd6528d4ad 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/QueueConsumerImpl.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/queue/QueueConsumerImpl.java
@@ -121,8 +121,8 @@ class QueueConsumerImpl
final Class<? extends ServerMessage> messageClass,
EnumSet<Option> optionSet)
{
- super(
- createAttributeMap(consumerName,filters,optionSet),
+ super(parentsMap(queue),
+ createAttributeMap(consumerName, filters, optionSet),
queue.getVirtualHost().getTaskExecutor());
_messageClass = messageClass;
_sessionReference = target.getSessionModel().getConnectionReference();
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/FileKeyStore.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/FileKeyStore.java
index b26f8e28cf..b1be18dc97 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/FileKeyStore.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/FileKeyStore.java
@@ -40,7 +40,6 @@ import javax.net.ssl.KeyManagerFactory;
import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.model.AbstractConfiguredObject;
import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.IntegrityViolationException;
import org.apache.qpid.server.model.KeyStore;
import org.apache.qpid.server.model.LifetimePolicy;
@@ -117,7 +116,7 @@ public class FileKeyStore extends AbstractConfiguredObject<FileKeyStore> impleme
public FileKeyStore(UUID id, Broker<?> broker, Map<String, Object> attributes)
{
- super(Collections.<Class<? extends ConfiguredObject>,ConfiguredObject<?>>singletonMap(Broker.class, broker),
+ super(parentsMap(broker),
combineIdWithAttributes(id, attributes),
broker.getTaskExecutor());
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/FileTrustStore.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/FileTrustStore.java
index 694d67b915..8111724f0c 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/FileTrustStore.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/FileTrustStore.java
@@ -104,7 +104,7 @@ public class FileTrustStore extends AbstractConfiguredObject<FileTrustStore> imp
public FileTrustStore(UUID id, Broker<?> broker, Map<String, Object> attributes)
{
- super(Collections.<Class<? extends ConfiguredObject>,ConfiguredObject<?>>singletonMap(Broker.class, broker),
+ super(parentsMap(broker),
combineIdWithAttributes(id, attributes),
broker.getTaskExecutor());
_broker = broker;
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractAuthenticationManager.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractAuthenticationManager.java
index a3e88031b2..52e4168cdd 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractAuthenticationManager.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/AbstractAuthenticationManager.java
@@ -23,7 +23,6 @@ package org.apache.qpid.server.security.auth.manager;
import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@@ -40,6 +39,7 @@ import org.apache.qpid.server.model.ConfiguredObjectFactory;
import org.apache.qpid.server.model.IllegalStateTransitionException;
import org.apache.qpid.server.model.IntegrityViolationException;
import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Model;
import org.apache.qpid.server.model.Port;
import org.apache.qpid.server.model.PreferencesProvider;
import org.apache.qpid.server.model.State;
@@ -63,7 +63,7 @@ public abstract class AbstractAuthenticationManager<T extends AbstractAuthentica
protected AbstractAuthenticationManager(final Broker broker,
final Map<String, Object> attributes)
{
- super(Collections.<Class<? extends ConfiguredObject>, ConfiguredObject<?>>singletonMap(Broker.class, broker),
+ super(parentsMap(broker),
attributes, broker.getTaskExecutor());
_broker = broker;
}
@@ -176,7 +176,7 @@ public abstract class AbstractAuthenticationManager<T extends AbstractAuthentica
if(childClass == PreferencesProvider.class)
{
// TODO RG - get the configured object factory from parents
- ConfiguredObjectFactory factory = new ConfiguredObjectFactory();
+ ConfiguredObjectFactory factory = new ConfiguredObjectFactory(Model.getInstance());
attributes = new HashMap<String, Object>(attributes);
attributes.put(ConfiguredObject.ID, UUID.randomUUID());
final ConfiguredObjectTypeFactory preferencesFactory =
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
index 354ae2c70c..c51ab38328 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
@@ -354,7 +354,7 @@ public abstract class PrincipalDatabaseAuthenticationManager<T extends Principal
public PrincipalAdapter(Principal user)
{
- super(createPrincipalAttributes(PrincipalDatabaseAuthenticationManager.this, user),
+ super(parentsMap(PrincipalDatabaseAuthenticationManager.this),createPrincipalAttributes(PrincipalDatabaseAuthenticationManager.this, user),
PrincipalDatabaseAuthenticationManager.this.getTaskExecutor());
_user = user;
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ScramSHA1AuthenticationManager.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ScramSHA1AuthenticationManager.java
index a8fdaacb23..82c045fe2d 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ScramSHA1AuthenticationManager.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ScramSHA1AuthenticationManager.java
@@ -27,7 +27,6 @@ import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import java.security.SecureRandom;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -48,7 +47,6 @@ import org.apache.qpid.server.configuration.RecovererProvider;
import org.apache.qpid.server.configuration.updater.ChangeAttributesTask;
import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.model.AbstractConfiguredObject;
-import org.apache.qpid.server.model.AuthenticationProvider;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.LifetimePolicy;
@@ -272,7 +270,7 @@ public class ScramSHA1AuthenticationManager
userAttrs.put(User.PASSWORD, createStoredPassword(password));
userAttrs.put(User.TYPE, SCRAM_USER_TYPE);
ScramAuthUser user = new ScramAuthUser(userAttrs, this);
- _users.put(username, user);
+ user.create();
return true;
}
@@ -420,14 +418,6 @@ public class ScramSHA1AuthenticationManager
}
- private static Map<Class<? extends ConfiguredObject>, ConfiguredObject<?>> parentsMap(final ScramSHA1AuthenticationManager scramSHA1AuthenticationManager)
- {
-
- final Map<Class<? extends ConfiguredObject>, ConfiguredObject<?>> map = new HashMap<Class<? extends ConfiguredObject>, ConfiguredObject<?>>();
- map.put(AuthenticationProvider.class, scramSHA1AuthenticationManager);
- return map;
- }
-
@Override
public ConfiguredObjectRecoverer<? extends ConfiguredObject> getRecoverer(final String type)
{
@@ -452,12 +442,20 @@ public class ScramSHA1AuthenticationManager
}
@Override
+ protected void onOpen()
+ {
+ super.onOpen();
+ _authenticationManager._users.put(getName(), this);
+ }
+
+ @Override
protected boolean setState(final State currentState, final State desiredState)
{
if(desiredState == State.DELETED)
{
_authenticationManager.getSecurityManager().authoriseUserOperation(Operation.DELETE, getName());
_authenticationManager._users.remove(getName());
+ _authenticationManager.unregisterChild(this);
_authenticationManager.childRemoved(this);
return true;
}
@@ -652,13 +650,12 @@ public class ScramSHA1AuthenticationManager
{
String username = (String) attributes.get("name");
String password = (String) attributes.get("password");
- Principal p = new UsernamePrincipal(username);
if(createUser(username, password,null))
{
@SuppressWarnings("unchecked")
- C principalAdapter = (C) _users.get(username);
- return principalAdapter;
+ C user = (C) _users.get(username);
+ return user;
}
else
{
@@ -669,25 +666,4 @@ public class ScramSHA1AuthenticationManager
return super.addChild(childClass, attributes, otherParents);
}
- public <C extends ConfiguredObject> Collection<C> getChildren(Class<C> clazz)
- {
- if(clazz == User.class)
- {
- return new ArrayList(_users.values());
- }
- else
- {
- return super.getChildren(clazz);
- }
- }
-
- public void instantiateUser(User<?> user)
- {
- if(!(user instanceof ScramAuthUser))
- {
- throw new IllegalArgumentException("Only users of type " + ScramAuthUser.class.getSimpleName() + " can be add to a " + getClass().getSimpleName());
- }
- _users.put(user.getName(), (ScramAuthUser) user);
-
- }
}
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 9ae03433cc..340b3ff08c 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
@@ -198,13 +198,6 @@ public abstract class AbstractVirtualHost<X extends AbstractVirtualHost<X>> exte
return attributes;
}
- private static Map<Class<? extends ConfiguredObject>, ConfiguredObject<?>> parentsMap(Broker<?> broker)
- {
- final Map<Class<? extends ConfiguredObject>, ConfiguredObject<?>> parentsMap = new HashMap<Class<? extends ConfiguredObject>, ConfiguredObject<?>>();
- parentsMap.put(Broker.class, broker);
- return parentsMap;
- }
-
public void validate()
{
super.validate();
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java
index e5beb21810..b1c60351ee 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreatorTest.java
@@ -69,7 +69,7 @@ public class BrokerConfigurationStoreCreatorTest extends QpidTestCase
final BrokerOptions brokerOptions = mock(BrokerOptions.class);
when(brokerOptions.getConfigurationStoreLocation()).thenReturn(_userStoreLocation.getAbsolutePath());
_systemContext = new SystemContext(new TaskExecutor(),
- new ConfiguredObjectFactory(),
+ new ConfiguredObjectFactory(Model.getInstance()),
mock(EventLogger.class),
mock(LogRecorder.class),
brokerOptions);
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java
index 23f71e4ac3..edd6b647d6 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java
@@ -70,7 +70,7 @@ public class BrokerRecovererTest extends TestCase
{
super.setUp();
- _configuredObjectFactory = new ConfiguredObjectFactory();
+ _configuredObjectFactory = new ConfiguredObjectFactory(Model.getInstance());
_systemContext = new SystemContext(mock(TaskExecutor.class),
_configuredObjectFactory, mock(EventLogger.class), mock(LogRecorder.class), mock(BrokerOptions.class));
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileKeyStoreCreationTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileKeyStoreCreationTest.java
index 1470e68a90..d9c0220e5f 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileKeyStoreCreationTest.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileKeyStoreCreationTest.java
@@ -37,6 +37,7 @@ import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.ConfiguredObjectFactory;
import org.apache.qpid.server.model.KeyStore;
+import org.apache.qpid.server.model.Model;
import org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory;
import org.apache.qpid.server.security.FileKeyStore;
import org.apache.qpid.server.security.SecurityManager;
@@ -50,7 +51,7 @@ public class FileKeyStoreCreationTest extends TestCase
public void setUp() throws Exception
{
super.setUp();
- _factory = new ConfiguredObjectFactory();
+ _factory = new ConfiguredObjectFactory(Model.getInstance());
}
public void testCreateWithAllAttributesProvided()
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
index ea3937ea15..9f15953b3b 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
@@ -47,6 +47,7 @@ import org.apache.qpid.server.logging.EventLogger;
import org.apache.qpid.server.logging.LogRecorder;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObjectFactory;
+import org.apache.qpid.server.model.Model;
import org.apache.qpid.server.model.PreferencesProvider;
import org.apache.qpid.server.model.SystemContext;
import org.apache.qpid.server.model.adapter.FileSystemPreferencesProvider;
@@ -99,7 +100,7 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest
final BrokerOptions brokerOptions = mock(BrokerOptions.class);
when(brokerOptions.getConfigurationStoreLocation()).thenReturn(absolutePath);
SystemContext context = new SystemContext(new TaskExecutor(),
- new ConfiguredObjectFactory(),
+ new ConfiguredObjectFactory(Model.getInstance()),
mock(EventLogger.class),
mock(LogRecorder.class),
brokerOptions);
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java
index 1de857d224..43335cdea3 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java
@@ -45,6 +45,7 @@ import org.apache.qpid.server.logging.EventLogger;
import org.apache.qpid.server.logging.LogRecorder;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObjectFactory;
+import org.apache.qpid.server.model.Model;
import org.apache.qpid.server.model.Port;
import org.apache.qpid.server.model.Protocol;
import org.apache.qpid.server.model.State;
@@ -74,7 +75,7 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase
_store = mock(DurableConfigurationStore.class);
- _systemContext = new SystemContext(new TaskExecutor(), new ConfiguredObjectFactory(), mock(
+ _systemContext = new SystemContext(new TaskExecutor(), new ConfiguredObjectFactory(Model.getInstance()), mock(
EventLogger.class), mock(LogRecorder.class), new BrokerOptions());
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java
index 86098729d5..bdc43e6a99 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java
@@ -41,6 +41,7 @@ import org.apache.qpid.server.logging.EventLogger;
import org.apache.qpid.server.logging.LogRecorder;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObjectFactory;
+import org.apache.qpid.server.model.Model;
import org.apache.qpid.server.model.SystemContext;
public class MemoryConfigurationEntryStoreTest extends ConfigurationEntryStoreTestCase
@@ -51,7 +52,7 @@ public class MemoryConfigurationEntryStoreTest extends ConfigurationEntryStoreTe
public void setUp() throws Exception
{
super.setUp();
- _systemContext = new SystemContext(new TaskExecutor(), new ConfiguredObjectFactory(),
+ _systemContext = new SystemContext(new TaskExecutor(), new ConfiguredObjectFactory(Model.getInstance()),
mock(EventLogger.class), mock(LogRecorder.class),
new BrokerOptions());
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/consumer/MockConsumer.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/consumer/MockConsumer.java
index 0f5931b902..7fd4f05a14 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/consumer/MockConsumer.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/consumer/MockConsumer.java
@@ -21,6 +21,15 @@
package org.apache.qpid.server.consumer;
+import java.net.SocketAddress;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.filter.FilterManager;
import org.apache.qpid.server.filter.Filterable;
@@ -32,6 +41,7 @@ import org.apache.qpid.server.message.ServerMessage;
import org.apache.qpid.server.model.Consumer;
import org.apache.qpid.server.model.Port;
import org.apache.qpid.server.model.Transport;
+import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.protocol.AMQConnectionModel;
import org.apache.qpid.server.protocol.AMQSessionModel;
import org.apache.qpid.server.protocol.ConsumerListener;
@@ -41,15 +51,6 @@ import org.apache.qpid.server.stats.StatisticsCounter;
import org.apache.qpid.server.util.Action;
import org.apache.qpid.server.util.StateChangeListener;
-import java.net.SocketAddress;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.UUID;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
public class MockConsumer implements ConsumerTarget
{
@@ -567,6 +568,12 @@ public class MockConsumer implements ConsumerTarget
}
@Override
+ public VirtualHost<?, ?, ?> getVirtualHost()
+ {
+ return null;
+ }
+
+ @Override
public void addDeleteTask(final Action task)
{
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java
index 1bf7f4f0a3..7d83d81d4e 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java
@@ -71,6 +71,7 @@ public class PortFactoryTest extends QpidTestCase
{
when(_authProvider.getName()).thenReturn(_authProviderName);
when(_broker.getChildren(eq(AuthenticationProvider.class))).thenReturn(Collections.singleton(_authProvider));
+ when(_broker.getCategoryClass()).thenReturn(Broker.class);
setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, null);
setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES, null);
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java
index 1ea74acd00..43a9307654 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/auth/manager/SimpleLDAPAuthenticationManagerFactoryTest.java
@@ -29,14 +29,13 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import junit.framework.TestCase;
+
import org.apache.qpid.server.model.AuthenticationProvider;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.SystemContext;
import org.apache.qpid.server.model.TrustStore;
-
-import junit.framework.TestCase;
-
public class SimpleLDAPAuthenticationManagerFactoryTest extends TestCase
{
private SimpleLDAPAuthenticationManagerFactory _factory = new SimpleLDAPAuthenticationManagerFactory();
@@ -52,7 +51,7 @@ public class SimpleLDAPAuthenticationManagerFactoryTest extends TestCase
when(_trustStore.getName()).thenReturn("mytruststore");
when(_trustStore.getId()).thenReturn(UUID.randomUUID());
-
+ when(_broker.getCategoryClass()).thenReturn(Broker.class);
when(_broker.getParent(eq(SystemContext.class))).thenReturn(_systemContext);
when(_systemContext.getChildren(eq(Broker.class))).thenReturn(Collections.singleton(_broker));
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java
index 697aee12eb..0182237a99 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/store/AbstractDurableConfigurationStoreTestCase.java
@@ -33,6 +33,11 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
+import org.mockito.ArgumentCaptor;
+import org.mockito.ArgumentMatcher;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
import org.apache.qpid.common.AMQPFilterTypes;
import org.apache.qpid.server.binding.BindingImpl;
import org.apache.qpid.server.exchange.ExchangeImpl;
@@ -51,10 +56,6 @@ import org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler;
import org.apache.qpid.server.virtualhost.VirtualHostImpl;
import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.util.FileUtils;
-import org.mockito.ArgumentCaptor;
-import org.mockito.ArgumentMatcher;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
public abstract class AbstractDurableConfigurationStoreTestCase extends QpidTestCase
{
@@ -415,6 +416,7 @@ public abstract class AbstractDurableConfigurationStoreTestCase extends QpidTest
when(queue.isExclusive()).thenReturn(exclusive);
when(queue.getId()).thenReturn(_queueId);
when(queue.getAlternateExchange()).thenReturn(alternateExchange);
+ when(queue.getCategoryClass()).thenReturn((Class)Queue.class);
final VirtualHostImpl vh = mock(VirtualHostImpl.class);
when(vh.getSecurityManager()).thenReturn(mock(SecurityManager.class));
when(queue.getVirtualHost()).thenReturn(vh);
@@ -466,6 +468,8 @@ public abstract class AbstractDurableConfigurationStoreTestCase extends QpidTest
when(exchange.getTypeName()).thenReturn(getName() + "Type");
when(exchange.isAutoDelete()).thenReturn(true);
when(exchange.getId()).thenReturn(_exchangeId);
+ when(exchange.getCategoryClass()).thenReturn(Exchange.class);
+
ConfiguredObjectRecord exchangeRecord = mock(ConfiguredObjectRecord.class);
when(exchangeRecord.getId()).thenReturn(_exchangeId);
when(exchangeRecord.getType()).thenReturn(Exchange.class.getSimpleName());
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
index e30c214150..1113f8699b 100644
--- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
+++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
@@ -36,6 +36,7 @@ import org.apache.qpid.server.exchange.ExchangeImpl;
import org.apache.qpid.server.logging.EventLogger;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObjectFactory;
+import org.apache.qpid.server.model.Model;
import org.apache.qpid.server.model.Queue;
import org.apache.qpid.server.model.State;
import org.apache.qpid.server.model.UUIDGenerator;
@@ -100,7 +101,7 @@ public class BrokerTestHelper
SecurityManager securityManager = new SecurityManager(broker, false);
when(broker.getSecurityManager()).thenReturn(securityManager);
- ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactory();
+ ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactory(Model.getInstance());
ConfiguredObjectTypeFactory factory = objectFactory.getConfiguredObjectTypeFactory(org.apache.qpid.server.model.VirtualHost.class,
attributes);
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 23d9aac93a..b4d3148dfa 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
@@ -32,9 +32,9 @@ import org.apache.qpid.server.exchange.ExchangeImpl;
import org.apache.qpid.server.logging.EventLogger;
import org.apache.qpid.server.message.MessageDestination;
import org.apache.qpid.server.message.MessageSource;
-import org.apache.qpid.server.model.AbstractConfiguredObject;
import org.apache.qpid.server.model.ConfigurationChangeListener;
import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.ConfiguredObjectAttribute;
import org.apache.qpid.server.model.Connection;
import org.apache.qpid.server.model.IllegalStateTransitionException;
import org.apache.qpid.server.model.LifetimePolicy;
@@ -525,7 +525,7 @@ public class MockVirtualHost implements VirtualHostImpl<MockVirtualHost, AMQQueu
}
@Override
- public <T> T getAttribute(final AbstractConfiguredObject.Attribute<? super MockVirtualHost, T> attr)
+ public <T> T getAttribute(final ConfiguredObjectAttribute<? super MockVirtualHost, T> attr)
{
return null;
}
diff --git a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProvider.java b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProvider.java
index 382f8d8efd..55de9fc902 100644
--- a/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProvider.java
+++ b/qpid/java/broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/plugins/ACLFileAccessControlProvider.java
@@ -53,7 +53,7 @@ public class ACLFileAccessControlProvider
public ACLFileAccessControlProvider(Broker broker,
Map<String, Object> attributes)
{
- super(Collections.<Class<? extends ConfiguredObject>,ConfiguredObject<?>>singletonMap(Broker.class, broker),
+ super(parentsMap(broker),
attributes, broker.getTaskExecutor());
diff --git a/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java b/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java
index 4c272e929f..031febbb1a 100644
--- a/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java
+++ b/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java
@@ -438,7 +438,7 @@ public class Connection_1_0 implements ConnectionEventListener, AMQConnectionMod
return _subject;
}
- VirtualHostImpl getVirtualHost()
+ public VirtualHostImpl getVirtualHost()
{
return _vhost;
}
diff --git a/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java b/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java
index 2cb611d382..fbdb34fb96 100644
--- a/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java
+++ b/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/HttpManagementFactoryTest.java
@@ -19,6 +19,7 @@
package org.apache.qpid.server.management.plugin;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.Map;
@@ -44,6 +45,7 @@ public class HttpManagementFactoryTest extends QpidTestCase
_attributes.put(ConfiguredObject.TYPE, HttpManagement.PLUGIN_TYPE);
_attributes.put(HttpManagement.TIME_OUT, SESSION_TIMEOUT);
_attributes.put(ConfiguredObject.ID, _id);
+ when(_broker.getCategoryClass()).thenReturn(Broker.class);
HttpManagement management = _pluginFactory.createInstance(_attributes, _broker);
management.open();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
index 59b4d496fa..645fc57677 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
@@ -39,6 +39,7 @@ import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.ConfiguredObjectFactory;
import org.apache.qpid.server.model.GroupProvider;
+import org.apache.qpid.server.model.Model;
import org.apache.qpid.server.model.Plugin;
import org.apache.qpid.server.model.PreferencesProvider;
import org.apache.qpid.server.model.SystemContext;
@@ -74,7 +75,8 @@ public class TestBrokerConfiguration
public TestBrokerConfiguration(String storeType, String intialStoreLocation)
{
- _store = new MemoryConfigurationEntryStore(new SystemContext(new TaskExecutor(), new ConfiguredObjectFactory(),
+ _store = new MemoryConfigurationEntryStore(new SystemContext(new TaskExecutor(), new ConfiguredObjectFactory(
+ Model.getInstance()),
mock(EventLogger.class), mock(LogRecorder.class),
mock(BrokerOptions.class)),
intialStoreLocation,