qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgodf...@apache.org
Subject svn commit: r1588715 [1/2] - in /qpid/trunk/qpid/java: bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/ broker-core/src/main/java/org/apache/qpid/server/binding/ broker-core/src/main/java/org/apache/qpid/server/configuration/updater/ bro...
Date Sun, 20 Apr 2014 01:32:50 GMT
Author: rgodfrey
Date: Sun Apr 20 01:32:50 2014
New Revision: 1588715

URL: http://svn.apache.org/r1588715
Log:
QPID-5712 : [Java Broker] Remove VirtualHostRegistry and remove redundant maps from BrokerAdapter

Removed:
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/ChangeAttributesTask.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/ChangeStateTask.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/CreateChildTask.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostRegistry.java
Modified:
    qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/SystemContextImpl.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPort.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPortImpl.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ScramSHA1AuthenticationManager.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/VirtualHostImpl.java
    qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostCreationTest.java
    qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/updater/TaskExecutorTest.java
    qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/VirtualHostTest.java
    qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/adapter/FileSystemPreferencesProviderTest.java
    qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
    qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java
    qpid/trunk/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerConnectionDelegate.java
    qpid/trunk/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/ConnectionOpenMethodHandler.java
    qpid/trunk/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/state/AMQStateManager.java
    qpid/trunk/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/VirtualHostMessageStoreTest.java

Modified: qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java (original)
+++ qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java Sun Apr 20 01:32:50 2014
@@ -59,6 +59,7 @@ public class VirtualHostTest extends Qpi
     private File _bdbStorePath;
     private VirtualHost<?,?,?> _host;
     private ConfigurationEntryStore _store;
+    private TaskExecutor _taskExecutor;
 
     @Override
     protected void setUp() throws Exception
@@ -67,9 +68,9 @@ public class VirtualHostTest extends Qpi
 
         _store = mock(ConfigurationEntryStore.class);
         _broker = BrokerTestHelper.createBrokerMock();
-        TaskExecutor taslExecutor = mock(TaskExecutor.class);
-        when(taslExecutor.isTaskExecutorThread()).thenReturn(true);
-        when(_broker.getTaskExecutor()).thenReturn(taslExecutor);
+        _taskExecutor = new TaskExecutor();
+        _taskExecutor.start();
+        when(_broker.getTaskExecutor()).thenReturn(_taskExecutor);
 
         _statisticsGatherer = mock(StatisticsGatherer.class);
 
@@ -89,6 +90,8 @@ public class VirtualHostTest extends Qpi
         }
         finally
         {
+            _taskExecutor.stopImmediately();
+
             if (_bdbStorePath != null)
             {
                 FileUtils.delete(_bdbStorePath, true);

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/binding/BindingImpl.java Sun Apr 20 01:32:50 2014
@@ -29,6 +29,7 @@ import java.util.concurrent.CopyOnWriteA
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.apache.qpid.server.configuration.updater.TaskExecutor;
 import org.apache.qpid.server.exchange.AbstractExchange;
 import org.apache.qpid.server.exchange.ExchangeImpl;
 import org.apache.qpid.server.logging.EventLogger;
@@ -255,26 +256,22 @@ public class BindingImpl
 
     public void setArguments(final Map<String, Object> arguments)
     {
-        if(getTaskExecutor().isTaskExecutorThread())
-        {
-            _arguments = arguments;
-            super.setAttribute(ARGUMENTS, getActualAttributes().get(ARGUMENTS), arguments);
-            if (isDurable())
-            {
-                VirtualHostImpl<?, ?, ?> vhost = (VirtualHostImpl<?, ?, ?>) _exchange.getParent(VirtualHost.class);
-                vhost.getDurableConfigurationStore().update(true, asObjectRecord());
-            }
-        }
-        else
-        {
-            getTaskExecutor().submitAndWait(new Runnable()
-            {
-                @Override
-                public void run()
+        runTask(new TaskExecutor.VoidTask()
                 {
-                    setArguments(arguments);
+                    @Override
+                    public void execute()
+                    {
+                        _arguments = arguments;
+                        BindingImpl.super.setAttribute(ARGUMENTS, getActualAttributes().get(ARGUMENTS), arguments);
+                        if (isDurable())
+                        {
+                            VirtualHostImpl<?, ?, ?> vhost =
+                                    (VirtualHostImpl<?, ?, ?>) _exchange.getParent(VirtualHost.class);
+                            vhost.getDurableConfigurationStore().update(true, asObjectRecord());
+                        }
+                    }
                 }
-            });
-        }
+               );
+
     }
 }

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/SetAttributeTask.java Sun Apr 20 01:32:50 2014
@@ -60,7 +60,7 @@ public final class SetAttributeTask impl
     }
 
     @Override
-    public Object call()
+    public Object execute()
     {
         return _object.setAttribute(_attributeName, _expectedValue, _desiredValue);
     }

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/updater/TaskExecutor.java Sun Apr 20 01:32:50 2014
@@ -49,11 +49,27 @@ public class TaskExecutor
     private final AtomicReference<State> _state;
     private volatile ExecutorService _executor;
 
-    public static interface Task<X> extends Callable<X>
+    public static interface Task<X>
     {
-        X call();
+        X execute();
     }
 
+    public static interface VoidTask
+    {
+        void execute();
+    }
+
+    public static interface TaskWithException<X,E extends Exception>
+    {
+        X execute() throws E;
+    }
+
+    public static interface VoidTaskWithException<E extends Exception>
+    {
+        void execute() throws E;
+    }
+
+
     public TaskExecutor()
     {
         _state = new AtomicReference<State>(State.INITIALISING);
@@ -142,20 +158,109 @@ public class TaskExecutor
         return future;
     }
 
-    public void submitAndWait(final Runnable task) throws CancellationException
+    public void run(final VoidTask task) throws CancellationException
     {
-        submitAndWait(new Task<Void>()
+        run(new Task<Void>()
         {
             @Override
-            public Void call()
+            public Void execute()
             {
-                task.run();
+                task.execute();
                 return null;
             }
         });
     }
 
-    public <T> T submitAndWait(Task<T> task) throws CancellationException
+    private static class ExceptionTaskWrapper<T, E extends Exception> implements Task<T>
+    {
+        private final TaskWithException<T,E> _underlying;
+        private E _exception;
+
+        private ExceptionTaskWrapper(final TaskWithException<T, E> underlying)
+        {
+            _underlying = underlying;
+        }
+
+
+        @Override
+        public T execute()
+        {
+            try
+            {
+                return _underlying.execute();
+            }
+            catch (Exception e)
+            {
+                _exception = (E) e;
+                return null;
+            }
+        }
+
+        E getException()
+        {
+            return _exception;
+        }
+    }
+
+
+    private static class ExceptionVoidTaskWrapper<E extends Exception> implements Task<Void>
+    {
+        private final VoidTaskWithException<E> _underlying;
+        private E _exception;
+
+        private ExceptionVoidTaskWrapper(final VoidTaskWithException<E> underlying)
+        {
+            _underlying = underlying;
+        }
+
+
+        @Override
+        public Void execute()
+        {
+            try
+            {
+                _underlying.execute();
+
+            }
+            catch (Exception e)
+            {
+                _exception = (E) e;
+            }
+            return null;
+        }
+
+        E getException()
+        {
+            return _exception;
+        }
+    }
+
+    public <T, E extends Exception> T run(TaskWithException<T,E> task) throws CancellationException, E
+    {
+        ExceptionTaskWrapper<T,E> wrapper = new ExceptionTaskWrapper<T, E>(task);
+        T result = run(wrapper);
+        if(wrapper.getException() != null)
+        {
+            throw wrapper.getException();
+        }
+        else
+        {
+            return result;
+        }
+    }
+
+
+    public <E extends Exception> void run(VoidTaskWithException<E> task) throws CancellationException, E
+    {
+        ExceptionVoidTaskWrapper<E> wrapper = new ExceptionVoidTaskWrapper<E>(task);
+        run(wrapper);
+        if(wrapper.getException() != null)
+        {
+            throw wrapper.getException();
+        }
+    }
+
+    public <T> T run(Task<T> task) throws CancellationException
     {
         try
         {
@@ -207,7 +312,7 @@ public class TaskExecutor
         {
             LOGGER.debug("Performing task " + userTask);
         }
-        T result = userTask.call();
+        T result = userTask.execute();
         if (LOGGER.isDebugEnabled())
         {
             LOGGER.debug("Task " + userTask + " is performed successfully with result:" + result);
@@ -215,7 +320,7 @@ public class TaskExecutor
         return result;
     }
 
-    private class CallableWrapper<T> implements Task<T>
+    private class CallableWrapper<T> implements Callable<T>
     {
         private Task<T> _userTask;
         private Subject _contextSubject;

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java Sun Apr 20 01:32:50 2014
@@ -48,10 +48,6 @@ import java.util.concurrent.atomic.Atomi
 import javax.security.auth.Subject;
 
 import org.apache.qpid.server.configuration.IllegalConfigurationException;
-import org.apache.qpid.server.configuration.updater.ChangeAttributesTask;
-import org.apache.qpid.server.configuration.updater.ChangeStateTask;
-import org.apache.qpid.server.configuration.updater.CreateChildTask;
-import org.apache.qpid.server.configuration.updater.SetAttributeTask;
 import org.apache.qpid.server.configuration.updater.TaskExecutor;
 import org.apache.qpid.server.security.SecurityManager;
 import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
@@ -544,23 +540,25 @@ public abstract class AbstractConfigured
     public final State setDesiredState(final State currentState, final State desiredState)
             throws IllegalStateTransitionException, AccessControlException
     {
-        if (_taskExecutor.isTaskExecutorThread())
-        {
-            authoriseSetDesiredState(currentState, desiredState);
-            if (setState(currentState, desiredState))
-            {
-                notifyStateChanged(currentState, desiredState);
-                return desiredState;
-            }
-            else
-            {
-                return getState();
-            }
-        }
-        else
-        {
-            return _taskExecutor.submitAndWait(new ChangeStateTask(this, currentState, desiredState));
-        }
+
+
+        return runTask(new TaskExecutor.Task<State>()
+                        {
+                            @Override
+                            public State execute()
+                            {
+                                authoriseSetDesiredState(currentState, desiredState);
+                                if (setState(currentState, desiredState))
+                                {
+                                    notifyStateChanged(currentState, desiredState);
+                                    return desiredState;
+                                }
+                                else
+                                {
+                                    return getState();
+                                }
+                            }
+                        });
     }
 
     /**
@@ -727,25 +725,25 @@ public abstract class AbstractConfigured
     public Object setAttribute(final String name, final Object expected, final Object desired)
             throws IllegalStateException, AccessControlException, IllegalArgumentException
     {
-        if (_taskExecutor.isTaskExecutorThread())
+        return _taskExecutor.run(new TaskExecutor.Task<Object>()
         {
-            authoriseSetAttributes(createProxyForValidation(Collections.singletonMap(name, desired)),
-                                   Collections.singleton(name));
-
-            if (changeAttribute(name, expected, desired))
-            {
-                attributeSet(name, expected, desired);
-                return desired;
-            }
-            else
+            @Override
+            public Object execute()
             {
-                return getAttribute(name);
+                authoriseSetAttributes(createProxyForValidation(Collections.singletonMap(name, desired)),
+                                       Collections.singleton(name));
+
+                if (changeAttribute(name, expected, desired))
+                {
+                    attributeSet(name, expected, desired);
+                    return desired;
+                }
+                else
+                {
+                    return getAttribute(name);
+                }
             }
-        }
-        else
-        {
-            return _taskExecutor.submitAndWait(new SetAttributeTask(this, name, expected, desired));
-        }
+        });
     }
 
     protected boolean changeAttribute(final String name, final Object expected, final Object desired)
@@ -864,22 +862,23 @@ public abstract class AbstractConfigured
 
     @SuppressWarnings("unchecked")
     @Override
-    public <C extends ConfiguredObject> C createChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+    public <C extends ConfiguredObject> C createChild(final Class<C> childClass, final Map<String, Object> attributes,
+                                                      final ConfiguredObject... otherParents)
     {
-        if (_taskExecutor.isTaskExecutorThread())
-        {
-            authoriseCreateChild(childClass, attributes, otherParents);
-            C child = addChild(childClass, attributes, otherParents);
-            if (child != null)
+        return _taskExecutor.run(new TaskExecutor.Task<C>() {
+
+            @Override
+            public C execute()
             {
-                childAdded(child);
+                authoriseCreateChild(childClass, attributes, otherParents);
+                C child = addChild(childClass, attributes, otherParents);
+                if (child != null)
+                {
+                    childAdded(child);
+                }
+                return child;
             }
-            return child;
-        }
-        else
-        {
-            return (C)_taskExecutor.submitAndWait(new CreateChildTask(this, childClass, attributes, otherParents));
-        }
+        });
     }
 
     protected <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
@@ -973,18 +972,39 @@ public abstract class AbstractConfigured
         return _taskExecutor;
     }
 
+    protected final <C> C runTask(TaskExecutor.Task<C> task)
+    {
+        return _taskExecutor.run(task);
+    }
+
+    protected void runTask(TaskExecutor.VoidTask task)
+    {
+        _taskExecutor.run(task);
+    }
+
+    protected final <T, E extends Exception> T runTask(TaskExecutor.TaskWithException<T,E> task) throws E
+    {
+        return _taskExecutor.run(task);
+    }
+
+    protected final <E extends Exception> void runTask(TaskExecutor.VoidTaskWithException<E> task) throws E
+    {
+        _taskExecutor.run(task);
+    }
+
+
     @Override
     public void setAttributes(final Map<String, Object> attributes) throws IllegalStateException, AccessControlException, IllegalArgumentException
     {
-        if (getTaskExecutor().isTaskExecutorThread())
+        runTask(new TaskExecutor.VoidTask()
         {
-            authoriseSetAttributes(createProxyForValidation(attributes), attributes.keySet());
-            changeAttributes(attributes);
-        }
-        else
-        {
-            getTaskExecutor().submitAndWait(new ChangeAttributesTask(this, attributes));
-        }
+            @Override
+            public void execute()
+            {
+                authoriseSetAttributes(createProxyForValidation(attributes), attributes.keySet());
+                changeAttributes(attributes);
+            }
+        });
     }
 
     protected void authoriseSetAttributes(final ConfiguredObject<?> proxyForValidation,

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java Sun Apr 20 01:32:50 2014
@@ -30,7 +30,6 @@ import org.apache.qpid.server.logging.Lo
 import org.apache.qpid.server.security.SecurityManager;
 import org.apache.qpid.server.security.SubjectCreator;
 import org.apache.qpid.server.stats.StatisticsGatherer;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
 
 @ManagedObject( defaultType = "broker" )
 public interface Broker<X extends Broker<X>> extends ConfiguredObject<X>, EventLoggerProvider, StatisticsGatherer
@@ -178,11 +177,6 @@ public interface Broker<X extends Broker
 
     Collection<TrustStore<?>> getTrustStores();
 
-    /*
-     * TODO: Remove this method. Eventually the broker will become a registry.
-     */
-    VirtualHostRegistry getVirtualHostRegistry();
-
     TaskExecutor getTaskExecutor();
 
     boolean isManagementMode();

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/SystemContextImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/SystemContextImpl.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/SystemContextImpl.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/SystemContextImpl.java Sun Apr 20 01:32:50 2014
@@ -84,121 +84,138 @@ public class SystemContextImpl extends A
     }
 
     @Override
-    public void resolveObjects(ConfiguredObjectRecord... records)
+    public void resolveObjects(final ConfiguredObjectRecord... records)
     {
-
-        ConfiguredObjectFactory factory = getObjectFactory();
-
-        Map<UUID, ConfiguredObject<?>> resolvedObjects = new HashMap<UUID, ConfiguredObject<?>>();
-        resolvedObjects.put(getId(), this);
-
-        Collection<ConfiguredObjectRecord> recordsWithUnresolvedParents = new ArrayList<ConfiguredObjectRecord>(Arrays.asList(records));
-        Collection<UnresolvedConfiguredObject<? extends ConfiguredObject>> recordsWithUnresolvedDependencies =
-                new ArrayList<UnresolvedConfiguredObject<? extends ConfiguredObject>>();
-
-        boolean updatesMade;
-
-        do
+        runTask(new TaskExecutor.VoidTask()
         {
-            updatesMade = false;
-            Iterator<ConfiguredObjectRecord> iter = recordsWithUnresolvedParents.iterator();
-            while (iter.hasNext())
+            @Override
+            public void execute()
             {
-                ConfiguredObjectRecord record = iter.next();
-                Collection<ConfiguredObject<?>> parents = new ArrayList<ConfiguredObject<?>>();
-                boolean foundParents = true;
-                for (ConfiguredObjectRecord parent : record.getParents().values())
-                {
-                    if (!resolvedObjects.containsKey(parent.getId()))
-                    {
-                        foundParents = false;
-                        break;
-                    }
-                    else
-                    {
-                        parents.add(resolvedObjects.get(parent.getId()));
-                    }
-                }
-                if (foundParents)
-                {
-                    iter.remove();
-                    UnresolvedConfiguredObject<? extends ConfiguredObject> recovered =
-                            factory.recover(record, parents.toArray(new ConfiguredObject<?>[parents.size()]));
-                    Collection<ConfiguredObjectDependency<?>> dependencies =
-                            recovered.getUnresolvedDependencies();
-                    if (dependencies.isEmpty())
-                    {
-                        updatesMade = true;
-                        ConfiguredObject<?> resolved = recovered.resolve();
-                        resolvedObjects.put(resolved.getId(), resolved);
-                    }
-                    else
-                    {
-                        recordsWithUnresolvedDependencies.add(recovered);
-                    }
-                }
 
-            }
 
-            Iterator<UnresolvedConfiguredObject<? extends ConfiguredObject>> unresolvedIter =
-                    recordsWithUnresolvedDependencies.iterator();
+                ConfiguredObjectFactory factory = getObjectFactory();
 
-            while(unresolvedIter.hasNext())
-            {
-                UnresolvedConfiguredObject<? extends ConfiguredObject> unresolvedObject = unresolvedIter.next();
-                Collection<ConfiguredObjectDependency<?>> dependencies =
-                        new ArrayList<ConfiguredObjectDependency<?>>(unresolvedObject.getUnresolvedDependencies());
+                Map<UUID, ConfiguredObject<?>> resolvedObjects = new HashMap<UUID, ConfiguredObject<?>>();
+                resolvedObjects.put(getId(), SystemContextImpl.this);
+
+                Collection<ConfiguredObjectRecord> recordsWithUnresolvedParents =
+                        new ArrayList<ConfiguredObjectRecord>(Arrays.asList(records));
+                Collection<UnresolvedConfiguredObject<? extends ConfiguredObject>> recordsWithUnresolvedDependencies =
+                        new ArrayList<UnresolvedConfiguredObject<? extends ConfiguredObject>>();
+
+                boolean updatesMade;
 
-                for(ConfiguredObjectDependency dependency : dependencies)
+                do
                 {
-                    if(dependency instanceof ConfiguredObjectIdDependency)
-                    {
-                        UUID id = ((ConfiguredObjectIdDependency)dependency).getId();
-                        if(resolvedObjects.containsKey(id))
+                    updatesMade = false;
+                    Iterator<ConfiguredObjectRecord> iter = recordsWithUnresolvedParents.iterator();
+                    while (iter.hasNext())
+                    {
+                        ConfiguredObjectRecord record = iter.next();
+                        Collection<ConfiguredObject<?>> parents = new ArrayList<ConfiguredObject<?>>();
+                        boolean foundParents = true;
+                        for (ConfiguredObjectRecord parent : record.getParents().values())
                         {
-                            dependency.resolve(resolvedObjects.get(id));
+                            if (!resolvedObjects.containsKey(parent.getId()))
+                            {
+                                foundParents = false;
+                                break;
+                            }
+                            else
+                            {
+                                parents.add(resolvedObjects.get(parent.getId()));
+                            }
                         }
+                        if (foundParents)
+                        {
+                            iter.remove();
+                            UnresolvedConfiguredObject<? extends ConfiguredObject> recovered =
+                                    factory.recover(record, parents.toArray(new ConfiguredObject<?>[parents.size()]));
+                            Collection<ConfiguredObjectDependency<?>> dependencies =
+                                    recovered.getUnresolvedDependencies();
+                            if (dependencies.isEmpty())
+                            {
+                                updatesMade = true;
+                                ConfiguredObject<?> resolved = recovered.resolve();
+                                resolvedObjects.put(resolved.getId(), resolved);
+                            }
+                            else
+                            {
+                                recordsWithUnresolvedDependencies.add(recovered);
+                            }
+                        }
+
                     }
-                    else if(dependency instanceof ConfiguredObjectNameDependency)
+
+                    Iterator<UnresolvedConfiguredObject<? extends ConfiguredObject>> unresolvedIter =
+                            recordsWithUnresolvedDependencies.iterator();
+
+                    while (unresolvedIter.hasNext())
                     {
-                        ConfiguredObject<?> dependentObject = null;
-                        for(ConfiguredObject<?> parent : unresolvedObject.getParents())
+                        UnresolvedConfiguredObject<? extends ConfiguredObject> unresolvedObject = unresolvedIter.next();
+                        Collection<ConfiguredObjectDependency<?>> dependencies =
+                                new ArrayList<ConfiguredObjectDependency<?>>(unresolvedObject.getUnresolvedDependencies());
+
+                        for (ConfiguredObjectDependency dependency : dependencies)
                         {
-                            dependentObject = parent.findConfiguredObject(dependency.getCategoryClass(), ((ConfiguredObjectNameDependency)dependency).getName());
-                            if(dependentObject != null)
+                            if (dependency instanceof ConfiguredObjectIdDependency)
                             {
-                                break;
+                                UUID id = ((ConfiguredObjectIdDependency) dependency).getId();
+                                if (resolvedObjects.containsKey(id))
+                                {
+                                    dependency.resolve(resolvedObjects.get(id));
+                                }
+                            }
+                            else if (dependency instanceof ConfiguredObjectNameDependency)
+                            {
+                                ConfiguredObject<?> dependentObject = null;
+                                for (ConfiguredObject<?> parent : unresolvedObject.getParents())
+                                {
+                                    dependentObject = parent.findConfiguredObject(dependency.getCategoryClass(),
+                                                                                  ((ConfiguredObjectNameDependency) dependency)
+                                                                                          .getName()
+                                                                                 );
+                                    if (dependentObject != null)
+                                    {
+                                        break;
+                                    }
+                                }
+                                if (dependentObject != null)
+                                {
+                                    dependency.resolve(dependentObject);
+                                }
+                            }
+                            else
+                            {
+                                throw new ServerScopedRuntimeException("Unknown dependency type "
+                                                                       + dependency.getClass()
+                                        .getSimpleName());
                             }
                         }
-                        if(dependentObject != null)
+                        if (unresolvedObject.getUnresolvedDependencies().isEmpty())
                         {
-                            dependency.resolve(dependentObject);
+                            updatesMade = true;
+                            unresolvedIter.remove();
+                            ConfiguredObject<?> resolved = unresolvedObject.resolve();
+                            resolvedObjects.put(resolved.getId(), resolved);
                         }
                     }
-                    else
-                    {
-                        throw new ServerScopedRuntimeException("Unknown dependency type " + dependency.getClass().getSimpleName());
-                    }
+
+                } while (updatesMade && !(recordsWithUnresolvedDependencies.isEmpty()
+                                          && recordsWithUnresolvedParents.isEmpty()));
+
+                if (!recordsWithUnresolvedDependencies.isEmpty())
+                {
+                    throw new IllegalArgumentException("Cannot resolve some objects: "
+                                                       + recordsWithUnresolvedDependencies);
                 }
-                if(unresolvedObject.getUnresolvedDependencies().isEmpty())
+                if (!recordsWithUnresolvedParents.isEmpty())
                 {
-                    updatesMade = true;
-                    unresolvedIter.remove();
-                    ConfiguredObject<?> resolved = unresolvedObject.resolve();
-                    resolvedObjects.put(resolved.getId(), resolved);
+                    throw new IllegalArgumentException("Cannot resolve object because their parents cannot be found"
+                                                       + recordsWithUnresolvedParents);
                 }
             }
-
-        } while(updatesMade && !(recordsWithUnresolvedDependencies.isEmpty() && recordsWithUnresolvedParents.isEmpty()));
-
-        if(!recordsWithUnresolvedDependencies.isEmpty())
-        {
-            throw new IllegalArgumentException("Cannot resolve some objects: " + recordsWithUnresolvedDependencies);
-        }
-        if(!recordsWithUnresolvedParents.isEmpty())
-        {
-            throw new IllegalArgumentException("Cannot resolve object because their parents cannot be found" + recordsWithUnresolvedParents);
-        }
+        });
     }
 
     @Override

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java Sun Apr 20 01:32:50 2014
@@ -24,9 +24,7 @@ import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.security.AccessControlException;
 import java.security.PrivilegedAction;
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
@@ -59,7 +57,6 @@ import org.apache.qpid.server.security.a
 import org.apache.qpid.server.stats.StatisticsCounter;
 import org.apache.qpid.server.stats.StatisticsGatherer;
 import org.apache.qpid.server.virtualhost.VirtualHostImpl;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
 import org.apache.qpid.util.SystemUtils;
 
 public class BrokerAdapter extends AbstractConfiguredObject<BrokerAdapter> implements Broker<BrokerAdapter>, ConfigurationChangeListener, StatisticsGatherer, StatisticsGatherer.Source
@@ -77,18 +74,10 @@ public class BrokerAdapter extends Abstr
 
 
     private EventLogger _eventLogger;
-    private final VirtualHostRegistry _virtualHostRegistry;
+    //private final VirtualHostRegistry _virtualHostRegistry;
     private final LogRecorder _logRecorder;
 
-    private final Map<String, VirtualHost<?,?,?>> _vhostAdapters = new HashMap<String, VirtualHost<?,?,?>>();
-    private final Map<UUID, Port<?>> _portAdapters = new HashMap<UUID, Port<?>>();
     private final Map<Port, Integer> _stillInUsePortNumbers = new HashMap<Port, Integer>();
-    private final Map<UUID, AuthenticationProvider<?>> _authenticationProviders = new HashMap<UUID, AuthenticationProvider<?>>();
-    private final Map<String, GroupProvider<?>> _groupProviders = new HashMap<String, GroupProvider<?>>();
-    private final Map<UUID, ConfiguredObject<?>> _plugins = new HashMap<UUID, ConfiguredObject<?>>();
-    private final Map<String, KeyStore<?>> _keyStores = new HashMap<String, KeyStore<?>>();
-    private final Map<String, TrustStore<?>> _trustStores = new HashMap<String, TrustStore<?>>();
-    private final Map<UUID, AccessControlProvider<?>> _accessControlProviders = new HashMap<UUID, AccessControlProvider<?>>();
 
     private final SecurityManager _securityManager;
 
@@ -122,7 +111,7 @@ public class BrokerAdapter extends Abstr
               parent.getTaskExecutor());
 
         _objectFactory = parent.getObjectFactory();
-        _virtualHostRegistry = new VirtualHostRegistry(parent.getEventLogger());
+        //_virtualHostRegistry = new VirtualHostRegistry(parent.getEventLogger());
 
         _logRecorder = parent.getLogRecorder();
         _eventLogger = parent.getEventLogger();
@@ -220,7 +209,6 @@ public class BrokerAdapter extends Abstr
         {
             _managementModeAuthenticationProvider.open();
         }
-        _virtualHostRegistry.setDefaultVirtualHostName(getDefaultVirtualHost());
 
         for(KeyStore<?> keyStore : getChildren(KeyStore.class))
         {
@@ -375,26 +363,20 @@ public class BrokerAdapter extends Abstr
 
     public Collection<VirtualHost<?,?,?>> getVirtualHosts()
     {
-        synchronized(_vhostAdapters)
-        {
-            return new ArrayList<VirtualHost<?,?,?>>(_vhostAdapters.values());
-        }
+        Collection children = getChildren(VirtualHost.class);
+        return children;
     }
 
     public Collection<Port<?>> getPorts()
     {
-        synchronized (_portAdapters)
-        {
-            return new ArrayList<Port<?>>(_portAdapters.values());
-        }
+        Collection children = getChildren(Port.class);
+        return children;
     }
 
     public Collection<AuthenticationProvider<?>> getAuthenticationProviders()
     {
-        synchronized (_authenticationProviders)
-        {
-            return new ArrayList<AuthenticationProvider<?>>(_authenticationProviders.values());
-        }
+        Collection children = getChildren(AuthenticationProvider.class);
+        return children;
     }
 
     public AuthenticationProvider<?> findAuthenticationProviderByName(String authenticationProviderName)
@@ -403,40 +385,24 @@ public class BrokerAdapter extends Abstr
         {
             return _managementModeAuthenticationProvider;
         }
-        Collection<AuthenticationProvider<?>> providers = getAuthenticationProviders();
-        for (AuthenticationProvider<?> authenticationProvider : providers)
-        {
-            if (authenticationProvider.getName().equals(authenticationProviderName))
-            {
-                return authenticationProvider;
-            }
-        }
-        return null;
+        return getChildByName(AuthenticationProvider.class, authenticationProviderName);
     }
 
     public KeyStore<?> findKeyStoreByName(String keyStoreName)
     {
-        synchronized(_keyStores)
-        {
-            return _keyStores.get(keyStoreName);
-        }
+        return getChildByName(KeyStore.class, keyStoreName);
     }
 
     public TrustStore<?> findTrustStoreByName(String trustStoreName)
     {
-        synchronized(_trustStores)
-        {
-            return _trustStores.get(trustStoreName);
-        }
+        return getChildByName(TrustStore.class, trustStoreName);
     }
 
     @Override
     public Collection<GroupProvider<?>> getGroupProviders()
     {
-        synchronized (_groupProviders)
-        {
-            return new ArrayList<GroupProvider<?>>(_groupProviders.values());
-        }
+        Collection children = getChildren(GroupProvider.class);
+        return children;
     }
 
     private VirtualHost createVirtualHost(final Map<String, Object> attributes)
@@ -462,10 +428,6 @@ public class BrokerAdapter extends Abstr
 
     private boolean deleteVirtualHost(final VirtualHost vhost) throws AccessControlException, IllegalStateException
     {
-        synchronized (_vhostAdapters)
-        {
-            _vhostAdapters.remove(vhost.getName());
-        }
         vhost.removeChangeListener(this);
         return true;
     }
@@ -476,18 +438,6 @@ public class BrokerAdapter extends Abstr
         return null;  //TODO
     }
 
-    public long getTimeToLive()
-    {
-        return 0;
-    }
-
-    public long setTimeToLive(final long expected, final long desired)
-            throws IllegalStateException, AccessControlException, IllegalArgumentException
-    {
-        throw new IllegalStateException();
-    }
-
-
     @Override
     public long getBytesIn()
     {
@@ -514,40 +464,48 @@ public class BrokerAdapter extends Abstr
 
     @SuppressWarnings("unchecked")
     @Override
-    public <C extends ConfiguredObject> C addChild(Class<C> childClass, Map<String, Object> attributes, ConfiguredObject... otherParents)
+    public <C extends ConfiguredObject> C addChild(final Class<C> childClass, final Map<String, Object> attributes, final ConfiguredObject... otherParents)
     {
-        if(childClass == VirtualHost.class)
-        {
-            return (C) createVirtualHost(attributes);
-        }
-        else if(childClass == Port.class)
+        return runTask( new TaskExecutor.Task<C>()
         {
-            return (C) createPort(attributes);
-        }
-        else if(childClass == AccessControlProvider.class)
-        {
-            return (C) createAccessControlProvider(attributes);
-        }
-        else if(childClass == AuthenticationProvider.class)
-        {
-            return (C) createAuthenticationProvider(attributes);
-        }
-        else if(childClass == KeyStore.class)
-        {
-            return (C) createKeyStore(attributes);
-        }
-        else if(childClass == TrustStore.class)
-        {
-            return (C) createTrustStore(attributes);
-        }
-        else if(childClass == GroupProvider.class)
-        {
-            return (C) createGroupProvider(attributes);
-        }
-        else
-        {
-            throw new IllegalArgumentException("Cannot create child of class " + childClass.getSimpleName());
-        }
+            @Override
+            public C execute()
+            {
+                if (childClass == VirtualHost.class)
+                {
+                    return (C) createVirtualHost(attributes);
+                }
+                else if (childClass == Port.class)
+                {
+                    return (C) createPort(attributes);
+                }
+                else if (childClass == AccessControlProvider.class)
+                {
+                    return (C) createAccessControlProvider(attributes);
+                }
+                else if (childClass == AuthenticationProvider.class)
+                {
+                    return (C) createAuthenticationProvider(attributes);
+                }
+                else if (childClass == KeyStore.class)
+                {
+                    return (C) createKeyStore(attributes);
+                }
+                else if (childClass == TrustStore.class)
+                {
+                    return (C) createTrustStore(attributes);
+                }
+                else if (childClass == GroupProvider.class)
+                {
+                    return (C) createGroupProvider(attributes);
+                }
+                else
+                {
+                    throw new IllegalArgumentException("Cannot create child of class " + childClass.getSimpleName());
+                }
+            }
+        });
+
     }
 
     /**
@@ -569,101 +527,77 @@ public class BrokerAdapter extends Abstr
         return port;
     }
 
-    private void addPort(Port<?> port)
+    private void addPort(final Port<?> port)
     {
-        synchronized (_portAdapters)
-        {
-            int portNumber = port.getPort();
-            String portName = port.getName();
-            UUID portId = port.getId();
+        assert getTaskExecutor().isTaskExecutorThread();
 
-            for(Port<?> p : _portAdapters.values())
-            {
-                if(portNumber == p.getPort())
-                {
-                    throw new IllegalConfigurationException("Can't add port " + portName + " because port number " + portNumber + " is already configured for port " + p.getName());
-                }
-
-                if(portName.equals(p.getName()))
-                {
-                    throw new IllegalConfigurationException("Can't add Port because one with name " + portName + " already exists");
-                }
+        int portNumber = port.getPort();
+        String portName = port.getName();
 
-                if(portId.equals(p.getId()))
+        for (Port<?> p : getChildren(Port.class))
+        {
+            if(p != port)
+            {
+                if (portNumber == p.getPort())
                 {
-                    throw new IllegalConfigurationException("Can't add Port because one with id " + portId + " already exists");
+                    throw new IllegalConfigurationException("Can't add port "
+                                                            + portName
+                                                            + " because port number "
+                                                            + portNumber
+                                                            + " is already configured for port "
+                                                            + p.getName());
                 }
             }
-
-            _portAdapters.put(port.getId(), port);
         }
+
         port.addChangeListener(this);
+
     }
 
-    private AccessControlProvider<?> createAccessControlProvider(Map<String, Object> attributes)
+    private AccessControlProvider<?> createAccessControlProvider(final Map<String, Object> attributes)
     {
-        AccessControlProvider<?> accessControlProvider;
-        synchronized (_accessControlProviders)
-        {
-            accessControlProvider = (AccessControlProvider<?>) createChild(AccessControlProvider.class, attributes);
-            addAccessControlProvider(accessControlProvider);
-        }
+        assert getTaskExecutor().isTaskExecutorThread();
+
+        AccessControlProvider<?> accessControlProvider = (AccessControlProvider<?>) createChild(AccessControlProvider.class, attributes);
+        addAccessControlProvider(accessControlProvider);
 
-        boolean quiesce = isManagementMode() ;
+        boolean quiesce = isManagementMode();
         accessControlProvider.setDesiredState(State.INITIALISING, quiesce ? State.QUIESCED : State.ACTIVE);
 
         return accessControlProvider;
+
     }
 
-    /**
-     * @throws IllegalConfigurationException if an AuthenticationProvider with the same name already exists
-     */
-    private void addAccessControlProvider(AccessControlProvider<?> accessControlProvider)
+    private void addAccessControlProvider(final AccessControlProvider<?> accessControlProvider)
     {
-        String name = accessControlProvider.getName();
-        synchronized (_accessControlProviders)
-        {
-            if (_accessControlProviders.containsKey(accessControlProvider.getId()))
-            {
-                throw new IllegalConfigurationException("Can't add AccessControlProvider because one with id " + accessControlProvider.getId() + " already exists");
-            }
-            for (AccessControlProvider<?> provider : _accessControlProviders.values())
-            {
-                if (provider.getName().equals(name))
-                {
-                    throw new IllegalConfigurationException("Can't add AccessControlProvider because one with name " + name + " already exists");
-                }
-            }
-            _accessControlProviders.put(accessControlProvider.getId(), accessControlProvider);
-        }
+        assert getTaskExecutor().isTaskExecutorThread();
 
         accessControlProvider.addChangeListener(this);
         accessControlProvider.addChangeListener(_securityManager);
+
     }
 
     private boolean deleteAccessControlProvider(AccessControlProvider<?> accessControlProvider)
     {
-        AccessControlProvider removedAccessControlProvider;
-        synchronized (_accessControlProviders)
-        {
-            removedAccessControlProvider = _accessControlProviders.remove(accessControlProvider.getId());
-        }
-
-        if(removedAccessControlProvider != null)
-        {
-            removedAccessControlProvider.removeChangeListener(this);
-            removedAccessControlProvider.removeChangeListener(_securityManager);
-        }
+        accessControlProvider.removeChangeListener(this);
+        accessControlProvider.removeChangeListener(_securityManager);
 
-        return removedAccessControlProvider != null;
+        return true;
     }
 
-    private AuthenticationProvider createAuthenticationProvider(Map<String, Object> attributes)
+    private AuthenticationProvider createAuthenticationProvider(final Map<String, Object> attributes)
     {
-        AuthenticationProvider<?> authenticationProvider = createChild(AuthenticationProvider.class, attributes);
-        addAuthenticationProvider(authenticationProvider);
-        authenticationProvider.setDesiredState(State.INITIALISING, State.ACTIVE);
-        return authenticationProvider;
+        return runTask(new TaskExecutor.Task<AuthenticationProvider>()
+        {
+            @Override
+            public AuthenticationProvider execute()
+            {
+                AuthenticationProvider<?> authenticationProvider = createChild(AuthenticationProvider.class, attributes);
+                addAuthenticationProvider(authenticationProvider);
+                authenticationProvider.setDesiredState(State.INITIALISING, State.ACTIVE);
+                return authenticationProvider;
+            }
+        });
     }
 
     private <X extends ConfiguredObject> X createChild(Class<X> clazz, Map<String, Object> attributes)
@@ -685,61 +619,35 @@ public class BrokerAdapter extends Abstr
      */
     private void addAuthenticationProvider(AuthenticationProvider<?> authenticationProvider)
     {
-        String name = authenticationProvider.getName();
-        synchronized (_authenticationProviders)
-        {
-            if (_authenticationProviders.containsKey(authenticationProvider.getId()))
-            {
-                throw new IllegalConfigurationException("Cannot add AuthenticationProvider because one with id " + authenticationProvider.getId() + " already exists");
-            }
-            for (AuthenticationProvider provider : _authenticationProviders.values())
-            {
-                if (provider.getName().equals(name))
-                {
-                    throw new IllegalConfigurationException("Cannot add AuthenticationProvider because one with name " + name + " already exists");
-                }
-            }
-            _authenticationProviders.put(authenticationProvider.getId(), authenticationProvider);
-        }
+        assert getTaskExecutor().isTaskExecutorThread();
+
         authenticationProvider.addChangeListener(this);
     }
 
-    private GroupProvider<?> createGroupProvider(Map<String, Object> attributes)
+    private GroupProvider<?> createGroupProvider(final Map<String, Object> attributes)
     {
-        GroupProvider<?> groupProvider = createChild(GroupProvider.class, attributes);
-        addGroupProvider(groupProvider);
-        groupProvider.setDesiredState(State.INITIALISING, State.ACTIVE);
-        return groupProvider;
+        return runTask(new TaskExecutor.Task<GroupProvider<?>>()
+        {
+            @Override
+            public GroupProvider<?> execute()
+            {
+                GroupProvider<?> groupProvider = createChild(GroupProvider.class, attributes);
+                addGroupProvider(groupProvider);
+                groupProvider.setDesiredState(State.INITIALISING, State.ACTIVE);
+                return groupProvider;
+            }
+        });
     }
 
     private void addGroupProvider(GroupProvider<?> groupProvider)
     {
-        synchronized (_groupProviders)
-        {
-            String name = groupProvider.getName();
-            if(_groupProviders.containsKey(name))
-            {
-                throw new IllegalConfigurationException("Cannot add GroupProvider because one with name " + name + " already exists");
-            }
-            _groupProviders.put(name, groupProvider);
-        }
         groupProvider.addChangeListener(this);
     }
 
     private boolean deleteGroupProvider(GroupProvider groupProvider)
     {
-        GroupProvider removedGroupProvider = null;
-        synchronized (_groupProviders)
-        {
-            removedGroupProvider = _groupProviders.remove(groupProvider.getName());
-        }
-
-        if(removedGroupProvider != null)
-        {
-            removedGroupProvider.removeChangeListener(this);
-        }
-
-        return removedGroupProvider != null;
+        groupProvider.removeChangeListener(this);
+        return true;
     }
 
     private KeyStore createKeyStore(Map<String, Object> attributes)
@@ -760,58 +668,25 @@ public class BrokerAdapter extends Abstr
 
     private void addKeyStore(KeyStore keyStore)
     {
-        synchronized (_keyStores)
-        {
-            if(_keyStores.containsKey(keyStore.getName()))
-            {
-                throw new IllegalConfigurationException("Can't add KeyStore because one with name " + keyStore.getName() + " already exists");
-            }
-            _keyStores.put(keyStore.getName(), keyStore);
-        }
         keyStore.addChangeListener(this);
     }
 
-    private boolean deleteKeyStore(KeyStore object)
+    private boolean deleteKeyStore(KeyStore keyStore)
     {
-        synchronized(_keyStores)
-        {
-            String name = object.getName();
-            KeyStore removedKeyStore = _keyStores.remove(name);
-            if(removedKeyStore != null)
-            {
-                removedKeyStore.removeChangeListener(this);
-            }
-
-            return removedKeyStore != null;
-        }
+        keyStore.removeChangeListener(this);
+        return true;
     }
 
     private void addTrustStore(TrustStore trustStore)
     {
-        synchronized (_trustStores)
-        {
-            if(_trustStores.containsKey(trustStore.getName()))
-            {
-                throw new IllegalConfigurationException("Can't add TrustStore because one with name " + trustStore.getName() + " already exists");
-            }
-            _trustStores.put(trustStore.getName(), trustStore);
-        }
         trustStore.addChangeListener(this);
     }
 
-    private boolean deleteTrustStore(TrustStore object)
+    private boolean deleteTrustStore(TrustStore trustStore)
     {
-        synchronized(_trustStores)
-        {
-            String name = object.getName();
-            TrustStore removedTrustStore = _trustStores.remove(name);
-            if(removedTrustStore != null)
-            {
-                removedTrustStore.removeChangeListener(this);
-            }
+        trustStore.removeChangeListener(this);
+        return true;
 
-            return removedTrustStore != null;
-        }
     }
 
     @Override
@@ -824,56 +699,36 @@ public class BrokerAdapter extends Abstr
         return super.getAttribute(name);
     }
 
-    private boolean deletePort(State oldState, Port portAdapter)
+    private boolean deletePort(State oldState, Port port)
     {
-        Port<?> removedPort;
-        synchronized (_portAdapters)
-        {
-            removedPort = _portAdapters.remove(portAdapter.getId());
-        }
+        port.removeChangeListener(this);
 
-        if (removedPort != null)
-        {
-            removedPort.removeChangeListener(this);
+        // TODO - this seems suspicious, wouldn't it make more sense to not allow deletion from active
+        // (must be stopped first) or something?
 
-            if(oldState == State.ACTIVE)
-            {
-                //Record the originally used port numbers of previously-active ports being deleted, to ensure
-                //when creating new ports we don't try to re-bind a port number that we are currently still using
-                recordPreviouslyUsedPortNumberIfNecessary(removedPort, removedPort.getPort());
-            }
+        if(oldState == State.ACTIVE)
+        {
+            //Record the originally used port numbers of previously-active ports being deleted, to ensure
+            //when creating new ports we don't try to re-bind a port number that we are currently still using
+            recordPreviouslyUsedPortNumberIfNecessary(port, port.getPort());
         }
 
-        return removedPort != null;
+
+        return port != null;
     }
 
     private boolean deleteAuthenticationProvider(AuthenticationProvider<?> authenticationProvider)
     {
-        AuthenticationProvider removedAuthenticationProvider;
-        synchronized (_authenticationProviders)
-        {
-            removedAuthenticationProvider = _authenticationProviders.remove(authenticationProvider.getId());
-        }
-
-        if(removedAuthenticationProvider != null)
+        if(authenticationProvider != null)
         {
-            removedAuthenticationProvider.removeChangeListener(this);
+            authenticationProvider.removeChangeListener(this);
         }
-
-        return removedAuthenticationProvider != null;
+        return true;
     }
 
     private void addVirtualHost(VirtualHost<?,?,?> virtualHost)
     {
-        synchronized (_vhostAdapters)
-        {
-            String name = virtualHost.getName();
-            if (_vhostAdapters.containsKey(name))
-            {
-                throw new IllegalConfigurationException("Virtual host with name " + name + " is already specified!");
-            }
-            _vhostAdapters.put(name, virtualHost);
-        }
+
         virtualHost.addChangeListener(this);
     }
 
@@ -883,16 +738,7 @@ public class BrokerAdapter extends Abstr
         if (desiredState == State.ACTIVE)
         {
             initialiseStatisticsReporting();
-            changeState(_groupProviders, currentState, State.ACTIVE, false);
-            changeState(_authenticationProviders, currentState, State.ACTIVE, false);
-            changeState(_accessControlProviders, currentState, State.ACTIVE, false);
-
-
-            changeState(_vhostAdapters, currentState, State.ACTIVE, false);
-
-            changeState(_portAdapters, currentState,State.ACTIVE, false);
-            changeState(_plugins, currentState,State.ACTIVE, false);
-
+            changeChildState(currentState, State.ACTIVE, false);
             if (isManagementMode())
             {
                 _eventLogger.message(BrokerMessages.MANAGEMENT_MODE(BrokerOptions.MANAGEMENT_MODE_USER_NAME,
@@ -908,49 +754,53 @@ public class BrokerAdapter extends Abstr
                 _reportingTimer.cancel();
             }
 
-            changeState(_plugins, currentState,State.STOPPED, true);
-            changeState(_portAdapters, currentState, State.STOPPED, true);
-            changeState(_vhostAdapters,currentState, State.STOPPED, true);
-            changeState(_authenticationProviders, currentState, State.STOPPED, true);
-            changeState(_groupProviders, currentState, State.STOPPED, true);
-            _virtualHostRegistry.close();
+            changeChildState(currentState, State.STOPPED, true);
             return true;
         }
         return false;
     }
 
-    private void changeState(Map<?, ? extends ConfiguredObject> configuredObjectMap, State currentState, State desiredState, boolean swallowException)
+    private void changeChildState(final State currentState,
+                                  final State desiredState,
+                                  final boolean swallowException)
     {
-        synchronized(configuredObjectMap)
+        runTask(new TaskExecutor.VoidTask()
         {
-            Collection<? extends ConfiguredObject> adapters = configuredObjectMap.values();
-            for (ConfiguredObject configuredObject : adapters)
+            @Override
+            public void execute()
             {
-                if (State.ACTIVE.equals(desiredState) && State.QUIESCED.equals(configuredObject.getState()))
+                for (Class<? extends ConfiguredObject> clazz : Model.getInstance().getChildTypes(getCategoryClass()))
                 {
-                    if (LOGGER.isDebugEnabled())
+                    for (ConfiguredObject configuredObject : getChildren(clazz))
                     {
-                        LOGGER.debug(configuredObject + " cannot be activated as it is " +State.QUIESCED);
-                    }
-                    continue;
-                }
-                try
-                {
-                    configuredObject.setDesiredState(currentState, desiredState);
-                }
-                catch(RuntimeException e)
-                {
-                    if (swallowException)
-                    {
-                        LOGGER.error("Failed to stop " + configuredObject, e);
-                    }
-                    else
-                    {
-                        throw e;
+                        if (State.ACTIVE.equals(desiredState) && State.QUIESCED.equals(configuredObject.getState()))
+                        {
+                            if (LOGGER.isDebugEnabled())
+                            {
+                                LOGGER.debug(configuredObject + " cannot be activated as it is " + State.QUIESCED);
+                            }
+                            continue;
+                        }
+                        try
+                        {
+                            configuredObject.setDesiredState(currentState, desiredState);
+                        }
+                        catch (RuntimeException e)
+                        {
+                            if (swallowException)
+                            {
+                                LOGGER.error("Failed to stop " + configuredObject, e);
+                            }
+                            else
+                            {
+                                throw e;
+                            }
+                        }
                     }
                 }
             }
-        }
+        });
+
     }
 
     @Override
@@ -1023,24 +873,14 @@ public class BrokerAdapter extends Abstr
 
     private void addPlugin(ConfiguredObject<?> plugin)
     {
-        synchronized(_plugins)
-        {
-            if (_plugins.containsKey(plugin.getId()))
-            {
-                throw new IllegalConfigurationException("Plugin with id '" + plugin.getId() + "' is already registered!");
-            }
-            _plugins.put(plugin.getId(), plugin);
-        }
         plugin.addChangeListener(this);
     }
 
 
     private Collection<ConfiguredObject<?>> getPlugins()
     {
-        synchronized(_plugins)
-        {
-            return Collections.unmodifiableCollection(_plugins.values());
-        }
+        Collection children = getChildren(Plugin.class);
+        return children;
     }
 
     @Override
@@ -1058,7 +898,7 @@ public class BrokerAdapter extends Abstr
     @Override
     public VirtualHost findVirtualHostByName(String name)
     {
-        return _vhostAdapters.get(name);
+        return getChildByName(VirtualHost.class, name);
     }
 
     @Override
@@ -1094,31 +934,15 @@ public class BrokerAdapter extends Abstr
     @Override
     public Collection<KeyStore<?>> getKeyStores()
     {
-        synchronized(_keyStores)
-        {
-            return Collections.unmodifiableCollection(_keyStores.values());
-        }
+        Collection children = getChildren(KeyStore.class);
+        return children;
     }
 
     @Override
     public Collection<TrustStore<?>> getTrustStores()
     {
-        synchronized(_trustStores)
-        {
-            return Collections.unmodifiableCollection(_trustStores.values());
-        }
-    }
-
-    @Override
-    public VirtualHostRegistry getVirtualHostRegistry()
-    {
-        return _virtualHostRegistry;
-    }
-
-    @Override
-    public TaskExecutor getTaskExecutor()
-    {
-        return super.getTaskExecutor();
+        Collection children = getChildren(TrustStore.class);
+        return children;
     }
 
     @Override
@@ -1149,10 +973,8 @@ public class BrokerAdapter extends Abstr
     @Override
     public Collection<AccessControlProvider<?>> getAccessControlProviders()
     {
-        synchronized (_accessControlProviders)
-        {
-            return new ArrayList<AccessControlProvider<?>>(_accessControlProviders.values());
-        }
+        Collection children = getChildren(AccessControlProvider.class);
+        return children;
     }
 
     private void recordPreviouslyUsedPortNumberIfNecessary(Port port, Integer portNumber)
@@ -1232,9 +1054,12 @@ public class BrokerAdapter extends Abstr
         _messagesReceived.reset();
         _dataReceived.reset();
 
-        for (VirtualHostImpl vhost : _virtualHostRegistry.getVirtualHosts())
+        for (VirtualHost vhost : getVirtualHosts())
         {
-            vhost.resetStatistics();
+            if(vhost instanceof VirtualHostImpl)
+            {
+                ((VirtualHostImpl) vhost).resetStatistics();
+            }
         }
     }
 
@@ -1285,27 +1110,37 @@ public class BrokerAdapter extends Abstr
                 _eventLogger.message(BrokerMessages.STATS_MSGS(RECEIVED,
                                                                _messagesReceived.getPeak(),
                                                                _messagesReceived.getTotal()));
-                Collection<VirtualHostImpl> hosts = _virtualHostRegistry.getVirtualHosts();
+                Collection<VirtualHost<?,?,?>> hosts = getVirtualHosts();
 
-                if (hosts.size() > 1)
-                {
-                    for (VirtualHostImpl vhost : hosts)
+                    for (VirtualHost vhost : hosts)
                     {
-                        String name = vhost.getName();
-                        StatisticsCounter dataDelivered = vhost.getDataDeliveryStatistics();
-                        StatisticsCounter messagesDelivered = vhost.getMessageDeliveryStatistics();
-                        StatisticsCounter dataReceived = vhost.getDataReceiptStatistics();
-                        StatisticsCounter messagesReceived = vhost.getMessageReceiptStatistics();
-                        EventLogger logger = vhost.getEventLogger();
-                        logger.message(VirtualHostMessages.STATS_DATA(name,
-                                                                      DELIVERED,
-                                                                      dataDelivered.getPeak() / 1024.0,
-                                                                      dataDelivered.getTotal()));
-                        logger.message(VirtualHostMessages.STATS_MSGS(name, DELIVERED, messagesDelivered.getPeak(), messagesDelivered.getTotal()));
-                        logger.message(VirtualHostMessages.STATS_DATA(name, RECEIVED, dataReceived.getPeak() / 1024.0, dataReceived.getTotal()));
-                        logger.message(VirtualHostMessages.STATS_MSGS(name, RECEIVED, messagesReceived.getPeak(), messagesReceived.getTotal()));
+                        if(vhost instanceof VirtualHostImpl)
+                        {
+                            VirtualHostImpl vhostImpl = (VirtualHostImpl) vhost;
+                            String name = vhost.getName();
+                            StatisticsCounter dataDelivered = vhostImpl.getDataDeliveryStatistics();
+                            StatisticsCounter messagesDelivered = vhostImpl.getMessageDeliveryStatistics();
+                            StatisticsCounter dataReceived = vhostImpl.getDataReceiptStatistics();
+                            StatisticsCounter messagesReceived = vhostImpl.getMessageReceiptStatistics();
+                            EventLogger logger = vhostImpl.getEventLogger();
+                            logger.message(VirtualHostMessages.STATS_DATA(name,
+                                                                          DELIVERED,
+                                                                          dataDelivered.getPeak() / 1024.0,
+                                                                          dataDelivered.getTotal()));
+                            logger.message(VirtualHostMessages.STATS_MSGS(name,
+                                                                          DELIVERED,
+                                                                          messagesDelivered.getPeak(),
+                                                                          messagesDelivered.getTotal()));
+                            logger.message(VirtualHostMessages.STATS_DATA(name,
+                                                                          RECEIVED,
+                                                                          dataReceived.getPeak() / 1024.0,
+                                                                          dataReceived.getTotal()));
+                            logger.message(VirtualHostMessages.STATS_MSGS(name,
+                                                                          RECEIVED,
+                                                                          messagesReceived.getPeak(),
+                                                                          messagesReceived.getTotal()));
+                        }
                     }
-                }
 
                 if (_reset)
                 {

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java Sun Apr 20 01:32:50 2014
@@ -27,6 +27,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -420,7 +421,7 @@ abstract public class AbstractPort<X ext
             //ManagementMode needs this relaxed to allow its overriding management ports to be inserted.
 
             //Enforce only a single port of each management protocol, as the plugins will only use one.
-            Collection<Port<?>> existingPorts = broker.getPorts();
+            Collection<Port<?>> existingPorts = new HashSet<Port<?>>(broker.getPorts());
             existingPorts.remove(this);
 
             for (Port<?> existingPort : existingPorts)

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPort.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPort.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPort.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPort.java Sun Apr 20 01:32:50 2014
@@ -24,6 +24,7 @@ import org.apache.qpid.server.model.Auth
 import org.apache.qpid.server.model.ManagedAttribute;
 import org.apache.qpid.server.model.ManagedObject;
 import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.virtualhost.VirtualHostImpl;
 
 @ManagedObject( category = false, type = "AMQP")
 public interface AmqpPort<X extends AmqpPort<X>> extends Port<X>
@@ -53,4 +54,6 @@ public interface AmqpPort<X extends Amqp
 
     @ManagedAttribute( automate = true, mandatory = true )
     AuthenticationProvider getAuthenticationProvider();
+
+    VirtualHostImpl getVirtualHost(String name);
 }

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPortImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPortImpl.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPortImpl.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPortImpl.java Sun Apr 20 01:32:50 2014
@@ -41,11 +41,13 @@ import org.apache.qpid.server.model.Mana
 import org.apache.qpid.server.model.Protocol;
 import org.apache.qpid.server.model.Transport;
 import org.apache.qpid.server.model.TrustStore;
+import org.apache.qpid.server.model.VirtualHost;
 import org.apache.qpid.server.plugin.QpidServiceLoader;
 import org.apache.qpid.server.plugin.TransportProviderFactory;
 import org.apache.qpid.server.transport.AcceptingTransport;
 import org.apache.qpid.server.transport.TransportProvider;
 import org.apache.qpid.server.util.ServerScopedRuntimeException;
+import org.apache.qpid.server.virtualhost.VirtualHostImpl;
 import org.apache.qpid.transport.network.security.ssl.QpidMultipleTrustManager;
 
 public class AmqpPortImpl extends AbstractPortWithAuthProvider<AmqpPortImpl> implements AmqpPort<AmqpPortImpl>
@@ -89,6 +91,17 @@ public class AmqpPortImpl extends Abstra
         return _receiveBufferSize;
     }
 
+    @Override
+    public VirtualHostImpl getVirtualHost(String name)
+    {
+        // TODO - aliases
+        if(name == null || name.trim().length() == 0)
+        {
+            name = _broker.getDefaultVirtualHost();
+        }
+        return (VirtualHostImpl) _broker.getChildByName(VirtualHost.class, name);
+    }
+
     protected Set<Protocol> getDefaultProtocols()
     {
         Set<Protocol> defaultProtocols = EnumSet.of(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1,

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ScramSHA1AuthenticationManager.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ScramSHA1AuthenticationManager.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ScramSHA1AuthenticationManager.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ScramSHA1AuthenticationManager.java Sun Apr 20 01:32:50 2014
@@ -45,7 +45,6 @@ import javax.xml.bind.DatatypeConverter;
 
 import org.apache.qpid.server.configuration.ConfiguredObjectRecoverer;
 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.Broker;
@@ -255,42 +254,34 @@ public class ScramSHA1AuthenticationMana
     @Override
     public boolean createUser(final String username, final String password, final Map<String, String> attributes)
     {
-        if (getTaskExecutor().isTaskExecutorThread())
+        return runTask(new TaskExecutor.Task<Boolean>()
         {
-            getSecurityManager().authoriseUserOperation(Operation.CREATE, username);
-            if(_users.containsKey(username))
+            @Override
+            public Boolean execute()
             {
-                throw new IllegalArgumentException("User '"+username+"' already exists");
-            }
-            try
-            {
-                Map<String,Object> userAttrs = new HashMap<String, Object>();
-                userAttrs.put(User.ID, UUID.randomUUID());
-                userAttrs.put(User.NAME, username);
-                userAttrs.put(User.PASSWORD, createStoredPassword(password));
-                userAttrs.put(User.TYPE, SCRAM_USER_TYPE);
-                ScramAuthUser user = new ScramAuthUser(userAttrs, this);
-                user.create();
-
-                return true;
-            }
-            catch (SaslException e)
-            {
-                throw new IllegalArgumentException(e);
-            }
-        }
-        else
-        {
-            return getTaskExecutor().submitAndWait(new TaskExecutor.Task<Boolean>()
-            {
-                @Override
-                public Boolean call()
+                getSecurityManager().authoriseUserOperation(Operation.CREATE, username);
+                if (_users.containsKey(username))
                 {
-                    return createUser(username, password, attributes);
+                    throw new IllegalArgumentException("User '" + username + "' already exists");
                 }
-            });
-        }
+                try
+                {
+                    Map<String, Object> userAttrs = new HashMap<String, Object>();
+                    userAttrs.put(User.ID, UUID.randomUUID());
+                    userAttrs.put(User.NAME, username);
+                    userAttrs.put(User.PASSWORD, createStoredPassword(password));
+                    userAttrs.put(User.TYPE, SCRAM_USER_TYPE);
+                    ScramAuthUser user = new ScramAuthUser(userAttrs, ScramSHA1AuthenticationManager.this);
+                    user.create();
 
+                    return true;
+                }
+                catch (SaslException e)
+                {
+                    throw new IllegalArgumentException(e);
+                }
+            }
+        });
     }
 
     private SecurityManager getSecurityManager()
@@ -301,115 +292,64 @@ public class ScramSHA1AuthenticationMana
     @Override
     public void deleteUser(final String user) throws AccountNotFoundException
     {
-        if (getTaskExecutor().isTaskExecutorThread())
+        runTask(new TaskExecutor.VoidTaskWithException<AccountNotFoundException>()
         {
-
-            final ScramAuthUser authUser = getUser(user);
-            if(authUser != null)
-            {
-                authUser.setState(State.ACTIVE, State.DELETED);
-            }
-            else
+            @Override
+            public void execute() throws AccountNotFoundException
             {
-                throw new AccountNotFoundException("No such user: '" + user + "'");
-            }
-        }
-        else
-        {
-            AccountNotFoundException e =
-                    getTaskExecutor().submitAndWait(new TaskExecutor.Task<AccountNotFoundException>() {
-
-                @Override
-                public AccountNotFoundException call()
+                final ScramAuthUser authUser = getUser(user);
+                if(authUser != null)
                 {
-                    try
-                    {
-                        deleteUser(user);
-                        return null;
-                    }
-                    catch (AccountNotFoundException e)
-                    {
-                        return e;
-                    }
-
+                    authUser.setState(State.ACTIVE, State.DELETED);
+                }
+                else
+                {
+                    throw new AccountNotFoundException("No such user: '" + user + "'");
                 }
-            });
-
-            if(e != null)
-            {
-                throw e;
             }
-        }
+        });
     }
 
     @Override
     public void setPassword(final String username, final String password) throws AccountNotFoundException
     {
-        if (getTaskExecutor().isTaskExecutorThread())
+        runTask(new TaskExecutor.VoidTaskWithException<AccountNotFoundException>()
         {
-            final ScramAuthUser authUser = getUser(username);
-            if(authUser != null)
+            @Override
+            public void execute() throws AccountNotFoundException
             {
-                authUser.setPassword(password);
-            }
-            else
-            {
-                throw new AccountNotFoundException("No such user: '" + username + "'");
-            }
-        }
-        else
-        {
-            AccountNotFoundException e =
-                    getTaskExecutor().submitAndWait(new TaskExecutor.Task<AccountNotFoundException>()
-                    {
 
-                        @Override
-                        public AccountNotFoundException call()
-                        {
-                            try
-                            {
-                                setPassword(username, password);
-                                return null;
-                            }
-                            catch (AccountNotFoundException e)
-                            {
-                                return e;
-                            }
-
-                        }
-                    });
-
-            if (e != null)
-            {
-                throw e;
+                final ScramAuthUser authUser = getUser(username);
+                if (authUser != null)
+                {
+                    authUser.setPassword(password);
+                }
+                else
+                {
+                    throw new AccountNotFoundException("No such user: '" + username + "'");
+                }
             }
-        }
+        });
 
     }
 
     @Override
     public Map<String, Map<String, String>> getUsers()
     {
-        if (getTaskExecutor().isTaskExecutorThread())
-        {
-            Map<String, Map<String,String>> users = new HashMap<String, Map<String, String>>();
-            for(String user : _users.keySet())
-            {
-                users.put(user, Collections.<String,String>emptyMap());
-            }
-            return users;
-        }
-        else
+        return runTask(new TaskExecutor.Task<Map<String, Map<String, String>>>()
         {
-            return getTaskExecutor().submitAndWait(new TaskExecutor.Task<Map<String, Map<String, String>>>()
+            @Override
+            public Map<String, Map<String, String>> execute()
             {
-                @Override
-                public Map<String, Map<String, String>> call()
+
+                Map<String, Map<String, String>> users = new HashMap<String, Map<String, String>>();
+                for (String user : _users.keySet())
                 {
-                    return getUsers();
+                    users.put(user, Collections.<String, String>emptyMap());
                 }
-            });
-        }
+                return users;
+            }
+        });
     }
 
     @Override
@@ -491,27 +431,31 @@ public class ScramSHA1AuthenticationMana
         public void setAttributes(final Map<String, Object> attributes)
                 throws IllegalStateException, AccessControlException, IllegalArgumentException
         {
-            if (getTaskExecutor().isTaskExecutorThread())
+            runTask(new TaskExecutor.VoidTask()
             {
-                Map<String,Object> modifiedAttributes = new HashMap<String, Object>(attributes);
-                final String newPassword = (String) attributes.get(User.PASSWORD);
-                if(attributes.containsKey(User.PASSWORD) && !newPassword.equals(getActualAttributes().get(User.PASSWORD)))
+
+                @Override
+                public void execute()
                 {
-                    try
-                    {
-                        modifiedAttributes.put(User.PASSWORD, _authenticationManager.createStoredPassword(newPassword));
-                    }
-                    catch (SaslException e)
+                    Map<String, Object> modifiedAttributes = new HashMap<String, Object>(attributes);
+                    final String newPassword = (String) attributes.get(User.PASSWORD);
+                    if (attributes.containsKey(User.PASSWORD)
+                        && !newPassword.equals(getActualAttributes().get(User.PASSWORD)))
                     {
-                        throw new IllegalArgumentException(e);
+                        try
+                        {
+                            modifiedAttributes.put(User.PASSWORD,
+                                                   _authenticationManager.createStoredPassword(newPassword));
+                        }
+                        catch (SaslException e)
+                        {
+                            throw new IllegalArgumentException(e);
+                        }
                     }
+                    ScramSHA1AuthenticationManager.ScramAuthUser.super.setAttributes(modifiedAttributes);
                 }
-                super.setAttributes(modifiedAttributes);
-            }
-            else
-            {
-                getTaskExecutor().submitAndWait(new ChangeAttributesTask(this, attributes));
-            }
+            });
+
 
         }
 

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java?rev=1588715&r1=1588714&r2=1588715&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java Sun Apr 20 01:32:50 2014
@@ -172,7 +172,7 @@ public abstract class AbstractVirtualHos
         _broker = broker;
         _dtxRegistry = new DtxRegistry();
 
-        _eventLogger = _broker.getVirtualHostRegistry().getEventLogger();
+        _eventLogger = _broker.getParent(SystemContext.class).getEventLogger();
 
         _eventLogger.message(VirtualHostMessages.CREATED(getName()));
 
@@ -244,8 +244,6 @@ public abstract class AbstractVirtualHos
         getMessageStore().addEventListener(this, Event.PERSISTENT_MESSAGE_SIZE_OVERFULL);
         getMessageStore().addEventListener(this, Event.PERSISTENT_MESSAGE_SIZE_UNDERFULL);
 
-        _broker.getVirtualHostRegistry().registerVirtualHost(this);
-
 
         synchronized(_aliases)
         {
@@ -869,11 +867,6 @@ public abstract class AbstractVirtualHos
         return null;
     }
 
-    public VirtualHostRegistry getVirtualHostRegistry()
-    {
-        return _broker.getVirtualHostRegistry();
-    }
-
     public void registerMessageDelivered(long messageSize)
     {
         _messagesDelivered.registerEvent(1L);
@@ -1448,15 +1441,7 @@ public abstract class AbstractVirtualHos
         }
         else if (desiredState == State.STOPPED)
         {
-            try
-            {
-                close();
-            }
-            finally
-            {
-                _broker.getVirtualHostRegistry().unregisterVirtualHost(this);
-            }
-
+            close();
             return true;
         }
         else if (desiredState == State.DELETED)



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message