[jboss-cvs] JBossAS SVN: r76782 - in projects/cluster/ha-server-api/trunk/src: main/java/org/jboss/ha/framework/server and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 7 15:47:46 EDT 2008
Author: pferraro
Date: 2008-08-07 15:47:46 -0400 (Thu, 07 Aug 2008)
New Revision: 76782
Added:
projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/interfaces/HAServiceKeyProvider.java
Modified:
projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/interfaces/HAService.java
projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/HAServiceImpl.java
projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/HASingletonImpl.java
projects/cluster/ha-server-api/trunk/src/test/java/org/jboss/test/ha/framework/server/HAServiceTestCase.java
Log:
[JBAS-5660] Create HAServiceKeyProvider sub-interface of HAService to allow ModClusterService to override the key used by DRM and HAPartition RPC handler map.
This is a re-implementation of the singleton-per-domain logic of ModClusterService.
Modified: projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/interfaces/HAService.java
===================================================================
--- projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/interfaces/HAService.java 2008-08-07 19:38:10 UTC (rev 76781)
+++ projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/interfaces/HAService.java 2008-08-07 19:47:46 UTC (rev 76782)
@@ -31,15 +31,8 @@
*
* @param <E> type of event generated by this service
*/
-public interface HAService<E extends EventObject> extends EventListener<E>
+public interface HAService<E extends EventObject> extends HAServiceKeyProvider, EventListener<E>
{
- /**
- * Get the underlying partition used by this service.
- *
- * @return the partition
- */
- HAPartition getHAPartition();
-
String getServiceHAName();
void setHAPartition(HAPartition partition);
Added: projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/interfaces/HAServiceKeyProvider.java
===================================================================
--- projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/interfaces/HAServiceKeyProvider.java (rev 0)
+++ projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/interfaces/HAServiceKeyProvider.java 2008-08-07 19:47:46 UTC (rev 76782)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.framework.interfaces;
+
+/**
+ * Provides the key used to identify a service within the {@link HAPartition}, {@link DistributedReplicantManager}, etc.
+ *
+ * @author Paul Ferraro
+ */
+public interface HAServiceKeyProvider
+{
+ /**
+ * Get the underlying partition used by this service.
+ *
+ * @return the partition
+ */
+ HAPartition getHAPartition();
+
+ /**
+ * Get the key used to identify a service within a clustering service.
+ *
+ * @return a key unique to this service
+ */
+ String getHAServiceKey();
+}
Modified: projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/HAServiceImpl.java
===================================================================
--- projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/HAServiceImpl.java 2008-08-07 19:38:10 UTC (rev 76781)
+++ projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/HAServiceImpl.java 2008-08-07 19:47:46 UTC (rev 76782)
@@ -217,43 +217,58 @@
protected void registerRPCHandler()
{
+ String key = this.getHAServiceKey();
+
if (this.isRegisterThreadContextClassLoader())
{
- this.partition.registerRPCHandler(this.name, this.getRpcHandler(), Thread.currentThread().getContextClassLoader());
+ this.partition.registerRPCHandler(key, this.getRpcHandler(), Thread.currentThread().getContextClassLoader());
}
else
{
- this.partition.registerRPCHandler(this.name, this.getRpcHandler());
+ this.partition.registerRPCHandler(key, this.getRpcHandler());
}
}
protected void unregisterRPCHandler()
{
- this.partition.unregisterRPCHandler(this.name, this.getRpcHandler());
+ this.partition.unregisterRPCHandler(this.getHAServiceKey(), this.getRpcHandler());
}
protected void registerDRMListener() throws Exception
{
DistributedReplicantManager drm = this.partition.getDistributedReplicantManager();
- drm.registerListener(this.name, this);
+ String key = this.getHAServiceKey();
+
+ drm.registerListener(key, this);
// this ensures that the DRM knows that this node has the MBean deployed
- drm.add(this.name, this.getReplicant());
+ drm.add(key, this.getReplicant());
}
protected void unregisterDRMListener() throws Exception
{
DistributedReplicantManager drm = this.partition.getDistributedReplicantManager();
+ String key = this.getHAServiceKey();
+
// remove replicant node
- drm.remove(this.name);
+ drm.remove(key);
// unregister
- drm.unregisterListener(this.name, this);
+ drm.unregisterListener(key, this);
}
/**
+ * {@inheritDoc}
+ * @return the key used by the DRM and partition rpc handler mapping.
+ */
+ public String getHAServiceKey()
+ {
+ return this.name;
+ }
+
+ /**
* @return the object to be registered with the {@link org.jboss.ha.framework.interfaces.DistributedReplicantManager}.
*/
protected Serializable getReplicant()
@@ -267,7 +282,7 @@
@SuppressWarnings("unchecked")
public void replicantsChanged(String key, List newReplicants, int newReplicantsViewId, boolean merge)
{
- if (key.equals(this.name))
+ if (key.equals(this.getHAServiceKey()))
{
// This synchronized block was added when the internal behavior of
// DistributedReplicantManagerImpl was changed so that concurrent
Modified: projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/HASingletonImpl.java
===================================================================
--- projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/HASingletonImpl.java 2008-08-07 19:38:10 UTC (rev 76781)
+++ projects/cluster/ha-server-api/trunk/src/main/java/org/jboss/ha/framework/server/HASingletonImpl.java 2008-08-07 19:47:46 UTC (rev 76782)
@@ -163,7 +163,7 @@
protected List<ClusterNode> getElectionCandidates()
{
- return this.getHAPartition().getDistributedReplicantManager().lookupReplicantsNodes(this.getServiceHAName());
+ return this.getHAPartition().getDistributedReplicantManager().lookupReplicantsNodes(this.getHAServiceKey());
}
/**
@@ -181,7 +181,7 @@
{
DistributedReplicantManager drm = this.getHAPartition().getDistributedReplicantManager();
- return drm.isMasterReplica(this.getServiceHAName());
+ return drm.isMasterReplica(this.getHAServiceKey());
}
protected void makeThisNodeMaster()
Modified: projects/cluster/ha-server-api/trunk/src/test/java/org/jboss/test/ha/framework/server/HAServiceTestCase.java
===================================================================
--- projects/cluster/ha-server-api/trunk/src/test/java/org/jboss/test/ha/framework/server/HAServiceTestCase.java 2008-08-07 19:38:10 UTC (rev 76781)
+++ projects/cluster/ha-server-api/trunk/src/test/java/org/jboss/test/ha/framework/server/HAServiceTestCase.java 2008-08-07 19:47:46 UTC (rev 76782)
@@ -55,7 +55,7 @@
}
};
- private HAServiceImpl<HAServiceEvent> service = this.getHAService();
+ private HAServiceImpl<HAServiceEvent> service;
/**
* @see junit.framework.TestCase#setUp()
@@ -79,6 +79,13 @@
return this.customService;
}
+ public void testGetServiceKey()
+ {
+ String key = this.service.getHAServiceKey();
+
+ assert key == SERVICE_HA_NAME;
+ }
+
public void testStart() throws Exception
{
// Test isRegisterThreadContextClassLoader() = default value
@@ -186,8 +193,9 @@
}
@SuppressWarnings("unchecked")
- public void testNotifyListeners()
+ public void testEventFacility()
{
+ // Test add and notify
HAServiceEvent event = new HAServiceEvent("", "");
EventListener<HAServiceEvent> listener1 = EasyMock.createStrictMock(EventListener.class);
EventListener<HAServiceEvent> listener2 = EasyMock.createStrictMock(EventListener.class);
@@ -213,6 +221,25 @@
EasyMock.verify(listener1, listener2);
EasyMock.reset(listener1, listener2);
+
+ // Test remove
+ try
+ {
+ // Verify that next listener is notified even if 1st throws exception
+ listener1.handleEvent(event);
+ }
+ catch (Exception e)
+ {
+ assert false;
+ }
+
+ EasyMock.replay(listener1, listener2);
+
+ this.service.removeEventListener(listener2);
+ this.service.notifyListeners(event);
+
+ EasyMock.verify(listener1, listener2);
+ EasyMock.reset(listener1, listener2);
}
public void testReplicantsChanged() throws Exception
More information about the jboss-cvs-commits
mailing list