[exo-jcr-commits] exo-jcr SVN: r3266 - in kernel/trunk/exo.kernel.component.common/src: main/java/org/exoplatform/services/rpc/impl and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Oct 8 11:24:49 EDT 2010
Author: nfilotto
Date: 2010-10-08 11:24:49 -0400 (Fri, 08 Oct 2010)
New Revision: 3266
Modified:
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/RPCService.java
kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java
kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java
Log:
EXOJCR-967: The method isCoordinator has been added
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/RPCService.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/RPCService.java 2010-10-08 14:40:49 UTC (rev 3265)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/RPCService.java 2010-10-08 15:24:49 UTC (rev 3266)
@@ -124,4 +124,11 @@
* doesn't have the {@link RuntimePermission} <code>ACCESS_RPC_SERVICE_PERMISSION</code>
*/
void unregisterCommand(RemoteCommand command) throws SecurityException;
+
+ /**
+ * Indicates whether the local node is the coordinator of the cluster
+ * @return <code>true</code> if the coordinator is the coordinator, <code>false</code> otherwise
+ * throws RPCException in case the {@link RPCService} is in an illegal state
+ */
+ boolean isCoordinator() throws RPCException;
}
\ No newline at end of file
Modified: kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java 2010-10-08 14:40:49 UTC (rev 3265)
+++ kernel/trunk/exo.kernel.component.common/src/main/java/org/exoplatform/services/rpc/impl/RPCServiceImpl.java 2010-10-08 15:24:49 UTC (rev 3266)
@@ -130,6 +130,11 @@
protected volatile Address coordinator;
/**
+ * Indicates whether the current node is the coordinator of the cluster or not
+ */
+ protected volatile boolean isCoordinator;
+
+ /**
* The default value of the timeout
*/
private long defaultTimeout = DEFAULT_TIMEOUT;
@@ -430,6 +435,7 @@
{
this.members = view.getMembers();
this.coordinator = members != null && members.size() > 0 ? members.get(0) : null;
+ this.isCoordinator = coordinator != null && coordinator.equals(channel.getLocalAddress());
}
/**
@@ -498,6 +504,19 @@
}
/**
+ * {@inheritDoc}
+ */
+ public boolean isCoordinator() throws RPCException
+ {
+ if (state != State.STARTED)
+ {
+ throw new RPCException("Cannot know whether the local node is a coordinator or not if " +
+ "the service is not started, the current state of the service is " + state);
+ }
+ return isCoordinator;
+ }
+
+ /**
* Gives the {@link RemoteCommand} corresponding to the given id
* @param commandId the command id of the command to retrieve
* @return the corresponding {@link RemoteCommand}
@@ -553,6 +572,7 @@
security.checkPermission(RPCService.ACCESS_RPC_SERVICE_PERMISSION);
}
this.state = State.STOPPED;
+ this.isCoordinator = false;
if (channel != null && channel.isOpen())
{
if (LOG.isInfoEnabled())
Modified: kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java 2010-10-08 14:40:49 UTC (rev 3265)
+++ kernel/trunk/exo.kernel.component.common/src/test/java/org/exoplatform/services/rpc/impl/TestRPCServiceImpl.java 2010-10-08 15:24:49 UTC (rev 3266)
@@ -221,7 +221,17 @@
{
// OK
}
+ try
+ {
+ service.isCoordinator();
+ fail("We expect a RPCException since the current state is not the expected one");
+ }
+ catch (RPCException e)
+ {
+ // OK
+ }
service.start();
+ assertEquals(true, service.isCoordinator());
service.executeCommandOnAllNodes(foo, true);
service.executeCommandOnAllNodes(foo, 10);
service.executeCommandOnCoordinator(foo, true);
@@ -668,6 +678,8 @@
service2.registerCommand(LongTask);
service1.start();
service2.start();
+ assertEquals(true, service1.isCoordinator());
+ assertEquals(false, service2.isCoordinator());
List<Object> result;
Object o;
result = service1.executeCommandOnAllNodes(CmdUnknownOnNode2, true);
@@ -739,6 +751,16 @@
assertNotNull(result);
assertTrue(result.size() == 1);
assertTrue("We expect an RPCException due to a member that has left", result.get(0) instanceof MemberHasLeftException);
+ try
+ {
+ service1.isCoordinator();
+ fail("We expect a RPCException since the current state is not the expected one");
+ }
+ catch (RPCException e)
+ {
+ // OK
+ }
+ assertEquals(true, service2.isCoordinator());
}
finally
{
More information about the exo-jcr-commits
mailing list