[jbosscache-commits] JBoss Cache SVN: r5575 - in core/trunk/src: main/java/org/jboss/cache/commands and 4 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Wed Apr 16 09:32:22 EDT 2008
Author: manik.surtani at jboss.com
Date: 2008-04-16 09:32:22 -0400 (Wed, 16 Apr 2008)
New Revision: 5575
Modified:
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
core/trunk/src/main/java/org/jboss/cache/commands/CommandsFactory.java
core/trunk/src/main/java/org/jboss/cache/commands/remote/ReplicateCommand.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java
Log:
Fixed some core BR issues
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java 2008-04-16 10:52:28 UTC (rev 5574)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java 2008-04-16 13:32:22 UTC (rev 5575)
@@ -22,6 +22,7 @@
import org.jgroups.Address;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
@@ -41,13 +42,19 @@
private String buddyGroupName;
- private CommandsFactory factory;
+ CommandsFactory factory;
public BuddyFqnTransformer(String buddyGroupName)
{
this.buddyGroupName = buddyGroupName == null ? "null" : buddyGroupName;
}
+ public BuddyFqnTransformer(String buddyGroupName, CommandsFactory cf)
+ {
+ this.buddyGroupName = buddyGroupName == null ? "null" : buddyGroupName;
+ this.factory = cf;
+ }
+
public Object handleCommitCommand(InvocationContext ctx, CommitCommand commitCommand) throws Throwable
{
return commitCommand;
@@ -176,7 +183,7 @@
public Object handleReplicateCommand(InvocationContext ctx, ReplicateCommand command) throws Throwable
{
- List<MarshallableCommand> transformed = transformBatch(command.getModifications());
+ List<MarshallableCommand> transformed = transformBatch(command.isSingleCommand() ? Collections.singletonList(command.getSingleModification()) : command.getModifications());
return factory.buildReplicateCommand(transformed);
}
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-04-16 10:52:28 UTC (rev 5574)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-04-16 13:32:22 UTC (rev 5575)
@@ -288,9 +288,15 @@
reassignBuddies(cache.getMembers());
queue.clear();
asyncViewChangeHandler.start();
- fqnTransformer = new BuddyFqnTransformer(buddyGroup.getGroupName());
+
+ initFqnTransformer(buddyGroup.getGroupName(), commandsFactory);
}
+ void initFqnTransformer(String groupName, CommandsFactory commandsFactory)
+ {
+ fqnTransformer = new BuddyFqnTransformer(groupName, commandsFactory);
+ }
+
public boolean isAutoDataGravitation()
{
return config.isAutoDataGravitation();
Modified: core/trunk/src/main/java/org/jboss/cache/commands/CommandsFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/CommandsFactory.java 2008-04-16 10:52:28 UTC (rev 5574)
+++ core/trunk/src/main/java/org/jboss/cache/commands/CommandsFactory.java 2008-04-16 13:32:22 UTC (rev 5575)
@@ -45,6 +45,16 @@
private RPCManager rpcManager;
private ComponentRegistry registry;
+ public CommandsFactory()
+ {
+ }
+
+ public CommandsFactory(RPCManager rpcManager, ComponentRegistry registry)
+ {
+ this.rpcManager = rpcManager;
+ this.registry = registry;
+ }
+
@Inject
public void initialize(RPCManager rpc, ComponentRegistry registry)
{
@@ -370,6 +380,19 @@
returnValue = new ClusteredGetCommand();
break;
+ // ---- Buddy replication - group organisation commands
+ case AnnounceBuddyPoolNameCommand.METHOD_ID:
+ returnValue = new AnnounceBuddyPoolNameCommand();
+ break;
+
+ case AssignToBuddyGroupCommand.METHOD_ID:
+ returnValue = new AssignToBuddyGroupCommand();
+ break;
+
+ case RemoveFromBuddyGroupCommand.METHOD_ID:
+ returnValue = new RemoveFromBuddyGroupCommand();
+ break;
+
default:
throw new CacheException("Unknown command id " + id + "!");
}
Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/ReplicateCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/ReplicateCommand.java 2008-04-16 10:52:28 UTC (rev 5574)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/ReplicateCommand.java 2008-04-16 13:32:22 UTC (rev 5575)
@@ -1,14 +1,13 @@
package org.jboss.cache.commands.remote;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.InvocationContext;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.commands.BaseCommand;
import org.jboss.cache.commands.CacheCommand;
import org.jboss.cache.commands.CommandsVisitor;
import org.jboss.cache.commands.cachedata.PutKeyValueCommand;
import org.jboss.cache.commands.functional.MarshallableCommand;
import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.invocation.InterceptorChain;
import org.jboss.cache.invocation.AbstractInvocationDelegate;
import java.util.List;
@@ -41,7 +40,14 @@
public ReplicateCommand(List<MarshallableCommand> modifications)
{
- this.modifications = modifications;
+ if (modifications != null && modifications.size() == 1)
+ {
+ singleModification = modifications.get(0);
+ }
+ else
+ {
+ this.modifications = modifications;
+ }
}
public ReplicateCommand(MarshallableCommand command)
@@ -88,7 +94,8 @@
}
else
{
- if (trace) log.trace("Caught an exception, but since this is a putForExternalRead() call, suppressing the exception. Exception is:", ex);
+ if (trace)
+ log.trace("Caught an exception, but since this is a putForExternalRead() call, suppressing the exception. Exception is:", ex);
result = null;
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-04-16 10:52:28 UTC (rev 5574)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-04-16 13:32:22 UTC (rev 5575)
@@ -276,11 +276,6 @@
return getOrCreateComponent(null, componentClass);
}
- public <T> T getOrCreateComponent(String componentName, Class<T> componentClass)
- {
- return getOrCreateComponent(componentName, componentClass, CONSTRUCTED);
- }
-
/**
* Retrieves a named component if one exists, and if not, attempts to find a factory capable of constructing the component
* (factories annotated with the {@link org.jboss.cache.factories.annotations.DefaultFactoryFor} annotation that is capable
@@ -297,11 +292,10 @@
*
* @param componentName name of component to be created. If null, uses the fully qualified class name as component name.
* @param componentClass type of component to be retrieved. Should not be null.
- * @param state state to move component to
* @return a fully wired component instance, or null if one cannot be found or constructed.
* @throws ConfigurationException if there is a problem with consructing or wiring the instance.
*/
- public <T> T getOrCreateComponent(String componentName, Class<T> componentClass, State state)
+ public <T> T getOrCreateComponent(String componentName, Class<T> componentClass)
{
T component = getComponent(componentName == null ? componentClass.getName() : componentName, componentClass);
@@ -333,9 +327,6 @@
}
}
- // guarantee state
-// Component c = componentLookup.get(componentName);
-// if (c != null) c.changeState(state);
return component;
}
@@ -444,13 +435,7 @@
public void unregisterComponent(String name)
{
Component c = componentLookup.remove(name);
- if (c != null)
- {
- c.changeState(c.state == STARTED ? STOPPED : CONSTRUCTED);
-
- c.dependencies.clear();
- c.dependencyFor.clear();
- }
+ if (c != null) c.changeState(c.state == STARTED ? STOPPED : CONSTRUCTED);
}
/**
@@ -835,26 +820,10 @@
{
if (d != null)
{
+ // always look up again in the component lookup. The dependencies and dependenciesFor sets are just
+ // used as references. The actual component instances may be out of date.
+ d = componentLookup.get(d.name);
- //if (d.instance == null)
- //{
- // this is a "hollow" component that has not been constructed yet. Another "constructed" version probably exists in the
- // componentLookup. Make sure we replace this.
- // always lookup from the component registry!!
- Component c = componentLookup.get(d.name);
- if (increase)
- {
- dependencies.remove(d);
- dependencies.add(c);
- }
- else
- {
- dependencyFor.remove(d);
- dependencies.add(c);
- }
- d = c;
- //}
-
if (d != null)
{
if (isShallowCyclic(d))
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2008-04-16 10:52:28 UTC (rev 5574)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2008-04-16 13:32:22 UTC (rev 5575)
@@ -49,7 +49,8 @@
this.rpcManager = rpcManager;
this.replicationQueue = replicationQueue;
this.buddyManager = buddyManager;
- usingBuddyReplication = buddyManager != null && buddyManager.isEnabled();
+// usingBuddyReplication = buddyManager != null && buddyManager.isEnabled();
+ usingBuddyReplication = config.getBuddyReplicationConfig() != null && config.getBuddyReplicationConfig().isEnabled();
CacheMode mode = config.getCacheMode();
defaultSynchronous = (mode == CacheMode.REPL_SYNC || mode == CacheMode.INVALIDATION_SYNC);
this.txTable = txTable;
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java 2008-04-16 10:52:28 UTC (rev 5574)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java 2008-04-16 13:32:22 UTC (rev 5575)
@@ -8,10 +8,12 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.commands.CommandsFactory;
+import org.jboss.cache.commands.cachedata.PutKeyValueCommand;
import org.jboss.cache.commands.functional.MarshallableCommand;
-import org.jboss.cache.commands.cachedata.PutKeyValueCommand;
import org.jboss.cache.commands.remote.ReplicateCommand;
import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.xml.XmlHelper;
import static org.testng.AssertJUnit.*;
@@ -26,12 +28,11 @@
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
*/
- at Test(groups = {"functional", "jgroups"})
+ at Test(groups = "functional")
public class BuddyManagerTest
{
+ private static final String DUMMY_LOCAL_ADDRESS = "myLocalAddress:12345";
- CommandsFactory commandsFactory = new CommandsFactory();
-
/**
* Constructs a buddy manager using the default buddy locator but with some specific properties.
*
@@ -124,6 +125,7 @@
Element element = XmlHelper.stringToElement("<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>");
BuddyReplicationConfig cfg = XmlConfigurationParser.parseBuddyReplicationConfig(element);
bm = new BuddyManager(cfg);
+ bm.initFqnTransformer(DUMMY_LOCAL_ADDRESS, new CommandsFactory(null, new ComponentRegistry(new Configuration())));
}
catch (Exception e)
{
@@ -136,17 +138,17 @@
{
Fqn fqn1 = Fqn.fromString("/hello/world");
- PutKeyValueCommand call1 = commandsFactory.buildPutKeyValueCommand(null, fqn1, "key", "value", false, false);
- ReplicateCommand call2 = commandsFactory.buildReplicateCommand(call1);
+ PutKeyValueCommand call1 = new PutKeyValueCommand(null, fqn1, "key", "value", false, false);
+ ReplicateCommand call2 = new ReplicateCommand(call1);
BuddyManager bm = createBasicBuddyManager();
ReplicateCommand newReplicatedCall = (ReplicateCommand) bm.transformFqns(call2);
- PutKeyValueCommand newPutCall = (PutKeyValueCommand) newReplicatedCall.getModifications().get(0);
+ PutKeyValueCommand newPutCall = (PutKeyValueCommand) newReplicatedCall.getSingleModification();
// should use object refs to transform the original MethodCall.
- String expected = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + null + "/hello/world";
- assertEquals(expected, newPutCall.getFqn().toString());
+ Fqn expected = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + DUMMY_LOCAL_ADDRESS + "/hello/world");
+ assertEquals(expected, newPutCall.getFqn());
}
@@ -154,16 +156,16 @@
{
Fqn fqn1 = Fqn.ROOT;
- MarshallableCommand call1 = commandsFactory.buildPutKeyValueCommand(null, fqn1, "key", "value", false, false);
- ReplicateCommand call2 = commandsFactory.buildReplicateCommand(call1);
+ MarshallableCommand call1 = new PutKeyValueCommand(null, fqn1, "key", "value", false, false);
+ ReplicateCommand call2 = new ReplicateCommand(call1);
BuddyManager bm = createBasicBuddyManager();
ReplicateCommand newReplicatedCall = (ReplicateCommand) bm.transformFqns(call2);
- PutKeyValueCommand newPutCall = (PutKeyValueCommand) newReplicatedCall.getModifications().get(0);
+ PutKeyValueCommand newPutCall = (PutKeyValueCommand) newReplicatedCall.getSingleModification();
// should use object refs to transform the original MethodCall.
- String expected = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + null;
+ String expected = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + DUMMY_LOCAL_ADDRESS;
assertEquals(expected, newPutCall.getFqn().toString());
}
@@ -174,17 +176,17 @@
Fqn fqn3 = Fqn.fromString("/hello/again");
Fqn fqn4 = Fqn.fromString("/buddy/replication");
- PutKeyValueCommand call1 = commandsFactory.buildPutKeyValueCommand(null, fqn1, "key", "value", false, false);
- PutKeyValueCommand call2 = commandsFactory.buildPutKeyValueCommand(null, fqn2, "key", "value", false, false);
- PutKeyValueCommand call3 = commandsFactory.buildPutKeyValueCommand(null, fqn3, "key", "value", false, false);
- PutKeyValueCommand call4 = commandsFactory.buildPutKeyValueCommand(null, fqn4, "key", "value", false, false);
+ PutKeyValueCommand call1 = new PutKeyValueCommand(null, fqn1, "key", "value", false, false);
+ PutKeyValueCommand call2 = new PutKeyValueCommand(null, fqn2, "key", "value", false, false);
+ PutKeyValueCommand call3 = new PutKeyValueCommand(null, fqn3, "key", "value", false, false);
+ PutKeyValueCommand call4 = new PutKeyValueCommand(null, fqn4, "key", "value", false, false);
List<MarshallableCommand> list = new ArrayList<MarshallableCommand>();
list.add(call1);
list.add(call2);
list.add(call3);
list.add(call4);
- ReplicateCommand call5 = commandsFactory.buildReplicateCommand(list);
+ ReplicateCommand call5 = new ReplicateCommand(list);
BuddyManager bm = createBasicBuddyManager();
@@ -192,13 +194,13 @@
List<MarshallableCommand> l = newReplicatedCall.getModifications();
// should use object refs to transform the original MethodCall.
- String expected = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/null";
+ String expected = "/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + DUMMY_LOCAL_ADDRESS;
int i = 0;
- assertEquals(expected, ((PutKeyValueCommand) l.get(i++)).getFqn());
- assertEquals(expected + "/hello/world", ((PutKeyValueCommand) l.get(i++)).getFqn());
- assertEquals(expected + "/hello/again", ((PutKeyValueCommand) l.get(i++)).getFqn());
- assertEquals(expected + "/buddy/replication", ((PutKeyValueCommand) l.get(i)).getFqn());
+ assertEquals(Fqn.fromString(expected), ((PutKeyValueCommand) l.get(i++)).getFqn());
+ assertEquals(Fqn.fromString(expected + "/hello/world"), ((PutKeyValueCommand) l.get(i++)).getFqn());
+ assertEquals(Fqn.fromString(expected + "/hello/again"), ((PutKeyValueCommand) l.get(i++)).getFqn());
+ assertEquals(Fqn.fromString(expected + "/buddy/replication"), ((PutKeyValueCommand) l.get(i)).getFqn());
}
public void testGetActualFqn()
More information about the jbosscache-commits
mailing list