Author: pferraro
Date: 2009-02-06 11:57:27 -0500 (Fri, 06 Feb 2009)
New Revision: 2268
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java
Log:
Replaced awkward/buggy errorState List<Boolean> with ResetState enum.
Cleaned up ClusteredMCMPHandler interface.
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandler.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandler.java 2009-02-05
18:55:04 UTC (rev 2267)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandler.java 2009-02-06
16:57:27 UTC (rev 2268)
@@ -36,18 +36,12 @@
*/
public interface ClusteredMCMPHandler extends MCMPHandler
{
- public static final String HA_SERVICE_NAME = "ModClusterService";
-
List<MCMPServerDiscoveryEvent> getPendingDiscoveryEvents();
void discoveryEventsReceived(PeerMCMPDiscoveryStatus status);
Set<MCMPServerState> updateServersFromMasterNode(Set<MCMPServer>
masterList);
- boolean getNeedsResetTransmission();
- void recordResetTransmission();
- void recordResetSuccess();
-
- String getHAServiceName();
-
- String getPartitionName();
+ boolean isResetNecessary();
+ void resetInitiated();
+ void resetCompleted();
}
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java 2009-02-05
18:55:04 UTC (rev 2267)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerImpl.java 2009-02-06
16:57:27 UTC (rev 2268)
@@ -31,6 +31,7 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
@@ -70,12 +71,14 @@
private final MCMPHandler localHandler;
private final HASingletonMBean singleton;
private final ClusteredMCMPHandlerRpcHandler rpcStub = new RpcStub();
+
+ private enum ResetState
+ {
+ NONE, REQUIRED, PENDING;
+ }
- private volatile String haServiceName;
+ private AtomicReference<ResetState> resetState = new
AtomicReference<ResetState>(ResetState.NONE);
- @GuardedBy("errorState")
- private final List<Boolean> errorState = new ArrayList<Boolean>();
-
@GuardedBy("pendingDiscoveryEvents")
private List<MCMPServerDiscoveryEvent> pendingDiscoveryEvents = new
LinkedList<MCMPServerDiscoveryEvent>();
@@ -97,33 +100,6 @@
/**
* @{inheritDoc}
- * @see org.jboss.modcluster.ha.ClusteredMCMPHandler#getHAServiceName()
- */
- public String getHAServiceName()
- {
- return this.haServiceName;
- }
-
- /**
- * @{inheritDoc}
- * @see
org.jboss.modcluster.ha.ClusteredMCMPHandler#setHAServiceName(java.lang.String)
- */
- public void setHAServiceName(String serviceName)
- {
- this.haServiceName = serviceName;
- }
-
- /**
- * @{inheritDoc}
- * @see org.jboss.modcluster.ha.ClusteredMCMPHandler#getPartitionName()
- */
- public String getPartitionName()
- {
- return this.serviceKeyProvider.getHAPartition().getPartitionName();
- }
-
- /**
- * @{inheritDoc}
* @see org.jboss.modcluster.ha.ClusteredMCMPHandler#getPendingDiscoveryEvents()
*/
public List<MCMPServerDiscoveryEvent> getPendingDiscoveryEvents()
@@ -182,44 +158,29 @@
/**
* @{inheritDoc}
- * @see org.jboss.modcluster.ha.ClusteredMCMPHandler#getNeedsResetTransmission()
+ * @see org.jboss.modcluster.ha.ClusteredMCMPHandler#isResetNecessary()
*/
- public boolean getNeedsResetTransmission()
+ public boolean isResetNecessary()
{
- synchronized (this.errorState)
- {
- return !this.errorState.isEmpty() &&
!this.errorState.get(this.errorState.size() - 1).booleanValue();
- }
+ return this.resetState.get() == ResetState.REQUIRED;
}
/**
* @{inheritDoc}
- * @see org.jboss.modcluster.ha.ClusteredMCMPHandler#recordResetTransmission()
+ * @see org.jboss.modcluster.ha.ClusteredMCMPHandler#resetInitiated()
*/
- public void recordResetTransmission()
+ public void resetInitiated()
{
- synchronized (this.errorState)
- {
- if (!this.errorState.isEmpty())
- {
- this.errorState.set(0, Boolean.TRUE);
- }
- }
+ this.resetState.set(ResetState.PENDING);
}
/**
* @{inheritDoc}
- * @see org.jboss.modcluster.ha.ClusteredMCMPHandler#recordResetSuccess()
+ * @see org.jboss.modcluster.ha.ClusteredMCMPHandler#resetCompleted()
*/
- public void recordResetSuccess()
+ public void resetCompleted()
{
- synchronized (this.errorState)
- {
- if (this.errorState.size() > 0 &&
this.errorState.get(this.errorState.size() - 1).booleanValue())
- {
- this.errorState.remove(0);
- }
- }
+ this.resetState.compareAndSet(ResetState.PENDING, ResetState.NONE);
}
// ------------------------------------------------------------ MCMPHandler
@@ -452,13 +413,7 @@
void recordRequestFailure()
{
- synchronized (this.errorState)
- {
- if (this.errorState.size() == 0 || this.errorState.get(this.errorState.size() -
1).booleanValue())
- {
- this.errorState.add(Boolean.FALSE);
- }
- }
+ this.resetState.set(ResetState.REQUIRED);
}
class RpcStub implements ClusteredMCMPHandlerRpcHandler
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java 2009-02-05
18:55:04 UTC (rev 2267)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/ha/HAModClusterService.java 2009-02-06
16:57:27 UTC (rev 2268)
@@ -572,7 +572,7 @@
Set<MCMPServerState> ourStates =
this.coord.clusteredHandler.updateServersFromMasterNode(masterList);
- boolean needReset = this.coord.clusteredHandler.getNeedsResetTransmission();
+ boolean needReset = this.coord.clusteredHandler.isResetNecessary();
Map<String, Set<ResetRequestSource.VirtualHost>> map =
Collections.emptyMap();
List<MCMPRequest> resetRequests = needReset ?
this.coord.resetRequestSource.getLocalResetRequests(map) : null;
@@ -584,7 +584,7 @@
if (needReset)
{
- this.coord.clusteredHandler.recordResetTransmission();
+ this.coord.clusteredHandler.resetInitiated();
}
return response;
@@ -604,7 +604,7 @@
this.coord.clusteredHandler.discoveryEventsReceived(status);
// Notify our handler that any reset requests have been processed
- this.coord.clusteredHandler.recordResetSuccess();
+ this.coord.clusteredHandler.resetCompleted();
DistributedReplicantManager drm =
partition.getDistributedReplicantManager();
String key = this.coord.getHAServiceKey();
Modified:
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java
===================================================================
---
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java 2009-02-05
18:55:04 UTC (rev 2267)
+++
trunk/mod_cluster/src/test/java/org/jboss/modcluster/ha/ClusteredMCMPHandlerTestCase.java 2009-02-06
16:57:27 UTC (rev 2268)
@@ -63,25 +63,6 @@
private ClusteredMCMPHandler handler = new ClusteredMCMPHandlerImpl(this.localHandler,
this.singleton, this.keyProvider);
@Test
- public void getPartitionName()
- {
- String expected = "name";
-
- EasyMock.expect(this.keyProvider.getHAPartition()).andReturn(this.partition);
- EasyMock.expect(this.partition.getPartitionName()).andReturn(expected);
-
- EasyMock.replay(this.keyProvider, this.partition);
-
- String result = this.handler.getPartitionName();
-
- EasyMock.verify(this.keyProvider, this.partition);
-
- Assert.assertSame(expected, result);
-
- EasyMock.reset(this.keyProvider, this.partition);
- }
-
- @Test
public void init() throws Exception
{
ClusterNode node = EasyMock.createMock(ClusterNode.class);
@@ -774,4 +755,54 @@
EasyMock.verify(this.localHandler);
EasyMock.reset(this.localHandler);
}
+
+ @Test
+ public void getNeedsResetTransmission()
+ {
+ Assert.assertFalse(this.handler.isResetNecessary());
+
+ // Set State to ERROR
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
+ this.localHandler.markProxiesInError();
+
+ EasyMock.replay(this.singleton, this.localHandler);
+
+ this.handler.markProxiesInError();
+
+ EasyMock.verify(this.singleton, this.localHandler);
+
+ Assert.assertTrue(this.handler.isResetNecessary());
+
+ EasyMock.reset(this.singleton, this.localHandler);
+
+ this.handler.resetInitiated();
+
+ Assert.assertFalse(this.handler.isResetNecessary());
+
+ // Set State to ERROR again
+ EasyMock.expect(this.singleton.isMasterNode()).andReturn(true);
+ this.localHandler.markProxiesInError();
+
+ EasyMock.replay(this.singleton, this.localHandler);
+
+ this.handler.markProxiesInError();
+
+ EasyMock.verify(this.singleton, this.localHandler);
+
+ Assert.assertTrue(this.handler.isResetNecessary());
+
+ EasyMock.reset(this.singleton, this.localHandler);
+
+ this.handler.resetCompleted();
+
+ Assert.assertTrue(this.handler.isResetNecessary());
+
+ this.handler.resetInitiated();
+
+ Assert.assertFalse(this.handler.isResetNecessary());
+
+ this.handler.resetCompleted();
+
+ Assert.assertFalse(this.handler.isResetNecessary());
+ }
}