diff options
| author | Robert Godfrey <rgodfrey@apache.org> | 2014-05-08 13:14:05 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org> | 2014-05-08 13:14:05 +0000 |
| commit | 14ffecc29a8393f54c9d4f6f3bce6ee3276cf381 (patch) | |
| tree | 8d3b879c9c74fa132f7cfba8e474bb72a781dece /qpid/java/bdbstore/src | |
| parent | 54243c16cf78f1d82c642335deaa01aa9a1b341e (diff) | |
| download | qpid-python-14ffecc29a8393f54c9d4f6f3bce6ee3276cf381.tar.gz | |
QPID-5754 : [Java Broker] Make state change operations methods rather than calls to setDesiredState
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1593264 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/bdbstore/src')
3 files changed, 50 insertions, 30 deletions
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeImpl.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeImpl.java index 23dd2ee5c0..d143d5a748 100644 --- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeImpl.java +++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHARemoteReplicationNodeImpl.java @@ -35,6 +35,7 @@ import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.IllegalStateTransitionException; import org.apache.qpid.server.model.ManagedAttributeField; import org.apache.qpid.server.model.State; +import org.apache.qpid.server.model.StateTransition; import org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade; public class BDBHARemoteReplicationNodeImpl extends AbstractConfiguredObject<BDBHARemoteReplicationNodeImpl> implements BDBHARemoteReplicationNode<BDBHARemoteReplicationNodeImpl> @@ -96,7 +97,8 @@ public class BDBHARemoteReplicationNodeImpl extends AbstractConfiguredObject<BDB return _lastTransactionId; } - public void delete() + @StateTransition(currentState = {State.ACTIVE, State.QUIESCED, State.STOPPED, State.ERRORED}, desiredState = State.DELETED) + private void doDelete() { this.deleted(); } @@ -115,7 +117,7 @@ public class BDBHARemoteReplicationNodeImpl extends AbstractConfiguredObject<BDB if (LOGGER.isDebugEnabled()) { - LOGGER.debug("The mastership has been transfered to " + nodeName); + LOGGER.debug("The mastership has been transferred to " + nodeName); } } catch(Exception e) diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java index a6ce1c47df..ce7c79208f 100644 --- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java +++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java @@ -48,6 +48,7 @@ import org.apache.qpid.server.model.ManagedObject; import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; import org.apache.qpid.server.model.RemoteReplicationNode; import org.apache.qpid.server.model.State; +import org.apache.qpid.server.model.StateTransition; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.model.VirtualHostNode; import org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory; @@ -322,12 +323,12 @@ public class BDBHAVirtualHostNodeImpl extends AbstractVirtualHostNode<BDBHAVirtu } } - @Override - protected void stop() + @StateTransition( currentState = { State.ACTIVE, State.ERRORED }, desiredState = State.STOPPED ) + protected void doStop() { try { - super.stop(); + super.doStop(); } finally { @@ -339,6 +340,22 @@ public class BDBHAVirtualHostNodeImpl extends AbstractVirtualHostNode<BDBHAVirtu } } + protected void onClose() + { + try + { + super.onClose(); + } + finally + { + ReplicatedEnvironmentFacade environmentFacade = getReplicatedEnvironmentFacade(); + if (environmentFacade != null && _environmentFacade.compareAndSet(environmentFacade, null)) + { + environmentFacade.close(); + } + } + } + private void onMaster() { try @@ -384,7 +401,7 @@ public class BDBHAVirtualHostNodeImpl extends AbstractVirtualHostNode<BDBHAVirtu } }); } - host.setDesiredState(State.ACTIVE); + host.start(); } catch (Exception e) @@ -421,7 +438,7 @@ public class BDBHAVirtualHostNodeImpl extends AbstractVirtualHostNode<BDBHAVirtu VirtualHost<?,?,?> virtualHost = getVirtualHost(); if (virtualHost!= null) { - virtualHost.setDesiredState(State.STOPPED); + virtualHost.close(); } } @@ -653,15 +670,6 @@ public class BDBHAVirtualHostNodeImpl extends AbstractVirtualHostNode<BDBHAVirtu { } - @Override - public boolean setState(State desiredState) - { - if (desiredState != State.STOPPED) - { - throw new IllegalArgumentException("Unsupported state " + desiredState); - } - return super.setState(desiredState); - } } } diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java index 49205930ea..4bff8918fd 100644 --- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java @@ -89,7 +89,7 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase { try { - node.setDesiredState(State.DELETED); + node.delete(); } catch(Exception e) { @@ -175,7 +175,9 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase { } }); - assertEquals(State.ACTIVE, node.setDesiredState(State.ACTIVE)); + + node.start(); + assertEquals(State.ACTIVE, node.getState()); DurableConfigurationStore store = node.getConfigurationStore(); assertNotNull(store); @@ -200,14 +202,14 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase assertEquals("Unexpected virtual host store", store, virtualHost.getMessageStore()); assertEquals("Unexpected virtual host state", State.ACTIVE, virtualHost.getState()); - State currentState = node.setDesiredState(State.STOPPED); - assertEquals("Unexpected state returned after stop", State.STOPPED, currentState); + node.stop(); + assertEquals("Unexpected state returned after stop", State.STOPPED, node.getState()); assertEquals("Unexpected state", State.STOPPED, node.getState()); assertNull("Virtual host is not destroyed", node.getVirtualHost()); - currentState = node.setDesiredState(State.DELETED); - assertEquals("Unexpected state returned after delete", State.DELETED, currentState); + node.delete(); + assertEquals("Unexpected state returned after delete", State.DELETED, node.getState()); assertEquals("Unexpected state", State.DELETED, node.getState()); assertFalse("Store still exists", _bdbStorePath.exists()); } @@ -228,7 +230,8 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase BDBHAVirtualHostNode<?> node = createHaVHN(attributes); - assertEquals("Failed to activate node", State.ACTIVE, node.setDesiredState(State.ACTIVE)); + node.start(); + assertEquals("Failed to activate node", State.ACTIVE, node.getState()); BDBMessageStore bdbMessageStore = (BDBMessageStore) node.getConfigurationStore(); ReplicatedEnvironment environment = (ReplicatedEnvironment) bdbMessageStore.getEnvironmentFacade().getEnvironment(); @@ -265,7 +268,8 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, _bdbStorePath + File.separator + "1"); BDBHAVirtualHostNode<?> node1 = createHaVHN(node1Attributes); - assertEquals("Failed to activate node", State.ACTIVE, node1.setDesiredState(State.ACTIVE)); + node1.start(); + assertEquals("Failed to activate node", State.ACTIVE, node1.getState()); int node2PortNumber = getNextAvailable(node1PortNumber+1); @@ -279,7 +283,8 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, _bdbStorePath + File.separator + "2"); BDBHAVirtualHostNode<?> node2 = createHaVHN(node2Attributes); - assertEquals("Failed to activate node2", State.ACTIVE, node2.setDesiredState(State.ACTIVE)); + node2.start(); + assertEquals("Failed to activate node2", State.ACTIVE, node2.getState()); int node3PortNumber = getNextAvailable(node2PortNumber+1); Map<String, Object> node3Attributes = new HashMap<String, Object>(); @@ -291,7 +296,8 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase node3Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); node3Attributes.put(BDBHAVirtualHostNode.STORE_PATH, _bdbStorePath + File.separator + "3"); BDBHAVirtualHostNode<?> node3 = createHaVHN(node3Attributes); - assertEquals("Failed to activate node3", State.ACTIVE, node3.setDesiredState(State.ACTIVE)); + node3.start(); + assertEquals("Failed to activate node3", State.ACTIVE, node3.getState()); BDBHAVirtualHostNode<?> replica = null; int findReplicaCount = 0; @@ -335,7 +341,8 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, _bdbStorePath + File.separator + "1"); BDBHAVirtualHostNode<?> node1 = createHaVHN(node1Attributes); - assertEquals("Failed to activate node", State.ACTIVE, node1.setDesiredState(State.ACTIVE)); + node1.start(); + assertEquals("Failed to activate node", State.ACTIVE, node1.getState()); final CountDownLatch remoteNodeLatch = new CountDownLatch(2); node1.addChangeListener(new ConfigurationChangeListener() @@ -378,7 +385,8 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, _bdbStorePath + File.separator + "2"); BDBHAVirtualHostNode<?> node2 = createHaVHN(node2Attributes); - assertEquals("Failed to activate node2", State.ACTIVE, node2.setDesiredState(State.ACTIVE)); + node2.start(); + assertEquals("Failed to activate node2", State.ACTIVE, node2.getState()); int node3PortNumber = getNextAvailable(node2PortNumber+1); Map<String, Object> node3Attributes = new HashMap<String, Object>(); @@ -390,7 +398,8 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase node3Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress); node3Attributes.put(BDBHAVirtualHostNode.STORE_PATH, _bdbStorePath + File.separator + "3"); BDBHAVirtualHostNode<?> node3 = createHaVHN(node3Attributes); - assertEquals("Failed to activate node3", State.ACTIVE, node3.setDesiredState(State.ACTIVE)); + node3.start(); + assertEquals("Failed to activate node3", State.ACTIVE, node3.getState()); assertTrue("Replication nodes have not been seen during 5s", remoteNodeLatch.await(5, TimeUnit.SECONDS)); @@ -429,7 +438,8 @@ public class BDBHAVirtualHostNodeTest extends QpidTestCase node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, _bdbStorePath + File.separator + "1"); BDBHAVirtualHostNode<?> node = createHaVHN(node1Attributes); - assertEquals("Failed to activate node", State.ACTIVE, node.setDesiredState(State.ACTIVE)); + node.start(); + assertEquals("Failed to activate node", State.ACTIVE, node.getState()); assertNodeRole(node, "MASTER"); |
