qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgodf...@apache.org
Subject svn commit: r1584365 [2/15] - in /qpid/branches/java-broker-config-store-changes/qpid/java: ./ bdbstore/jmx/src/main/java/org/apache/qpid/server/store/berkeleydb/jmx/ bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/ bdbstore/src/main/jav...
Date Thu, 03 Apr 2014 19:59:01 GMT
Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java Thu Apr  3 19:58:53 2014
@@ -37,7 +37,7 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.log4j.Logger;
 import org.apache.qpid.server.message.EnqueueableMessage;
-import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.ConfiguredObject;
 import org.apache.qpid.server.queue.AMQQueue;
 import org.apache.qpid.server.store.ConfigurationRecoveryHandler;
 import org.apache.qpid.server.store.ConfiguredObjectRecord;
@@ -46,11 +46,8 @@ import org.apache.qpid.server.store.Even
 import org.apache.qpid.server.store.EventListener;
 import org.apache.qpid.server.store.EventManager;
 import org.apache.qpid.server.store.MessageStore;
-import org.apache.qpid.server.store.MessageStoreConstants;
 import org.apache.qpid.server.store.MessageStoreRecoveryHandler;
 import org.apache.qpid.server.store.MessageStoreRecoveryHandler.StoredMessageRecoveryHandler;
-import org.apache.qpid.server.store.State;
-import org.apache.qpid.server.store.StateManager;
 import org.apache.qpid.server.store.StorableMessageMetaData;
 import org.apache.qpid.server.store.StoreException;
 import org.apache.qpid.server.store.StoreFuture;
@@ -59,6 +56,7 @@ import org.apache.qpid.server.store.Stor
 import org.apache.qpid.server.store.TransactionLogRecoveryHandler;
 import org.apache.qpid.server.store.TransactionLogRecoveryHandler.QueueEntryRecoveryHandler;
 import org.apache.qpid.server.store.TransactionLogResource;
+import org.apache.qpid.server.store.berkeleydb.EnvironmentFacadeFactory.EnvironmentFacadeTask;
 import org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey;
 import org.apache.qpid.server.store.berkeleydb.entry.PreparedTransaction;
 import org.apache.qpid.server.store.berkeleydb.entry.QueueEntryKey;
@@ -72,6 +70,7 @@ import org.apache.qpid.server.store.berk
 import org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding;
 import org.apache.qpid.server.store.berkeleydb.tuple.XidBinding;
 import org.apache.qpid.server.store.berkeleydb.upgrade.Upgrader;
+import org.apache.qpid.server.util.MapValueConverter;
 import org.apache.qpid.util.FileUtils;
 
 import com.sleepycat.bind.tuple.ByteBinding;
@@ -102,7 +101,6 @@ public class BDBMessageStore implements 
     private static final Logger LOGGER = Logger.getLogger(BDBMessageStore.class);
 
     public static final int VERSION = 8;
-    public static final String ENVIRONMENT_CONFIGURATION = "bdbEnvironmentConfig";
     private static final int LOCK_RETRY_ATTEMPTS = 5;
     private static String CONFIGURED_OBJECTS_DB_NAME = "CONFIGURED_OBJECTS";
     private static String CONFIGURED_OBJECT_HIERARCHY_DB_NAME = "CONFIGURED_OBJECT_HIERARCHY";
@@ -110,25 +108,20 @@ public class BDBMessageStore implements 
     private static String MESSAGE_META_DATA_DB_NAME = "MESSAGE_METADATA";
     private static String MESSAGE_CONTENT_DB_NAME = "MESSAGE_CONTENT";
     private static String DELIVERY_DB_NAME = "QUEUE_ENTRIES";
+
+    //TODO: Add upgrader to remove BRIDGES and LINKS
     private static String BRIDGEDB_NAME = "BRIDGES";
     private static String LINKDB_NAME = "LINKS";
     private static String XID_DB_NAME = "XIDS";
     private static String CONFIG_VERSION_DB_NAME = "CONFIG_VERSION";
-    private static final String[] DATABASE_NAMES = new String[] { CONFIGURED_OBJECTS_DB_NAME, CONFIGURED_OBJECT_HIERARCHY_DB_NAME, MESSAGE_META_DATA_DB_NAME,
-            MESSAGE_CONTENT_DB_NAME, DELIVERY_DB_NAME, BRIDGEDB_NAME, LINKDB_NAME, XID_DB_NAME, CONFIG_VERSION_DB_NAME };
-
-    private final AtomicBoolean _closed = new AtomicBoolean(false);
+    private static final String[] CONFIGURATION_STORE_DATABASE_NAMES = new String[] { CONFIGURED_OBJECTS_DB_NAME, CONFIG_VERSION_DB_NAME , CONFIGURED_OBJECT_HIERARCHY_DB_NAME};
+    private static final String[] MESSAGE_STORE_DATABASE_NAMES = new String[] { MESSAGE_META_DATA_DB_NAME, MESSAGE_CONTENT_DB_NAME, DELIVERY_DB_NAME, BRIDGEDB_NAME, LINKDB_NAME, XID_DB_NAME };
 
     private EnvironmentFacade _environmentFacade;
     private final AtomicLong _messageId = new AtomicLong(0);
 
-    protected final StateManager _stateManager;
-
-    private MessageStoreRecoveryHandler _messageRecoveryHandler;
-
-    private TransactionLogRecoveryHandler _tlogRecoveryHandler;
-
-    private ConfigurationRecoveryHandler _configRecoveryHandler;
+    private final AtomicBoolean _messageStoreOpen = new AtomicBoolean();
+    private final AtomicBoolean _configurationStoreOpen = new AtomicBoolean();
 
     private long _totalStoreSize;
     private boolean _limitBusted;
@@ -137,12 +130,12 @@ public class BDBMessageStore implements 
 
     private final EventManager _eventManager = new EventManager();
     private final String _type;
-    private VirtualHost _virtualHost;
 
     private final EnvironmentFacadeFactory _environmentFacadeFactory;
 
     private volatile Committer _committer;
 
+
     public BDBMessageStore()
     {
         this(new StandardEnvironmentFacadeFactory());
@@ -152,7 +145,6 @@ public class BDBMessageStore implements 
     {
         _type = environmentFacadeFactory.getType();
         _environmentFacadeFactory = environmentFacadeFactory;
-        _stateManager = new StateManager(_eventManager);
     }
 
     @Override
@@ -162,110 +154,90 @@ public class BDBMessageStore implements 
     }
 
     @Override
-    public void configureConfigStore(VirtualHost virtualHost, ConfigurationRecoveryHandler recoveryHandler)
+    public void openConfigurationStore(ConfiguredObject<?> parent, Map<String, Object> storeSettings)
+    {
+        if (_configurationStoreOpen.compareAndSet(false,  true))
+        {
+            if (_environmentFacade == null)
+            {
+                String[] databaseNames = null;
+                if (MapValueConverter.getBooleanAttribute(IS_MESSAGE_STORE_TOO, storeSettings, false))
+                {
+                    databaseNames = new String[CONFIGURATION_STORE_DATABASE_NAMES.length + MESSAGE_STORE_DATABASE_NAMES.length];
+                    System.arraycopy(CONFIGURATION_STORE_DATABASE_NAMES, 0, databaseNames, 0, CONFIGURATION_STORE_DATABASE_NAMES.length);
+                    System.arraycopy(MESSAGE_STORE_DATABASE_NAMES, 0, databaseNames, CONFIGURATION_STORE_DATABASE_NAMES.length, MESSAGE_STORE_DATABASE_NAMES.length);
+                }
+                else
+                {
+                    databaseNames = CONFIGURATION_STORE_DATABASE_NAMES;
+                }
+                _environmentFacade = _environmentFacadeFactory.createEnvironmentFacade(storeSettings, new UpgradeTask(parent), new OpenDatabasesTask(databaseNames));
+            }
+            else
+            {
+                throw new IllegalStateException("The database have been already opened as message store");
+            }
+        }
+    }
+
+    @Override
+    public void recoverConfigurationStore(ConfigurationRecoveryHandler recoveryHandler)
     {
-        _stateManager.attainState(State.INITIALISING);
+        checkConfigurationStoreOpen();
 
-        _configRecoveryHandler = recoveryHandler;
-        _virtualHost = virtualHost;
+        recoverConfig(recoveryHandler);
     }
 
     @Override
-    public void configureMessageStore(VirtualHost virtualHost, MessageStoreRecoveryHandler messageRecoveryHandler,
-                                      TransactionLogRecoveryHandler tlogRecoveryHandler) throws StoreException
+    public void openMessageStore(ConfiguredObject<?> parent, Map<String, Object> messageStoreSettings) throws StoreException
     {
-        if(_stateManager.isInState(State.INITIAL))
+        if (_messageStoreOpen.compareAndSet(false, true))
         {
-            // Is acting as a message store, but not a durable config store
-            _stateManager.attainState(State.INITIALISING);
-        }
 
-        _messageRecoveryHandler = messageRecoveryHandler;
-        _tlogRecoveryHandler = tlogRecoveryHandler;
-        _virtualHost = virtualHost;
+            Object overfullAttr = messageStoreSettings.get(MessageStore.OVERFULL_SIZE);
+            Object underfullAttr = messageStoreSettings.get(MessageStore.UNDERFULL_SIZE);
 
-        completeInitialisation();
-    }
+            _persistentSizeHighThreshold = overfullAttr == null ? -1l :
+                                           overfullAttr instanceof Number ? ((Number) overfullAttr).longValue() : Long.parseLong(overfullAttr.toString());
+            _persistentSizeLowThreshold = underfullAttr == null ? _persistentSizeHighThreshold :
+                                           underfullAttr instanceof Number ? ((Number) underfullAttr).longValue() : Long.parseLong(underfullAttr.toString());
 
-    private void completeInitialisation() throws StoreException
-    {
-        configure(_virtualHost, _messageRecoveryHandler != null);
+            if(_persistentSizeLowThreshold > _persistentSizeHighThreshold || _persistentSizeLowThreshold < 0l)
+            {
+                _persistentSizeLowThreshold = _persistentSizeHighThreshold;
+            }
 
-        _stateManager.attainState(State.INITIALISED);
-    }
+            if (_environmentFacade == null)
+            {
+                _environmentFacade = _environmentFacadeFactory.createEnvironmentFacade(messageStoreSettings, new UpgradeTask(parent), new OpenDatabasesTask(MESSAGE_STORE_DATABASE_NAMES), new DiskSpaceTask());
+            }
 
-    private void startActivation() throws StoreException
-    {
-        DatabaseConfig dbConfig = new DatabaseConfig();
-        dbConfig.setTransactional(true);
-        dbConfig.setAllowCreate(true);
-        try
-        {
-            new Upgrader(_environmentFacade.getEnvironment(), _virtualHost).upgradeIfNecessary();
-            _environmentFacade.openDatabases(dbConfig, DATABASE_NAMES);
-            _totalStoreSize = getSizeOnDisk();
-        }
-        catch(DatabaseException e)
-        {
-            throw _environmentFacade.handleDatabaseException("Cannot configure store", e);
+            _committer = _environmentFacade.createCommitter(parent.getName());
+            _committer.start();
         }
-
     }
 
     @Override
-    public synchronized void activate() throws StoreException
+    public synchronized void recoverMessageStore(MessageStoreRecoveryHandler messageRecoveryHandler, TransactionLogRecoveryHandler transactionLogRecoveryHandler) throws StoreException
     {
-        // check if acting as a durable config store, but not a message store
-        if(_stateManager.isInState(State.INITIALISING))
-        {
-            completeInitialisation();
-        }
-
-        _stateManager.attainState(State.ACTIVATING);
-        startActivation();
+        checkMessageStoreOpen();
 
-        if(_configRecoveryHandler != null)
+        if(messageRecoveryHandler != null)
         {
-            recoverConfig(_configRecoveryHandler);
+            recoverMessages(messageRecoveryHandler);
         }
-        if(_messageRecoveryHandler != null)
+        if(transactionLogRecoveryHandler != null)
         {
-            recoverMessages(_messageRecoveryHandler);
+            recoverQueueEntries(transactionLogRecoveryHandler);
         }
-        if(_tlogRecoveryHandler != null)
-        {
-            recoverQueueEntries(_tlogRecoveryHandler);
-        }
-
-        _stateManager.attainState(State.ACTIVE);
     }
 
     @Override
     public org.apache.qpid.server.store.Transaction newTransaction() throws StoreException
     {
-        return new BDBTransaction();
-    }
-
-    private void configure(VirtualHost virtualHost, boolean isMessageStore) throws StoreException
-    {
-        Object overfullAttr = virtualHost.getAttribute(MessageStoreConstants.OVERFULL_SIZE_ATTRIBUTE);
-        Object underfullAttr = virtualHost.getAttribute(MessageStoreConstants.UNDERFULL_SIZE_ATTRIBUTE);
-
-        _persistentSizeHighThreshold = overfullAttr == null ? -1l :
-                                       overfullAttr instanceof Number ? ((Number) overfullAttr).longValue() : Long.parseLong(overfullAttr.toString());
-        _persistentSizeLowThreshold = underfullAttr == null ? _persistentSizeHighThreshold :
-                                       underfullAttr instanceof Number ? ((Number) underfullAttr).longValue() : Long.parseLong(underfullAttr.toString());
-
+        checkMessageStoreOpen();
 
-        if(_persistentSizeLowThreshold > _persistentSizeHighThreshold || _persistentSizeLowThreshold < 0l)
-        {
-            _persistentSizeLowThreshold = _persistentSizeHighThreshold;
-        }
-
-        _environmentFacade = _environmentFacadeFactory.createEnvironmentFacade(virtualHost, isMessageStore);
-
-        _committer = _environmentFacade.createCommitter(virtualHost.getName());
-        _committer.start();
+        return new BDBTransaction();
     }
 
     @Override
@@ -283,33 +255,47 @@ public class BDBMessageStore implements 
         return _environmentFacade;
     }
 
-    /**
-     * Called to close and cleanup any resources used by the message store.
-     *
-     * @throws Exception If the close fails.
-     */
     @Override
-    public void close() throws StoreException
+    public void closeMessageStore() throws StoreException
     {
-        if (_closed.compareAndSet(false, true))
+        if (_messageStoreOpen.compareAndSet(true, false))
         {
-            _stateManager.attainState(State.CLOSING);
             try
             {
-                try
+                if (_committer != null)
                 {
                     _committer.stop();
                 }
-                finally
+            }
+            finally
+            {
+                if (!_configurationStoreOpen.get())
                 {
                     closeEnvironment();
                 }
             }
-            catch(DatabaseException e)
+        }
+    }
+
+    @Override
+    public void closeConfigurationStore() throws StoreException
+    {
+        if (_configurationStoreOpen.compareAndSet(true, false))
+        {
+            try
             {
-                throw new StoreException("Exception occured on message store close", e);
+                if (_committer != null)
+                {
+                    _committer.stop();
+                }
+            }
+            finally
+            {
+                if (!_messageStoreOpen.get())
+                {
+                    closeEnvironment();
+                }
             }
-            _stateManager.attainState(State.CLOSED);
         }
     }
 
@@ -751,27 +737,25 @@ public class BDBMessageStore implements 
     @Override
     public void create(ConfiguredObjectRecord configuredObject) throws StoreException
     {
-        if (_stateManager.isInState(State.ACTIVE))
+        checkConfigurationStoreOpen();
+        com.sleepycat.je.Transaction txn = null;
+        try
         {
-            com.sleepycat.je.Transaction txn = null;
-            try
-            {
-                txn = _environmentFacade.getEnvironment().beginTransaction(null, null);
-                storeConfiguredObjectEntry(txn, configuredObject);
-                txn.commit();
-                txn = null;
-            }
-            catch (DatabaseException e)
-            {
-                throw _environmentFacade.handleDatabaseException("Error creating configured object " + configuredObject
-                        + " in database: " + e.getMessage(), e);
-            }
-            finally
+            txn = _environmentFacade.getEnvironment().beginTransaction(null, null);
+            storeConfiguredObjectEntry(txn, configuredObject);
+            txn.commit();
+            txn = null;
+        }
+        catch (DatabaseException e)
+        {
+            throw _environmentFacade.handleDatabaseException("Error creating configured object " + configuredObject
+                    + " in database: " + e.getMessage(), e);
+        }
+        finally
+        {
+            if (txn != null)
             {
-                if (txn != null)
-                {
-                    abortTransactionIgnoringException("Error creating configured object", txn);
-                }
+                abortTransactionIgnoringException("Error creating configured object", txn);
             }
         }
     }
@@ -779,11 +763,13 @@ public class BDBMessageStore implements 
     @Override
     public UUID[] remove(final ConfiguredObjectRecord... objects) throws StoreException
     {
+        checkConfigurationStoreOpen();
+
         com.sleepycat.je.Transaction txn = null;
         try
         {
             txn = _environmentFacade.getEnvironment().beginTransaction(null, null);
-            
+
             Collection<UUID> removed = new ArrayList<UUID>(objects.length);
             for(ConfiguredObjectRecord record : objects)
             {
@@ -792,7 +778,7 @@ public class BDBMessageStore implements 
                     removed.add(record.getId());
                 }
             }
-            
+
             txn.commit();
             txn = null;
             return removed.toArray(new UUID[removed.size()]);
@@ -814,6 +800,8 @@ public class BDBMessageStore implements 
     @Override
     public void update(boolean createIfNecessary, ConfiguredObjectRecord... records) throws StoreException
     {
+        checkConfigurationStoreOpen();
+
         com.sleepycat.je.Transaction txn = null;
         try
         {
@@ -885,7 +873,7 @@ public class BDBMessageStore implements 
      *
      * @throws StoreException If the operation fails for any reason.
      */
-    public void enqueueMessage(final com.sleepycat.je.Transaction tx, final TransactionLogResource queue,
+    private void enqueueMessage(final com.sleepycat.je.Transaction tx, final TransactionLogResource queue,
                                long messageId) throws StoreException
     {
 
@@ -924,7 +912,7 @@ public class BDBMessageStore implements 
      *
      * @throws StoreException If the operation fails for any reason, or if the specified message does not exist.
      */
-    public void dequeueMessage(final com.sleepycat.je.Transaction tx, final TransactionLogResource queue,
+    private void dequeueMessage(final com.sleepycat.je.Transaction tx, final TransactionLogResource queue,
                                long messageId) throws StoreException
     {
 
@@ -1341,38 +1329,35 @@ public class BDBMessageStore implements 
 
     private void storeConfiguredObjectEntry(final Transaction txn, ConfiguredObjectRecord configuredObject) throws StoreException
     {
-        if (_stateManager.isInState(State.ACTIVE))
+        if (LOGGER.isDebugEnabled())
         {
-            if (LOGGER.isDebugEnabled())
-            {
-                LOGGER.debug("Storing configured object: " + configuredObject);
-            }
-            DatabaseEntry key = new DatabaseEntry();
-            UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
-            uuidBinding.objectToEntry(configuredObject.getId(), key);
+            LOGGER.debug("Storing configured object record: " + configuredObject);
+        }
+        DatabaseEntry key = new DatabaseEntry();
+        UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
+        uuidBinding.objectToEntry(configuredObject.getId(), key);
 
-            DatabaseEntry value = new DatabaseEntry();
-            ConfiguredObjectBinding queueBinding = ConfiguredObjectBinding.getInstance();
+        DatabaseEntry value = new DatabaseEntry();
+        ConfiguredObjectBinding queueBinding = ConfiguredObjectBinding.getInstance();
 
-            queueBinding.objectToEntry(configuredObject, value);
-            try
-            {
-                OperationStatus status = getConfiguredObjectsDb().put(txn, key, value);
-                if (status != OperationStatus.SUCCESS)
-                {
-                    throw new StoreException("Error writing configured object " + configuredObject + " to database: "
-                            + status);
-                }
-                writeHierarchyRecords(txn, configuredObject);               
-            }
-            catch (DatabaseException e)
+        queueBinding.objectToEntry(configuredObject, value);
+        try
+        {
+            OperationStatus status = getConfiguredObjectsDb().put(txn, key, value);
+            if (status != OperationStatus.SUCCESS)
             {
-                throw _environmentFacade.handleDatabaseException("Error writing configured object " + configuredObject
-                        + " to database: " + e.getMessage(), e);
+                throw new StoreException("Error writing configured object " + configuredObject + " to database: "
+                        + status);
             }
+            writeHierarchyRecords(txn, configuredObject);
+        }
+        catch (DatabaseException e)
+        {
+            throw _environmentFacade.handleDatabaseException("Error writing configured object " + configuredObject
+                    + " to database: " + e.getMessage(), e);
         }
     }
-    
+
     private void writeHierarchyRecords(final Transaction txn, final ConfiguredObjectRecord configuredObject)
     {
         OperationStatus status;
@@ -1398,7 +1383,7 @@ public class BDBMessageStore implements 
     {
         UUID id = record.getId();
         Map<String, ConfiguredObjectRecord> parents = record.getParents();
- 
+
         if (LOGGER.isDebugEnabled())
         {
             LOGGER.debug("Removing configured object: " + id);
@@ -1449,11 +1434,14 @@ public class BDBMessageStore implements 
             _metaDataRef = new SoftReference<StorableMessageMetaData>(metaData);
         }
 
+        @Override
         public StorableMessageMetaData getMetaData()
         {
             StorableMessageMetaData metaData = _metaDataRef.get();
             if(metaData == null)
             {
+                checkMessageStoreOpen();
+
                 metaData = BDBMessageStore.this.getMessageMetaData(_messageId);
                 _metaDataRef = new SoftReference<StorableMessageMetaData>(metaData);
             }
@@ -1461,11 +1449,13 @@ public class BDBMessageStore implements 
             return metaData;
         }
 
+        @Override
         public long getMessageNumber()
         {
             return _messageId;
         }
 
+        @Override
         public void addContent(int offsetInMessage, java.nio.ByteBuffer src)
         {
             src = src.slice();
@@ -1488,6 +1478,7 @@ public class BDBMessageStore implements 
 
         }
 
+        @Override
         public int getContent(int offsetInMessage, java.nio.ByteBuffer dst)
         {
             byte[] data = _dataRef == null ? null : _dataRef.get();
@@ -1499,10 +1490,13 @@ public class BDBMessageStore implements 
             }
             else
             {
+                checkMessageStoreOpen();
+
                 return BDBMessageStore.this.getContent(_messageId, offsetInMessage, dst);
             }
         }
 
+        @Override
         public ByteBuffer getContent(int offsetInMessage, int size)
         {
             byte[] data = _dataRef == null ? null : _dataRef.get();
@@ -1539,10 +1533,13 @@ public class BDBMessageStore implements 
             }
         }
 
+        @Override
         public synchronized StoreFuture flushToStore()
         {
             if(!stored())
             {
+                checkMessageStoreOpen();
+
                 com.sleepycat.je.Transaction txn;
                 try
                 {
@@ -1562,8 +1559,11 @@ public class BDBMessageStore implements 
             return StoreFuture.IMMEDIATE_FUTURE;
         }
 
+        @Override
         public void remove()
         {
+            checkMessageStoreOpen();
+
             int delta = getMetaData().getContentSize();
             BDBMessageStore.this.removeMessage(_messageId, false);
             storedSizeChangeOccured(-delta);
@@ -1592,8 +1592,11 @@ public class BDBMessageStore implements 
             }
         }
 
+        @Override
         public void enqueueMessage(TransactionLogResource queue, EnqueueableMessage message) throws StoreException
         {
+            checkMessageStoreOpen();
+
             if(message.getStoredMessage() instanceof StoredBDBMessage)
             {
                 final StoredBDBMessage storedMessage = (StoredBDBMessage) message.getStoredMessage();
@@ -1604,36 +1607,54 @@ public class BDBMessageStore implements 
             BDBMessageStore.this.enqueueMessage(_txn, queue, message.getMessageNumber());
         }
 
+        @Override
         public void dequeueMessage(TransactionLogResource queue, EnqueueableMessage message) throws StoreException
         {
+            checkMessageStoreOpen();
+
             BDBMessageStore.this.dequeueMessage(_txn, queue, message.getMessageNumber());
         }
 
+        @Override
         public void commitTran() throws StoreException
         {
+            checkMessageStoreOpen();
+
             BDBMessageStore.this.commitTranImpl(_txn, true);
             BDBMessageStore.this.storedSizeChangeOccured(_storeSizeIncrease);
         }
 
+        @Override
         public StoreFuture commitTranAsync() throws StoreException
         {
+            checkMessageStoreOpen();
+
             BDBMessageStore.this.storedSizeChangeOccured(_storeSizeIncrease);
             return BDBMessageStore.this.commitTranImpl(_txn, false);
         }
 
+        @Override
         public void abortTran() throws StoreException
         {
+            checkMessageStoreOpen();
+
             BDBMessageStore.this.abortTran(_txn);
         }
 
+        @Override
         public void removeXid(long format, byte[] globalId, byte[] branchId) throws StoreException
         {
+            checkMessageStoreOpen();
+
             BDBMessageStore.this.removeXid(_txn, format, globalId, branchId);
         }
 
+        @Override
         public void recordXid(long format, byte[] globalId, byte[] branchId, Record[] enqueues,
                               Record[] dequeues) throws StoreException
         {
+            checkMessageStoreOpen();
+
             BDBMessageStore.this.recordXid(_txn, format, globalId, branchId, enqueues, dequeues);
         }
     }
@@ -1697,6 +1718,22 @@ public class BDBMessageStore implements 
         }
     }
 
+    private void checkConfigurationStoreOpen()
+    {
+        if (!_configurationStoreOpen.get())
+        {
+            throw new IllegalStateException("Configuration store is not open");
+        }
+    }
+
+    private void checkMessageStoreOpen()
+    {
+        if (!_messageStoreOpen.get())
+        {
+            throw new IllegalStateException("Message store is not open");
+        }
+    }
+
     private void reduceSizeOnDisk()
     {
         _environmentFacade.getEnvironment().getConfig().setConfigParam(EnvironmentConfig.ENV_RUN_CLEANER, "false");
@@ -1796,4 +1833,72 @@ public class BDBMessageStore implements 
         return _environmentFacade.getOpenDatabase(XID_DB_NAME);
     }
 
+    class UpgradeTask implements EnvironmentFacadeTask
+    {
+
+        private ConfiguredObject<?> _parent;
+
+        public UpgradeTask(ConfiguredObject<?> parent)
+        {
+            _parent = parent;
+        }
+
+        @Override
+        public void execute(EnvironmentFacade facade)
+        {
+            try
+            {
+                new Upgrader(facade.getEnvironment(), _parent).upgradeIfNecessary();
+            }
+            catch(DatabaseException e)
+            {
+                throw facade.handleDatabaseException("Cannot upgrade store", e);
+            }
+        }
+    }
+
+    class OpenDatabasesTask implements EnvironmentFacadeTask
+    {
+        private String[] _names;
+
+        public OpenDatabasesTask(String[] names)
+        {
+            _names = names;
+        }
+
+        @Override
+        public void execute(EnvironmentFacade facade)
+        {
+            try
+            {
+                DatabaseConfig dbConfig = new DatabaseConfig();
+                dbConfig.setTransactional(true);
+                dbConfig.setAllowCreate(true);
+                facade.openDatabases(dbConfig, _names);
+            }
+            catch(DatabaseException e)
+            {
+                throw facade.handleDatabaseException("Cannot open databases", e);
+            }
+        }
+
+    }
+
+    class DiskSpaceTask implements EnvironmentFacadeTask
+    {
+
+        @Override
+        public void execute(EnvironmentFacade facade)
+        {
+            try
+            {
+                _totalStoreSize = facade.getEnvironment().getStats(null).getTotalLogSize();
+            }
+            catch(DatabaseException e)
+            {
+                throw facade.handleDatabaseException("Cannot evaluate disk store size", e);
+            }
+        }
+
+    }
 }

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreFactory.java Thu Apr  3 19:58:53 2014
@@ -20,12 +20,8 @@
  */
 package org.apache.qpid.server.store.berkeleydb;
 
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.configuration.Configuration;
 import org.apache.qpid.server.model.VirtualHost;
 import org.apache.qpid.server.plugin.DurableConfigurationStoreFactory;
 import org.apache.qpid.server.plugin.MessageStoreFactory;
@@ -54,53 +50,29 @@ public class BDBMessageStoreFactory impl
     }
 
     @Override
-    public Map<String, Object> convertStoreConfiguration(Configuration storeConfiguration)
-    {
-        final List<Object> argumentNames = storeConfiguration.getList("envConfig.name");
-        final List<Object> argumentValues = storeConfiguration.getList("envConfig.value");
-        final int initialSize = argumentNames.size();
-
-        final Map<String,String> attributes = new HashMap<String,String>(initialSize);
-
-        for (int i = 0; i < argumentNames.size(); i++)
-        {
-            final String argName = argumentNames.get(i).toString();
-            final String argValue = argumentValues.get(i).toString();
-
-            attributes.put(argName, argValue);
-        }
-
-        if(initialSize != 0)
-        {
-            return Collections.singletonMap(BDBMessageStore.ENVIRONMENT_CONFIGURATION, (Object)attributes);
-        }
-        else
-        {
-            return Collections.emptyMap();
-        }
-
-
-    }
-
-    @Override
     public void validateAttributes(Map<String, Object> attributes)
     {
-        if(getType().equals(attributes.get(VirtualHost.STORE_TYPE)))
+        @SuppressWarnings("unchecked")
+        Map<String, Object> messageStoreSettings = (Map<String, Object>) attributes.get(VirtualHost.MESSAGE_STORE_SETTINGS);
+        if(messageStoreSettings != null && getType().equals(messageStoreSettings.get(MessageStore.STORE_TYPE)))
         {
-            Object storePath = attributes.get(VirtualHost.STORE_PATH);
+            Object storePath = messageStoreSettings.get(MessageStore.STORE_PATH);
             if(!(storePath instanceof String))
             {
-                throw new IllegalArgumentException("Attribute '"+ VirtualHost.STORE_PATH
+                throw new IllegalArgumentException("Setting '"+ MessageStore.STORE_PATH
                                                                +"' is required and must be of type String.");
 
             }
         }
-        if(getType().equals(attributes.get(VirtualHost.CONFIG_STORE_TYPE)))
+
+        @SuppressWarnings("unchecked")
+        Map<String, Object> configurationStoreSettings = (Map<String, Object>) attributes.get(VirtualHost.CONFIGURATION_STORE_SETTINGS);
+        if(configurationStoreSettings != null && getType().equals(configurationStoreSettings.get(DurableConfigurationStore.STORE_TYPE)))
         {
-            Object storePath = attributes.get(VirtualHost.CONFIG_STORE_PATH);
+            Object storePath = configurationStoreSettings.get(DurableConfigurationStore.STORE_PATH);
             if(!(storePath instanceof String))
             {
-                throw new IllegalArgumentException("Attribute '"+ VirtualHost.CONFIG_STORE_PATH
+                throw new IllegalArgumentException("Setting '"+ DurableConfigurationStore.STORE_PATH
                                                                +"' is required and must be of type String.");
 
             }

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/EnvironmentFacadeFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/EnvironmentFacadeFactory.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/EnvironmentFacadeFactory.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/EnvironmentFacadeFactory.java Thu Apr  3 19:58:53 2014
@@ -20,13 +20,18 @@
  */
 package org.apache.qpid.server.store.berkeleydb;
 
-import org.apache.qpid.server.model.VirtualHost;
+import java.util.Map;
 
 public interface EnvironmentFacadeFactory
 {
+    public static final String ENVIRONMENT_CONFIGURATION = "bdbEnvironmentConfig";
 
-    EnvironmentFacade createEnvironmentFacade(VirtualHost virtualHost, boolean isMessageStore);
+    EnvironmentFacade createEnvironmentFacade(Map<String, Object> storeSettings, EnvironmentFacadeTask... initialisationTasks);
 
     String getType();
 
+    public static interface EnvironmentFacadeTask
+    {
+        void execute(EnvironmentFacade facade);
+    }
 }

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacade.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacade.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacade.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacade.java Thu Apr  3 19:58:53 2014
@@ -25,6 +25,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
+import org.apache.qpid.server.store.berkeleydb.EnvironmentFacadeFactory.EnvironmentFacadeTask;
 
 import com.sleepycat.je.Database;
 import com.sleepycat.je.DatabaseConfig;
@@ -42,7 +43,7 @@ public class StandardEnvironmentFacade i
 
     private Environment _environment;
 
-    public StandardEnvironmentFacade(String storePath, Map<String, String> attributes)
+    public StandardEnvironmentFacade(String storePath, Map<String, String> attributes, EnvironmentFacadeTask[] initialisationTasks)
     {
         _storePath = storePath;
 
@@ -74,6 +75,13 @@ public class StandardEnvironmentFacade i
         envConfig.setExceptionListener(new LoggingAsyncExceptionListener());
 
         _environment = new Environment(environmentPath, envConfig);
+        if (initialisationTasks != null)
+        {
+            for (EnvironmentFacadeTask task : initialisationTasks)
+            {
+                task.execute(this);
+            }
+        }
     }
 
     @Override

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeFactory.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeFactory.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeFactory.java Thu Apr  3 19:58:53 2014
@@ -20,51 +20,28 @@
  */
 package org.apache.qpid.server.store.berkeleydb;
 
-import java.io.File;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.qpid.server.configuration.BrokerProperties;
-import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.store.MessageStore;
 
 public class StandardEnvironmentFacadeFactory implements EnvironmentFacadeFactory
 {
 
     @SuppressWarnings("unchecked")
     @Override
-    public EnvironmentFacade createEnvironmentFacade(VirtualHost virtualHost, boolean isMessageStore)
+    public EnvironmentFacade createEnvironmentFacade(Map<String, Object> messageStoreSettings, EnvironmentFacadeTask... initialisationTasks)
     {
         Map<String, String> envConfigMap = new HashMap<String, String>();
         envConfigMap.putAll(EnvironmentFacade.ENVCONFIG_DEFAULTS);
 
-        Object environmentConfigurationAttributes = virtualHost.getAttribute(BDBMessageStore.ENVIRONMENT_CONFIGURATION);
+        Object environmentConfigurationAttributes = messageStoreSettings.get(ENVIRONMENT_CONFIGURATION);
         if (environmentConfigurationAttributes instanceof Map)
         {
             envConfigMap.putAll((Map<String, String>) environmentConfigurationAttributes);
         }
-
-        String name = virtualHost.getName();
-        final String defaultPath = System.getProperty(BrokerProperties.PROPERTY_QPID_WORK) + File.separator + "bdbstore" + File.separator + name;
-
-        String storeLocation;
-        if(isMessageStore)
-        {
-            storeLocation = (String) virtualHost.getAttribute(VirtualHost.STORE_PATH);
-            if(storeLocation == null)
-            {
-                storeLocation = defaultPath;
-            }
-        }
-        else // we are acting only as the durable config store
-        {
-            storeLocation = (String) virtualHost.getAttribute(VirtualHost.CONFIG_STORE_PATH);
-            if(storeLocation == null)
-            {
-                storeLocation = defaultPath;
-            }
-        }
-
-        return new StandardEnvironmentFacade(storeLocation, envConfigMap);
+        String storeLocation = (String) messageStoreSettings.get(MessageStore.STORE_PATH);
+        return new StandardEnvironmentFacade(storeLocation, envConfigMap, initialisationTasks);
     }
 
     @Override

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java Thu Apr  3 19:58:53 2014
@@ -40,12 +40,14 @@ import java.util.concurrent.Future;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.log4j.Logger;
 import org.apache.qpid.server.store.berkeleydb.CoalescingCommiter;
 import org.apache.qpid.server.store.berkeleydb.Committer;
 import org.apache.qpid.server.store.berkeleydb.EnvironmentFacade;
+import org.apache.qpid.server.store.berkeleydb.EnvironmentFacadeFactory.EnvironmentFacadeTask;
 import org.apache.qpid.server.store.berkeleydb.LoggingAsyncExceptionListener;
 import org.apache.qpid.server.util.DaemonThreadFactory;
 
@@ -110,7 +112,7 @@ public class ReplicatedEnvironmentFacade
          */
         put(ReplicationConfig.ENV_SETUP_TIMEOUT, "15 min");
         /**
-         * Parameter changed from default (off) to allow the Environment to start in the 
+         * Parameter changed from default (off) to allow the Environment to start in the
          * UNKNOWN state when the majority is not available.
          */
         put(ReplicationConfig.ENV_UNKNOWN_STATE_TIMEOUT, "5 s");
@@ -148,7 +150,10 @@ public class ReplicatedEnvironmentFacade
     private volatile long _joinTime;
     private volatile ReplicatedEnvironment.State _lastKnownEnvironmentState;
 
-    public ReplicatedEnvironmentFacade(ReplicatedEnvironmentConfiguration configuration)
+    private AtomicBoolean _initialised;
+    private EnvironmentFacadeTask[] _initialisationTasks;
+
+    public ReplicatedEnvironmentFacade(ReplicatedEnvironmentConfiguration configuration, EnvironmentFacadeTask[] initialisationTasks)
     {
         _environmentDirectory = new File(configuration.getStorePath());
         if (!_environmentDirectory.exists())
@@ -160,6 +165,8 @@ public class ReplicatedEnvironmentFacade
             }
         }
 
+        _initialised = new AtomicBoolean();
+        _initialisationTasks = initialisationTasks;
         _configuration = configuration;
 
         _durability = Durability.parse(_configuration.getDurability());
@@ -393,9 +400,10 @@ public class ReplicatedEnvironmentFacade
                     LOGGER.info("The environment facade is in open state for node " + _prettyGroupNodeName);
                     _joinTime = System.currentTimeMillis();
                 }
+
                 if (state == ReplicatedEnvironment.State.MASTER)
                 {
-                    reopenDatabases();
+                    onMasterStateChange();
                 }
             }
 
@@ -413,6 +421,22 @@ public class ReplicatedEnvironmentFacade
         _lastKnownEnvironmentState = state;
     }
 
+    private void onMasterStateChange()
+    {
+        reopenDatabases();
+
+        if (_initialised.compareAndSet(false, true))
+        {
+            if (_initialisationTasks != null)
+            {
+                for (EnvironmentFacadeTask task : _initialisationTasks)
+                {
+                    task.execute(ReplicatedEnvironmentFacade.this);
+                }
+            }
+        }
+    }
+
     private void reopenDatabases()
     {
         if (_state.get() == State.OPEN)
@@ -992,7 +1016,7 @@ public class ReplicatedEnvironmentFacade
                             {
                                 nodeState = ReplicatedEnvironment.State.UNKNOWN;
                             }
-                            
+
                             currentGroupState.put(node.getName(), nodeState);
                             return null;
                         }
@@ -1079,5 +1103,4 @@ public class ReplicatedEnvironmentFacade
         }
 
     }
-
 }

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeFactory.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeFactory.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeFactory.java Thu Apr  3 19:58:53 2014
@@ -20,59 +20,66 @@
  */
 package org.apache.qpid.server.store.berkeleydb.replication;
 
-import java.util.Map;
-
-import org.apache.qpid.server.model.VirtualHost;
-import org.apache.qpid.server.store.berkeleydb.EnvironmentFacade;
-import org.apache.qpid.server.store.berkeleydb.EnvironmentFacadeFactory;
-
 import com.sleepycat.je.Durability;
 import com.sleepycat.je.Durability.ReplicaAckPolicy;
 import com.sleepycat.je.Durability.SyncPolicy;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.berkeleydb.EnvironmentFacade;
+import org.apache.qpid.server.store.berkeleydb.EnvironmentFacadeFactory;
+
+import java.util.Map;
 
 public class ReplicatedEnvironmentFacadeFactory implements EnvironmentFacadeFactory
 {
-    
+    public static final String DURABILITY = "haDurability";
+    public static final String GROUP_NAME = "haGroupName";
+    public static final String HELPER_ADDRESS = "haHelperAddress";
+    public static final String NODE_ADDRESS = "haNodeAddress";
+    public static final String NODE_NAME = "haNodeName";
+    public static final String REPLICATION_CONFIG = "haReplicationConfig";
+    public static final String COALESCING_SYNC = "haCoalescingSync";
+    public static final String DESIGNATED_PRIMARY = "haDesignatedPrimary";
+
     private static final int DEFAULT_NODE_PRIORITY = 1;
     private static final Durability DEFAULT_DURABILITY = new Durability(SyncPolicy.NO_SYNC, SyncPolicy.NO_SYNC,
             ReplicaAckPolicy.SIMPLE_MAJORITY);
     private static final boolean DEFAULT_COALESCING_SYNC = true;
 
-    
-
     @Override
-    public EnvironmentFacade createEnvironmentFacade(final VirtualHost virtualHost, boolean isMessageStore)
+    public EnvironmentFacade createEnvironmentFacade(final Map<String, Object> messageStoreSettings, EnvironmentFacadeTask... initialisationTasks)
     {
         ReplicatedEnvironmentConfiguration configuration = new ReplicatedEnvironmentConfiguration()
         {
             @Override
             public boolean isDesignatedPrimary()
             {
-                return convertBoolean(virtualHost.getAttribute("haDesignatedPrimary"), false);
+                return convertBoolean(messageStoreSettings.get(DESIGNATED_PRIMARY), false);
             }
 
             @Override
             public boolean isCoalescingSync()
             {
-                return convertBoolean(virtualHost.getAttribute("haCoalescingSync"), DEFAULT_COALESCING_SYNC);
+                return convertBoolean(messageStoreSettings.get(COALESCING_SYNC), DEFAULT_COALESCING_SYNC);
             }
 
             @Override
             public String getStorePath()
             {
-                return (String) virtualHost.getAttribute(VirtualHost.STORE_PATH);
+                return (String) messageStoreSettings.get(MessageStore.STORE_PATH);
             }
 
+            @SuppressWarnings("unchecked")
             @Override
             public Map<String, String> getParameters()
             {
-                return (Map<String, String>) virtualHost.getAttribute("bdbEnvironmentConfig");
+                return (Map<String, String>) messageStoreSettings.get(EnvironmentFacadeFactory.ENVIRONMENT_CONFIGURATION);
             }
 
+            @SuppressWarnings("unchecked")
             @Override
             public Map<String, String> getReplicationParameters()
             {
-                return (Map<String, String>) virtualHost.getAttribute("haReplicationConfig");
+                return (Map<String, String>) messageStoreSettings.get(REPLICATION_CONFIG);
             }
 
             @Override
@@ -87,39 +94,38 @@ public class ReplicatedEnvironmentFacade
                 return DEFAULT_NODE_PRIORITY;
             }
 
-
-
             @Override
             public String getName()
             {
-                return (String)virtualHost.getAttribute("haNodeName");
+                return (String)messageStoreSettings.get(NODE_NAME);
             }
 
             @Override
             public String getHostPort()
             {
-                return (String)virtualHost.getAttribute("haNodeAddress");
+                return (String)messageStoreSettings.get(NODE_ADDRESS);
             }
 
             @Override
             public String getHelperHostPort()
             {
-                return (String)virtualHost.getAttribute("haHelperAddress");
+                return (String)messageStoreSettings.get(HELPER_ADDRESS);
             }
 
             @Override
             public String getGroupName()
             {
-                return (String)virtualHost.getAttribute("haGroupName");
+                return (String)messageStoreSettings.get(GROUP_NAME);
             }
 
             @Override
             public String getDurability()
             {
-                return virtualHost.getAttribute("haDurability") == null ? DEFAULT_DURABILITY.toString() : (String)virtualHost.getAttribute("haDurability");
+                String durability = (String)messageStoreSettings.get(DURABILITY);
+                return durability == null ? DEFAULT_DURABILITY.toString() : durability;
             }
         };
-        return new ReplicatedEnvironmentFacade(configuration);
+        return new ReplicatedEnvironmentFacade(configuration, initialisationTasks);
 
     }
 

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/StoreUpgrade.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/StoreUpgrade.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/StoreUpgrade.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/StoreUpgrade.java Thu Apr  3 19:58:53 2014
@@ -21,9 +21,10 @@
 package org.apache.qpid.server.store.berkeleydb.upgrade;
 
 import com.sleepycat.je.Environment;
-import org.apache.qpid.server.model.VirtualHost;
+
+import org.apache.qpid.server.model.ConfiguredObject;
 
 public interface StoreUpgrade
 {
-    void performUpgrade(Environment environment, UpgradeInteractionHandler handler, VirtualHost virtualHost);
+    void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent);
 }

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom4To5.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom4To5.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom4To5.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom4To5.java Thu Apr  3 19:58:53 2014
@@ -39,7 +39,7 @@ import org.apache.qpid.framing.AMQShortS
 import org.apache.qpid.framing.ContentHeaderBody;
 import org.apache.qpid.framing.FieldTable;
 import org.apache.qpid.framing.abstraction.MessagePublishInfo;
-import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.ConfiguredObject;
 import org.apache.qpid.server.protocol.v0_8.MessageMetaData;
 import org.apache.qpid.server.store.StoreException;
 import org.apache.qpid.server.store.StorableMessageMetaData;
@@ -75,7 +75,7 @@ public class UpgradeFrom4To5 extends Abs
 
     private static final Logger _logger = Logger.getLogger(UpgradeFrom4To5.class);
 
-    public void performUpgrade(final Environment environment, final UpgradeInteractionHandler handler, VirtualHost virtualHost)
+    public void performUpgrade(final Environment environment, final UpgradeInteractionHandler handler, ConfiguredObject<?> parent)
     {
         Transaction transaction = null;
         reportStarting(environment, 4);

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom5To6.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom5To6.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom5To6.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom5To6.java Thu Apr  3 19:58:53 2014
@@ -40,11 +40,11 @@ import org.apache.qpid.exchange.Exchange
 import org.apache.qpid.framing.AMQShortString;
 import org.apache.qpid.framing.FieldTable;
 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.UUIDGenerator;
-import org.apache.qpid.server.model.VirtualHost;
 import org.apache.qpid.server.queue.QueueArgumentsConverter;
 import org.apache.qpid.server.store.StoreException;
 import org.apache.qpid.server.store.berkeleydb.AMQShortStringEncoding;
@@ -119,11 +119,11 @@ public class UpgradeFrom5To6 extends Abs
      * Queue, Exchange, Bindings entries are stored now as configurable objects
      * in "CONFIGURED_OBJECTS" table.
      */
-    public void performUpgrade(final Environment environment, final UpgradeInteractionHandler handler, VirtualHost virtualHost)
+    public void performUpgrade(final Environment environment, final UpgradeInteractionHandler handler, ConfiguredObject<?> parent)
     {
         reportStarting(environment, 5);
         upgradeMessages(environment, handler);
-        upgradeConfiguredObjectsAndDependencies(environment, handler, virtualHost.getName());
+        upgradeConfiguredObjectsAndDependencies(environment, handler, parent.getName());
         renameDatabases(environment, null);
         reportFinished(environment, 6);
     }

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom6To7.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom6To7.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom6To7.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom6To7.java Thu Apr  3 19:58:53 2014
@@ -27,7 +27,8 @@ import com.sleepycat.je.DatabaseConfig;
 import com.sleepycat.je.DatabaseEntry;
 import com.sleepycat.je.Environment;
 import com.sleepycat.je.OperationStatus;
-import org.apache.qpid.server.model.VirtualHost;
+
+import org.apache.qpid.server.model.ConfiguredObject;
 import org.apache.qpid.server.store.StoreException;
 
 public class UpgradeFrom6To7 extends AbstractStoreUpgrade
@@ -36,7 +37,7 @@ public class UpgradeFrom6To7 extends Abs
     private static final int DEFAULT_CONFIG_VERSION = 0;
 
     @Override
-    public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, VirtualHost virtualHost)
+    public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent)
     {
         reportStarting(environment, 6);
         DatabaseConfig dbConfig = new DatabaseConfig();

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java Thu Apr  3 19:58:53 2014
@@ -26,7 +26,9 @@ import com.sleepycat.bind.tuple.TupleBin
 import com.sleepycat.bind.tuple.TupleInput;
 import com.sleepycat.bind.tuple.TupleOutput;
 import com.sleepycat.je.*;
-import org.apache.qpid.server.model.VirtualHost;
+
+import org.apache.qpid.server.model.ConfiguredObject;
+
 import org.apache.qpid.server.store.ConfiguredObjectRecord;
 import org.apache.qpid.server.store.StoreException;
 import org.apache.qpid.server.store.berkeleydb.BDBConfiguredObjectRecord;
@@ -46,7 +48,7 @@ public class UpgradeFrom7To8 extends Abs
 {
 
     @Override
-    public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, VirtualHost virtualHost)
+    public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent)
     {
         reportStarting(environment, 7);
 
@@ -78,7 +80,7 @@ public class UpgradeFrom7To8 extends Abs
 
                 if(!type.endsWith("Binding"))
                 {
-                    UUIDTupleBinding.getInstance().objectToEntry(virtualHost.getId(),value);
+                    UUIDTupleBinding.getInstance().objectToEntry(parent.getId(),value);
                     TupleOutput tupleOutput = new TupleOutput();
                     tupleOutput.writeLong(id.getMostSignificantBits());
                     tupleOutput.writeLong(id.getLeastSignificantBits());

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/Upgrader.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/Upgrader.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/Upgrader.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/Upgrader.java Thu Apr  3 19:58:53 2014
@@ -26,6 +26,7 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 
 import org.apache.log4j.Logger;
+import org.apache.qpid.server.model.ConfiguredObject;
 import org.apache.qpid.server.model.VirtualHost;
 import org.apache.qpid.server.store.StoreException;
 import org.apache.qpid.server.store.berkeleydb.BDBMessageStore;
@@ -46,12 +47,12 @@ public class Upgrader
     static final String VERSION_DB_NAME = "DB_VERSION";
 
     private Environment _environment;
-    private VirtualHost _virtualHost;
+    private ConfiguredObject<?> _parent;
 
-    public Upgrader(Environment environment, VirtualHost virtualHost)
+    public Upgrader(Environment environment, ConfiguredObject<?> parent)
     {
         _environment = environment;
-        _virtualHost = virtualHost;
+        _parent = parent;
     }
 
     public void upgradeIfNecessary()
@@ -159,7 +160,7 @@ public class Upgrader
                                                         + "UpgradeFrom"+fromVersion+"To"+toVersion);
             Constructor<StoreUpgrade> ctr = upgradeClass.getConstructor();
             StoreUpgrade upgrade = ctr.newInstance();
-            upgrade.performUpgrade(_environment, UpgradeInteractionHandler.DEFAULT_HANDLER, _virtualHost);
+            upgrade.performUpgrade(_environment, UpgradeInteractionHandler.DEFAULT_HANDLER, _parent);
         }
         catch (ClassNotFoundException e)
         {

Added: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory?rev=1584365&view=auto
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory (added)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory Thu Apr  3 19:58:53 2014
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+org.apache.qpid.server.store.berkeleydb.BDBHAVirtualHostAdapterFactory

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreConfigurationTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreConfigurationTest.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreConfigurationTest.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreConfigurationTest.java Thu Apr  3 19:58:53 2014
@@ -25,49 +25,9 @@ import org.apache.qpid.server.store.Dura
 
 public class BDBMessageStoreConfigurationTest extends AbstractDurableConfigurationStoreTestCase
 {
-    private BDBMessageStore _bdbMessageStore;
-
-    @Override
-    protected BDBMessageStore createMessageStore() throws Exception
-    {
-        createStoreIfNecessary();
-        return _bdbMessageStore;
-    }
-
-    @Override
-    protected void closeMessageStore() throws Exception
-    {
-        closeStoreIfNecessary();
-    }
-
     @Override
     protected DurableConfigurationStore createConfigStore() throws Exception
     {
-        createStoreIfNecessary();
-
-        return _bdbMessageStore;
-    }
-
-    @Override
-    protected void closeConfigStore() throws Exception
-    {
-        closeStoreIfNecessary();
-    }
-
-    private void createStoreIfNecessary()
-    {
-        if(_bdbMessageStore == null)
-        {
-            _bdbMessageStore = new BDBMessageStore();
-        }
-    }
-
-    private void closeStoreIfNecessary() throws Exception
-    {
-        if (_bdbMessageStore != null)
-        {
-            _bdbMessageStore.close();
-            _bdbMessageStore = null;
-        }
+        return new BDBMessageStore();
     }
 }

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java Thu Apr  3 19:58:53 2014
@@ -21,16 +21,13 @@
 package org.apache.qpid.server.store.berkeleydb;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
+
 import org.apache.log4j.Logger;
-import org.apache.qpid.server.model.VirtualHost;
 import org.apache.qpid.server.store.MessageStore;
-import org.apache.qpid.server.store.MessageStoreConstants;
 import org.apache.qpid.server.store.MessageStoreQuotaEventsTestBase;
 
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.when;
-
 public class BDBMessageStoreQuotaEventsTest extends MessageStoreQuotaEventsTestBase
 {
     private static final Logger _logger = Logger.getLogger(BDBMessageStoreQuotaEventsTest.class);
@@ -59,16 +56,19 @@ public class BDBMessageStoreQuotaEventsT
         return NUMBER_OF_MESSAGES_TO_OVERFILL_STORE;
     }
 
+
     @Override
-    protected void applyStoreSpecificConfiguration(VirtualHost virtualHost)
+    protected Map<String, Object>createStoreSettings(String storeLocation)
     {
-        _logger.debug("Applying store specific config. overfull-sze=" + OVERFULL_SIZE + ", underfull-size=" + UNDERFULL_SIZE);
+        _logger.debug("Applying store specific config. overfull-size=" + OVERFULL_SIZE + ", underfull-size=" + UNDERFULL_SIZE);
 
+        Map<String, Object> messageStoreSettings = new HashMap<String, Object>();
+        messageStoreSettings.put(MessageStore.STORE_PATH, storeLocation);
+        messageStoreSettings.put(MessageStore.OVERFULL_SIZE, OVERFULL_SIZE);
+        messageStoreSettings.put(MessageStore.UNDERFULL_SIZE, UNDERFULL_SIZE);
         Map<String,String> envMap = Collections.singletonMap("je.log.fileMax", MAX_BDB_LOG_SIZE);
-        when(virtualHost.getAttribute(eq("bdbEnvironmentConfig"))).thenReturn(envMap);
-        when(virtualHost.getAttribute(eq(MessageStoreConstants.OVERFULL_SIZE_ATTRIBUTE))).thenReturn(OVERFULL_SIZE);
-        when(virtualHost.getAttribute(eq(MessageStoreConstants.UNDERFULL_SIZE_ATTRIBUTE))).thenReturn(UNDERFULL_SIZE);
-
+        messageStoreSettings.put(EnvironmentFacadeFactory.ENVIRONMENT_CONFIGURATION, envMap);
+        return messageStoreSettings;
     }
 
     @Override

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeTest.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeTest.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeTest.java Thu Apr  3 19:58:53 2014
@@ -122,7 +122,7 @@ public class StandardEnvironmentFacadeTe
 
     EnvironmentFacade createEnvironmentFacade()
     {
-        return new StandardEnvironmentFacade(_storePath.getAbsolutePath(), Collections.<String, String>emptyMap());
+        return new StandardEnvironmentFacade(_storePath.getAbsolutePath(), Collections.<String, String>emptyMap(), null);
     }
 
 }

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java Thu Apr  3 19:58:53 2014
@@ -20,45 +20,41 @@
  */
 package org.apache.qpid.server.store.berkeleydb;
 
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-
-import org.apache.qpid.server.configuration.ConfigurationEntry;
+import com.sleepycat.je.rep.ReplicatedEnvironment;
+import com.sleepycat.je.rep.ReplicationConfig;
 import org.apache.qpid.server.configuration.ConfigurationEntryStore;
 import org.apache.qpid.server.configuration.RecovererProvider;
-import org.apache.qpid.server.configuration.startup.VirtualHostRecoverer;
 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.State;
 import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory;
 import org.apache.qpid.server.stats.StatisticsGatherer;
-import org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade;
+import org.apache.qpid.server.store.MessageStore;
+import org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacadeFactory;
 import org.apache.qpid.server.util.BrokerTestHelper;
-import org.apache.qpid.server.virtualhost.StandardVirtualHostFactory;
 import org.apache.qpid.test.utils.QpidTestCase;
-import org.apache.qpid.test.utils.TestFileUtils;
 import org.apache.qpid.util.FileUtils;
 
-import com.sleepycat.je.EnvironmentConfig;
-import com.sleepycat.je.rep.ReplicatedEnvironment;
-import com.sleepycat.je.rep.ReplicationConfig;
+import java.io.File;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public class VirtualHostTest extends QpidTestCase
 {
 
-    private Broker _broker;
+    private Broker<?> _broker;
     private StatisticsGatherer _statisticsGatherer;
     private RecovererProvider _recovererProvider;
-    private File _configFile;
     private File _bdbStorePath;
-    private VirtualHost _host;
+    private VirtualHost<?> _host;
     private ConfigurationEntryStore _store;
 
     @Override
@@ -72,7 +68,6 @@ public class VirtualHostTest extends Qpi
         when(taslExecutor.isTaskExecutorThread()).thenReturn(true);
         when(_broker.getTaskExecutor()).thenReturn(taslExecutor);
 
-
         _statisticsGatherer = mock(StatisticsGatherer.class);
 
         _bdbStorePath = new File(TMP_FOLDER, getTestName() + "." + System.currentTimeMillis());
@@ -91,10 +86,6 @@ public class VirtualHostTest extends Qpi
         }
         finally
         {
-            if (_configFile != null)
-            {
-                _configFile.delete();
-            }
             if (_bdbStorePath != null)
             {
                 FileUtils.delete(_bdbStorePath, true);
@@ -103,106 +94,63 @@ public class VirtualHostTest extends Qpi
         }
     }
 
-
-    public void testCreateBdbVirtualHostFromConfigurationFile()
-    {
-        String hostName = getName();
-        long logFileMax = 2000000;
-        _host = createHostFromConfiguration(hostName, logFileMax);
-        _host.setDesiredState(State.INITIALISING, State.ACTIVE);
-        assertEquals("Unexpected host name", hostName, _host.getName());
-        assertEquals("Unexpected host type", StandardVirtualHostFactory.TYPE, _host.getType());
-        assertEquals("Unexpected store type", new BDBMessageStoreFactory().getType(), _host.getAttribute(VirtualHost.STORE_TYPE));
-        assertEquals("Unexpected store path", _bdbStorePath.getAbsolutePath(), _host.getAttribute(VirtualHost.STORE_PATH));
-
-        BDBMessageStore messageStore = (BDBMessageStore) _host.getMessageStore();
-        EnvironmentConfig envConfig = messageStore.getEnvironmentFacade().getEnvironment().getConfig();
-        assertEquals("Unexpected JE log file max", String.valueOf(logFileMax), envConfig.getConfigParam(EnvironmentConfig.LOG_FILE_MAX));
-
-    }
-
-    public void testCreateBdbHaVirtualHostFromConfigurationFile()
+    public void testCreateBdbHaVirtualHostFromConfigurationEntry()
     {
-        String hostName = getName();
-
         String repStreamTimeout = "2 h";
         String nodeName = "node";
         String groupName = "group";
         String nodeHostPort = "localhost:" + findFreePort();
         String helperHostPort = nodeHostPort;
         String durability = "NO_SYNC,SYNC,NONE";
-        _host = createHaHostFromConfiguration(hostName, groupName, nodeName, nodeHostPort, helperHostPort, durability, repStreamTimeout);
+        String virtualHostName = getName();
+
+        Map<String, Object> messageStoreSettings = new HashMap<String, Object>();
+        messageStoreSettings.put(ReplicatedEnvironmentFacadeFactory.NODE_NAME, nodeName);
+        messageStoreSettings.put(ReplicatedEnvironmentFacadeFactory.GROUP_NAME, groupName);
+        messageStoreSettings.put(ReplicatedEnvironmentFacadeFactory.NODE_ADDRESS, nodeHostPort);
+        messageStoreSettings.put(ReplicatedEnvironmentFacadeFactory.HELPER_ADDRESS, helperHostPort);
+        messageStoreSettings.put(ReplicatedEnvironmentFacadeFactory.DURABILITY, durability);
+
+        messageStoreSettings.put(MessageStore.STORE_PATH, _bdbStorePath.getAbsolutePath());
+        messageStoreSettings.put(ReplicatedEnvironmentFacadeFactory.REPLICATION_CONFIG,
+                Collections.singletonMap(ReplicationConfig.REP_STREAM_TIMEOUT, repStreamTimeout));
+
+        Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
+        virtualHostAttributes.put(VirtualHost.NAME, virtualHostName);
+        virtualHostAttributes.put(VirtualHost.TYPE, BDBHAVirtualHostFactory.TYPE);
+        virtualHostAttributes.put(VirtualHost.MESSAGE_STORE_SETTINGS, messageStoreSettings);
+
+        _host = createHost(virtualHostAttributes);
         _host.setDesiredState(State.INITIALISING, State.ACTIVE);
-        assertEquals("Unexpected host name", hostName, _host.getName());
+
+        assertEquals("Unexpected virtual host name", virtualHostName, _host.getName());
         assertEquals("Unexpected host type", BDBHAVirtualHostFactory.TYPE, _host.getType());
-        assertEquals("Unexpected store type", ReplicatedEnvironmentFacade.TYPE, _host.getAttribute(VirtualHost.STORE_TYPE));
-        assertEquals("Unexpected store path", _bdbStorePath.getAbsolutePath(), _host.getAttribute(VirtualHost.STORE_PATH));
+
+        assertEquals(messageStoreSettings, _host.getMessageStoreSettings());
 
         BDBMessageStore messageStore = (BDBMessageStore) _host.getMessageStore();
         ReplicatedEnvironment environment = (ReplicatedEnvironment) messageStore.getEnvironmentFacade().getEnvironment();
-        ReplicationConfig repConfig = environment.getRepConfig();
-        assertEquals("Unexpected JE replication groupName", groupName, repConfig.getConfigParam(ReplicationConfig.GROUP_NAME));
-        assertEquals("Unexpected JE replication nodeName", nodeName, repConfig.getConfigParam(ReplicationConfig.NODE_NAME));
-        assertEquals("Unexpected JE replication nodeHostPort", nodeHostPort, repConfig.getConfigParam(ReplicationConfig.NODE_HOST_PORT));
-        assertEquals("Unexpected JE replication nodeHostPort", helperHostPort, repConfig.getConfigParam(ReplicationConfig.HELPER_HOSTS));
-        assertEquals("Unexpected JE replication nodeHostPort", "false", repConfig.getConfigParam(ReplicationConfig.DESIGNATED_PRIMARY));
-        assertEquals("Unexpected JE replication stream timeout", repStreamTimeout, repConfig.getConfigParam(ReplicationConfig.REP_STREAM_TIMEOUT));
-    }
-
-    private VirtualHost createHost(Map<String, Object> attributes, Set<UUID> children)
-    {
-        ConfigurationEntry entry = new ConfigurationEntry(UUID.randomUUID(), VirtualHost.class.getSimpleName(), attributes,
-                children, _store);
-
-        return new VirtualHostRecoverer(_statisticsGatherer).create(_recovererProvider, entry, _broker);
-    }
+        ReplicationConfig replicationConfig = environment.getRepConfig();
 
-    private VirtualHost createHost(Map<String, Object> attributes)
-    {
-        return createHost(attributes, Collections.<UUID> emptySet());
-    }
-
-    private VirtualHost createHostFromConfiguration(String hostName, long logFileMax)
-    {
-        String content = "<virtualhosts><virtualhost><name>" + hostName + "</name><" + hostName + ">"
-                        + "<store><class>" + BDBMessageStore.class.getName() + "</class>"
-                        + "<environment-path>" + _bdbStorePath.getAbsolutePath() + "</environment-path>"
-                        + "<envConfig><name>" + EnvironmentConfig.LOG_FILE_MAX + "</name><value>" + logFileMax + "</value></envConfig>"
-                        + "</store>"
-                        + "</" + hostName + "></virtualhost></virtualhosts>";
-        Map<String, Object> attributes = writeConfigAndGenerateAttributes(content);
-        return createHost(attributes);
+        assertEquals(nodeName, environment.getNodeName());
+        assertEquals(groupName, environment.getGroup().getName());
+        assertEquals(nodeHostPort, replicationConfig.getNodeHostPort());
+        assertEquals(helperHostPort, replicationConfig.getHelperHosts());
+        assertEquals(durability, environment.getConfig().getDurability().toString());
+        assertEquals("Unexpected JE replication stream timeout", repStreamTimeout, replicationConfig.getConfigParam(ReplicationConfig.REP_STREAM_TIMEOUT));
     }
 
 
-    private VirtualHost createHaHostFromConfiguration(String hostName, String groupName, String nodeName, String nodeHostPort, String helperHostPort, String durability, String repStreamTimeout)
+    private VirtualHost<?> createHost(Map<String, Object> attributes)
     {
-        String content = "<virtualhosts><virtualhost><name>" + hostName + "</name><" + hostName + ">"
-                        + "<type>" + BDBHAVirtualHostFactory.TYPE + "</type>"
-                        + "<store><class>" + BDBMessageStore.class.getName() + "</class>"
-                        + "<environment-path>" + _bdbStorePath.getAbsolutePath() + "</environment-path>"
-                        + "<highAvailability>"
-                        + "<groupName>" + groupName + "</groupName>"
-                        + "<nodeName>" + nodeName + "</nodeName>"
-                        + "<nodeHostPort>" + nodeHostPort + "</nodeHostPort>"
-                        + "<helperHostPort>" + helperHostPort + "</helperHostPort>"
-                        + "<durability>" + durability.replaceAll(",", "\\\\,") + "</durability>"
-                        + "</highAvailability>"
-                        + "<repConfig><name>" + ReplicationConfig.REP_STREAM_TIMEOUT + "</name><value>" + repStreamTimeout + "</value></repConfig>"
-                        + "</store>"
-                        + "</" + hostName + "></virtualhost></virtualhosts>";
-        Map<String, Object> attributes = writeConfigAndGenerateAttributes(content);
-        return createHost(attributes);
+        ConfiguredObjectFactory factory = new ConfiguredObjectFactory();
+        ConfiguredObjectTypeFactory vhostFactory =
+                factory.getConfiguredObjectTypeFactory(VirtualHost.class, attributes);
+        attributes = new HashMap<String, Object>(attributes);
+        attributes.put(ConfiguredObject.ID, UUID.randomUUID());
+        return (VirtualHost<?>) vhostFactory.create(attributes,_broker);
     }
 
-    private Map<String, Object> writeConfigAndGenerateAttributes(String content)
-    {
-        _configFile = TestFileUtils.createTempFile(this, ".virtualhost.xml", content);
-        Map<String, Object> attributes = new HashMap<String, Object>();
-        attributes.put(VirtualHost.NAME, getName());
-        attributes.put(VirtualHost.CONFIG_PATH, _configFile.getAbsolutePath());
-        return attributes;
-    }
 }
 
-    
\ No newline at end of file
+    

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java Thu Apr  3 19:58:53 2014
@@ -31,8 +31,6 @@ import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.apache.qpid.server.configuration.updater.TaskExecutor;
-import org.apache.qpid.server.model.VirtualHost;
 import org.apache.qpid.server.store.berkeleydb.EnvironmentFacade;
 import org.apache.qpid.test.utils.QpidTestCase;
 import org.apache.qpid.test.utils.TestFileUtils;
@@ -65,16 +63,11 @@ public class ReplicatedEnvironmentFacade
 
     private File _storePath;
     private final Map<String, ReplicatedEnvironmentFacade> _nodes = new HashMap<String, ReplicatedEnvironmentFacade>();
-    private VirtualHost _virtualHost = mock(VirtualHost.class);
 
     public void setUp() throws Exception
     {
         super.setUp();
 
-        TaskExecutor taskExecutor = mock(TaskExecutor.class);
-        when(taskExecutor.isTaskExecutorThread()).thenReturn(true);
-        when(_virtualHost.getTaskExecutor()).thenReturn(taskExecutor);
-
         _storePath = TestFileUtils.createTestDirectory("bdb", true);
 
         setTestSystemProperty(ReplicatedEnvironmentFacade.DB_PING_SOCKET_TIMEOUT_PROPERTY_NAME, "100");
@@ -302,7 +295,7 @@ public class ReplicatedEnvironmentFacade
             State desiredState, StateChangeListener stateChangeListener)
     {
         ReplicatedEnvironmentConfiguration config = createReplicatedEnvironmentConfiguration(nodeName, nodeHostPort, designatedPrimary);
-        ReplicatedEnvironmentFacade ref = new ReplicatedEnvironmentFacade(config);
+        ReplicatedEnvironmentFacade ref = new ReplicatedEnvironmentFacade(config, null);
         ref.setStateChangeListener(stateChangeListener);
         _nodes.put(nodeName, ref);
         return ref;

Modified: qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java?rev=1584365&r1=1584364&r2=1584365&view=diff
==============================================================================
--- qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java (original)
+++ qpid/branches/java-broker-config-store-changes/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java Thu Apr  3 19:58:53 2014
@@ -31,6 +31,8 @@ import javax.jms.MessageConsumer;
 import javax.jms.Session;
 
 import org.apache.log4j.Logger;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.store.MessageStore;
 import org.apache.qpid.test.utils.Piper;
 import org.apache.qpid.test.utils.QpidBrokerTestCase;
 import org.apache.qpid.util.FileUtils;
@@ -59,12 +61,9 @@ public class BDBBackupTest extends QpidB
         super.setUp();
         _backupToDir = new File(SYSTEM_TMP_DIR + File.separator + getTestName());
         _backupToDir.mkdirs();
-
-        final String qpidWork = getBroker(DEFAULT_PORT).getWorkingDirectory();
-
-        // It would be preferable to lookup the store path using #getConfigurationStringProperty("virtualhosts...")
-        // but the config as known to QBTC does not pull-in the virtualhost section from its separate source file
-        _backupFromDir = new File(qpidWork + File.separator + TEST_VHOST + "-store");
+        Map<String, Object> virtualHostAttributes = getBrokerConfiguration().getObjectAttributes(TEST_VHOST);
+        Map<String, Object> messageStoreSettings = (Map<String, Object>) virtualHostAttributes.get(VirtualHost.MESSAGE_STORE_SETTINGS);
+        _backupFromDir = new File((String)messageStoreSettings.get(MessageStore.STORE_PATH));
         boolean fromDirExistsAndIsDir = _backupFromDir.isDirectory();
         assertTrue("backupFromDir " + _backupFromDir + " should already exist", fromDirExistsAndIsDir);
     }



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


Mime
View raw message