summaryrefslogtreecommitdiff
path: root/qpid/java/bdbstore/src
diff options
context:
space:
mode:
authorRobert Godfrey <rgodfrey@apache.org>2014-04-07 12:44:42 +0000
committerRobert Godfrey <rgodfrey@apache.org>2014-04-07 12:44:42 +0000
commit6121e960f95fe74b0a93cb3d1e27c7439d585eb3 (patch)
tree165a7d92f132bace4ee6bb542505cf471d069ad5 /qpid/java/bdbstore/src
parenta465268557507d5f0ac1b151f183c1cd294ad372 (diff)
downloadqpid-python-6121e960f95fe74b0a93cb3d1e27c7439d585eb3.tar.gz
QPID-5665 : [Java Broker] Unify VirtualHost model and implementation classes
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1585471 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/bdbstore/src')
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHost.java65
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostAdapter.java39
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostAdapterFactory.java51
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java63
-rw-r--r--qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory2
-rw-r--r--qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.VirtualHostFactory19
-rw-r--r--qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java29
7 files changed, 78 insertions, 190 deletions
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHost.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHost.java
index a58bc274a9..3bb44b3e9c 100644
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHost.java
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHost.java
@@ -23,12 +23,16 @@ package org.apache.qpid.server.store.berkeleydb;
import java.util.HashMap;
import java.util.Map;
+import com.sleepycat.je.rep.StateChangeEvent;
+import com.sleepycat.je.rep.StateChangeListener;
import org.apache.log4j.Logger;
+
import org.apache.qpid.server.connection.IConnectionRegistry;
import org.apache.qpid.server.logging.messages.MessageStoreMessages;
import org.apache.qpid.server.logging.subjects.MessageStoreLogSubject;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ManagedObject;
import org.apache.qpid.server.model.VirtualHost;
-import org.apache.qpid.server.stats.StatisticsGatherer;
import org.apache.qpid.server.store.ConfiguredObjectRecordRecoveverAndUpgrader;
import org.apache.qpid.server.store.DurableConfigurationStore;
import org.apache.qpid.server.store.MessageStore;
@@ -37,30 +41,55 @@ import org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironment
import org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler;
import org.apache.qpid.server.virtualhost.AbstractVirtualHost;
import org.apache.qpid.server.virtualhost.MessageStoreRecoverer;
-import org.apache.qpid.server.virtualhost.State;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-
-import com.sleepycat.je.rep.StateChangeEvent;
-import com.sleepycat.je.rep.StateChangeListener;
+import org.apache.qpid.server.virtualhost.VirtualHostState;
-public class BDBHAVirtualHost extends AbstractVirtualHost
+@ManagedObject( category = false, type = "BDB_HA" )
+public class BDBHAVirtualHost extends AbstractVirtualHost<BDBHAVirtualHost>
{
+ public static final String TYPE = "BDB_HA";
private static final Logger LOGGER = Logger.getLogger(BDBHAVirtualHost.class);
private BDBMessageStore _messageStore;
private MessageStoreLogSubject _messageStoreLogSubject;
- BDBHAVirtualHost(VirtualHostRegistry virtualHostRegistry,
- StatisticsGatherer brokerStatisticsGatherer,
- org.apache.qpid.server.security.SecurityManager parentSecurityManager,
- VirtualHost virtualHost)
+ BDBHAVirtualHost(final Map<String, Object> attributes, Broker<?> broker)
{
- super(virtualHostRegistry, brokerStatisticsGatherer, parentSecurityManager, virtualHost);
+ super(attributes, broker);
+ }
+
+
+ @Override
+ protected void validateAttributes()
+ {
+ super.validateAttributes();
+ Map<String, Object> attributes = getActualAttributes();
+ @SuppressWarnings("unchecked")
+ Map<String, Object> messageStoreSettings = (Map<String, Object>)attributes.get(org.apache.qpid.server.model.VirtualHost.MESSAGE_STORE_SETTINGS);
+ if (messageStoreSettings == null)
+ {
+ throw new IllegalArgumentException("Attribute '"+ org.apache.qpid.server.model.VirtualHost.MESSAGE_STORE_SETTINGS + "' is required.");
+ }
+
+ validateAttribute(MessageStore.STORE_PATH, String.class, messageStoreSettings);
+ validateAttribute(ReplicatedEnvironmentFacadeFactory.GROUP_NAME, String.class, messageStoreSettings);
+ validateAttribute(ReplicatedEnvironmentFacadeFactory.NODE_NAME, String.class, messageStoreSettings);
+ validateAttribute(ReplicatedEnvironmentFacadeFactory.NODE_ADDRESS, String.class, messageStoreSettings);
+ validateAttribute(ReplicatedEnvironmentFacadeFactory.HELPER_ADDRESS, String.class, messageStoreSettings);
+ }
+
+ private void validateAttribute(String attrName, Class<?> clazz, Map<String, Object> attributes)
+ {
+ Object attr = attributes.get(attrName);
+ if(!clazz.isInstance(attr))
+ {
+ throw new IllegalArgumentException("Attribute '"+ attrName
+ +"' is required and must be of type "+clazz.getSimpleName()+".");
+ }
}
protected void initialiseStorage(VirtualHost virtualHost)
{
- setState(State.PASSIVE);
+ setState(VirtualHostState.PASSIVE);
_messageStoreLogSubject = new MessageStoreLogSubject(getName(), BDBMessageStore.class.getSimpleName());
_messageStore = new BDBMessageStore(new ReplicatedEnvironmentFacadeFactory());
@@ -92,7 +121,7 @@ public class BDBHAVirtualHost extends AbstractVirtualHost
return _messageStore;
}
- private void activate()
+ private void onMaster()
{
try
{
@@ -115,7 +144,7 @@ public class BDBHAVirtualHost extends AbstractVirtualHost
private void passivate()
{
- State finalState = State.ERRORED;
+ VirtualHostState finalState = VirtualHostState.ERRORED;
try
{
@@ -132,12 +161,12 @@ public class BDBHAVirtualHost extends AbstractVirtualHost
getExchangeRegistry().clearAndUnregisterMbeans();
getDtxRegistry().close();
- finalState = State.PASSIVE;
+ finalState = VirtualHostState.PASSIVE;
}
finally
{
setState(finalState);
- reportIfError(getState());
+ reportIfError(getVirtualHostState());
}
}
@@ -163,7 +192,7 @@ public class BDBHAVirtualHost extends AbstractVirtualHost
switch (state)
{
case MASTER:
- activate();
+ onMaster();
break;
case REPLICA:
passivate();
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostAdapter.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostAdapter.java
deleted file mode 100644
index 6d249ddc34..0000000000
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostAdapter.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.server.store.berkeleydb;
-
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.model.ManagedObject;
-import org.apache.qpid.server.model.adapter.VirtualHostAdapter;
-
-import java.util.Map;
-import java.util.UUID;
-
-@ManagedObject( category = false, type = "BDB_HA" )
-public class BDBHAVirtualHostAdapter extends VirtualHostAdapter<BDBHAVirtualHostAdapter>
-{
- public BDBHAVirtualHostAdapter(final UUID id,
- final Map<String, Object> attributes,
- final Broker<?> broker)
- {
- super(id, attributes, broker);
- }
-}
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostAdapterFactory.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostAdapterFactory.java
deleted file mode 100644
index 7d1d6ea664..0000000000
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostAdapterFactory.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.server.store.berkeleydb;
-
-import org.apache.qpid.server.model.AbstractConfiguredObjectTypeFactory;
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.model.ConfiguredObject;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-public class BDBHAVirtualHostAdapterFactory extends AbstractConfiguredObjectTypeFactory<BDBHAVirtualHostAdapter>
-{
-
- public BDBHAVirtualHostAdapterFactory()
- {
- super(BDBHAVirtualHostAdapter.class);
- }
-
- @Override
- public BDBHAVirtualHostAdapter createInstance(final Map<String, Object> attributes,
- final ConfiguredObject<?>... parents)
- {
- Map<String,Object> attributesWithoutId = new HashMap<String, Object>(attributes);
- Object idObj = attributesWithoutId.remove(ConfiguredObject.ID);
- UUID id = idObj == null ? UUID.randomUUID() : idObj instanceof UUID ? (UUID) idObj : UUID.fromString(idObj.toString());
- final Broker broker = getParent(Broker.class, parents);
- return new BDBHAVirtualHostAdapter(id, attributesWithoutId, broker);
- }
-
-
-}
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java
index 6fb84b8a4d..2a28a61eca 100644
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostFactory.java
@@ -1,4 +1,4 @@
-package org.apache.qpid.server.store.berkeleydb;/*
+/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,64 +18,31 @@ package org.apache.qpid.server.store.berkeleydb;/*
* under the License.
*
*/
+package org.apache.qpid.server.store.berkeleydb;
-import java.util.Map;
+import org.apache.qpid.server.model.AbstractConfiguredObjectTypeFactory;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
-import org.apache.qpid.server.plugin.VirtualHostFactory;
-import org.apache.qpid.server.stats.StatisticsGatherer;
-import org.apache.qpid.server.store.MessageStore;
-import org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacadeFactory;
-import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
-public class BDBHAVirtualHostFactory implements VirtualHostFactory
+public class BDBHAVirtualHostFactory extends AbstractConfiguredObjectTypeFactory<BDBHAVirtualHost>
{
- public static final String TYPE = "BDB_HA";
-
- @Override
- public String getType()
+ public BDBHAVirtualHostFactory()
{
- return TYPE;
+ super(BDBHAVirtualHost.class);
}
@Override
- public VirtualHost createVirtualHost(VirtualHostRegistry virtualHostRegistry,
- StatisticsGatherer brokerStatisticsGatherer,
- org.apache.qpid.server.security.SecurityManager parentSecurityManager,
- org.apache.qpid.server.model.VirtualHost virtualHost)
+ public BDBHAVirtualHost createInstance(final Map<String, Object> attributes,
+ final ConfiguredObject<?>... parents)
{
- return new BDBHAVirtualHost(virtualHostRegistry,
- brokerStatisticsGatherer,
- parentSecurityManager,
- virtualHost);
+ final Broker broker = getParent(Broker.class, parents);
+ return new BDBHAVirtualHost(attributes, broker);
}
- @Override
- public void validateAttributes(Map<String, Object> attributes)
- {
- @SuppressWarnings("unchecked")
- Map<String, Object> messageStoreSettings = (Map<String, Object>)attributes.get(org.apache.qpid.server.model.VirtualHost.MESSAGE_STORE_SETTINGS);
- if (messageStoreSettings == null)
- {
- throw new IllegalArgumentException("Attribute '"+ org.apache.qpid.server.model.VirtualHost.MESSAGE_STORE_SETTINGS + "' is required.");
- }
-
- validateAttribute(MessageStore.STORE_PATH, String.class, messageStoreSettings);
- validateAttribute(ReplicatedEnvironmentFacadeFactory.GROUP_NAME, String.class, messageStoreSettings);
- validateAttribute(ReplicatedEnvironmentFacadeFactory.NODE_NAME, String.class, messageStoreSettings);
- validateAttribute(ReplicatedEnvironmentFacadeFactory.NODE_ADDRESS, String.class, messageStoreSettings);
- validateAttribute(ReplicatedEnvironmentFacadeFactory.HELPER_ADDRESS, String.class, messageStoreSettings);
- }
-
- private void validateAttribute(String attrName, Class<?> clazz, Map<String, Object> attributes)
- {
- Object attr = attributes.get(attrName);
- if(!clazz.isInstance(attr))
- {
- throw new IllegalArgumentException("Attribute '"+ attrName
- +"' is required and must be of type "+clazz.getSimpleName()+".");
- }
- }
}
diff --git a/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory b/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory
index ab12289814..0f8848cb74 100644
--- a/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory
+++ b/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.qpid.server.store.berkeleydb.BDBHAVirtualHostAdapterFactory
+org.apache.qpid.server.store.berkeleydb.BDBHAVirtualHostFactory
diff --git a/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.VirtualHostFactory b/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.VirtualHostFactory
deleted file mode 100644
index 0f8848cb74..0000000000
--- a/qpid/java/bdbstore/src/main/resources/META-INF/services/org.apache.qpid.server.plugin.VirtualHostFactory
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.BDBHAVirtualHostFactory
diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java
index c702e557c2..70882ca45b 100644
--- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java
+++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/VirtualHostTest.java
@@ -20,8 +20,18 @@
*/
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.UUID;
+
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.updater.TaskExecutor;
@@ -38,15 +48,6 @@ import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.util.FileUtils;
-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
{
@@ -54,7 +55,7 @@ public class VirtualHostTest extends QpidTestCase
private StatisticsGatherer _statisticsGatherer;
private RecovererProvider _recovererProvider;
private File _bdbStorePath;
- private VirtualHost<?> _host;
+ private VirtualHost<?,?,?> _host;
private ConfigurationEntryStore _store;
@Override
@@ -117,14 +118,14 @@ public class VirtualHostTest extends QpidTestCase
Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
virtualHostAttributes.put(VirtualHost.NAME, virtualHostName);
- virtualHostAttributes.put(VirtualHost.TYPE, BDBHAVirtualHostFactory.TYPE);
+ virtualHostAttributes.put(VirtualHost.TYPE, BDBHAVirtualHost.TYPE);
virtualHostAttributes.put(VirtualHost.MESSAGE_STORE_SETTINGS, messageStoreSettings);
_host = createHost(virtualHostAttributes);
_host.setDesiredState(State.INITIALISING, State.ACTIVE);
assertEquals("Unexpected virtual host name", virtualHostName, _host.getName());
- assertEquals("Unexpected host type", BDBHAVirtualHostFactory.TYPE, _host.getType());
+ assertEquals("Unexpected host type", BDBHAVirtualHost.TYPE, _host.getType());
assertEquals(messageStoreSettings, _host.getMessageStoreSettings());
@@ -141,14 +142,14 @@ public class VirtualHostTest extends QpidTestCase
}
- private VirtualHost<?> createHost(Map<String, Object> attributes)
+ private VirtualHost<?,?,?> createHost(Map<String, Object> 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);
+ return (VirtualHost<?,?,?>) vhostFactory.create(attributes,_broker);
}
}