gdamour 2004/03/24 03:42:57
Modified:
sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote/datastore
RemoteUseCaseTest.java
sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/local
AbstractUseCaseTest.java
sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore
GFileManagerClient.java GFileManagerProxy.java
sandbox/webdav/src/java/org/apache/geronimo/datastore/impl
AbstractGFileManager.java
sandbox/webdav/src/java/org/apache/geronimo/datastore
GFileManager.java
Log:
o GFileManagers can now be concurrently accessed: each operation
is related to an interaction, identified by an opaque object returned
when an interaction is started;
o GFileManagerClient and GFileManagerProxy have been updated in
order to leverage the base implementation for the Connector
contracts; and
o JUnit tests have been updated to also test the GBean configuration.
Revision Changes Path
1.3 +77 -24
incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote/datastore/RemoteUseCaseTest.java
Index: RemoteUseCaseTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote/datastore/RemoteUseCaseTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RemoteUseCaseTest.java 11 Mar 2004 15:36:13 -0000 1.2
+++ RemoteUseCaseTest.java 24 Mar 2004 11:42:57 -0000 1.3
@@ -21,18 +21,21 @@
import java.net.InetAddress;
import java.util.Collections;
+import javax.management.ObjectName;
+
import org.apache.geronimo.datastore.GFileManager;
import org.apache.geronimo.datastore.Util;
import org.apache.geronimo.datastore.impl.LockManager;
import org.apache.geronimo.datastore.impl.local.AbstractUseCaseTest;
import org.apache.geronimo.datastore.impl.local.LocalGFileManager;
-import
org.apache.geronimo.datastore.impl.remote.datastore.GFileManagerClient;
-import org.apache.geronimo.datastore.impl.remote.datastore.GFileManagerProxy;
+import org.apache.geronimo.datastore.impl.remote.messaging.Node;
+import org.apache.geronimo.datastore.impl.remote.messaging.NodeImpl;
import org.apache.geronimo.datastore.impl.remote.messaging.NodeInfo;
import org.apache.geronimo.datastore.impl.remote.messaging.Topology;
-import org.apache.geronimo.datastore.impl.remote.messaging.ServerNode;
import org.apache.geronimo.datastore.impl.remote.messaging.Topology.NodePath;
import
org.apache.geronimo.datastore.impl.remote.messaging.Topology.PathWeight;
+import org.apache.geronimo.gbean.jmx.GBeanMBean;
+import org.apache.geronimo.kernel.Kernel;
/**
* This is a remote use-case.
@@ -41,6 +44,27 @@
*/
public class RemoteUseCaseTest extends AbstractUseCaseTest {
+ private Kernel kernel1;
+ private ObjectName node1Name;
+ private ObjectName delegateName;
+ private ObjectName proxyName;
+
+ private Kernel kernel2;
+ private ObjectName node2Name;
+ private ObjectName clientName;
+
+ private void loadAndStart(Kernel kernel, ObjectName name, GBeanMBean
instance)
+ throws Exception {
+ kernel.loadGBean(name, instance);
+ kernel.startGBean(name);
+ }
+
+ private void unloadAndStop(Kernel kernel, ObjectName name)
+ throws Exception {
+ kernel.stopGBean(name);
+ kernel.unloadGBean(name);
+ }
+
/**
* In this set-up one initializes two nodes, namely Node1 and Node2. A
* local GFileManager is mounted by Node1. A client GFileManager is
mounted
@@ -48,37 +72,66 @@
*/
protected void setUp() throws Exception {
File root = new File(System.getProperty("java.io.tmpdir"),
- "GFileManager");
+ "GFileManager");
Util.recursiveDelete(root);
root.mkdir();
LockManager lockManager = new LockManager();
- GFileManager delegate;
- delegate = new LocalGFileManager("test", root, lockManager);
InetAddress address = InetAddress.getLocalHost();
- GFileManagerProxy proxy = new GFileManagerProxy(delegate);
- NodeInfo nodeInfo1 = new NodeInfo("Node1", address, 8080);
- ServerNode server1 = new ServerNode(nodeInfo1,
- Collections.singleton(proxy));
- server1.doStart();
- proxy.doStart();
-
- fileManager = new GFileManagerClient("test", nodeInfo1);
- NodeInfo nodeInfo2 = new NodeInfo("Node2", address, 8082);
- ServerNode server2 = new ServerNode(nodeInfo2,
- Collections.singleton(fileManager));
- server2.doStart();
- ((GFileManagerClient) fileManager).doStart();
+ NodeInfo node1Info = new NodeInfo("Node1", address, 8080);
+ NodeInfo node2Info = new NodeInfo("Node2", address, 8082);
+
+
+ // Set-up the first ServerNode.
+ kernel1 = new Kernel("test.kernel1", "test");
+ kernel1.boot();
+
+ node1Name = new ObjectName("geronimo.test:role=node1");
+ GBeanMBean node1GB = new GBeanMBean(NodeImpl.GBEAN_INFO);
+ node1GB.setAttribute("NodeInfo", node1Info);
+ delegateName = new ObjectName("geronimo.test:role=delegate");
+ GBeanMBean delegateGB = new GBeanMBean(LocalGFileManager.GBEAN_INFO);
+ delegateGB.setAttribute("Name", "FileSystem1");
+ delegateGB.setAttribute("Root", root);
+ delegateGB.setAttribute("LockManager", lockManager);
+ proxyName = new ObjectName("geronimo.test:role=proxy");
+ GBeanMBean proxyGB = new GBeanMBean(GFileManagerProxy.GBEAN_INFO);
+ proxyGB.setReferencePatterns("Delegate",
Collections.singleton(delegateName));
+ proxyGB.setReferencePatterns("Node",
+ Collections.singleton(node1Name));
+ loadAndStart(kernel1, delegateName, delegateGB);
+ loadAndStart(kernel1, proxyName, proxyGB);
+ loadAndStart(kernel1, node1Name, node1GB);
- server2.join(nodeInfo1);
+ // Set-up the second ServerNode.
+ kernel2 = new Kernel("test.kernel2", "test");
+ kernel2.boot();
+
+ node2Name = new ObjectName("geronimo.test:role=node2");
+ GBeanMBean node2GB = new GBeanMBean(NodeImpl.GBEAN_INFO);
+ node2GB.setAttribute("NodeInfo", node2Info);
+ clientName = new ObjectName("geronimo.test:role=client");
+ GBeanMBean clientGB = new GBeanMBean(GFileManagerClient.GBEAN_INFO);
+ clientGB.setAttribute("Name", "FileSystem1");
+ clientGB.setAttribute("HostingNode", node1Info);
+ clientGB.setReferencePatterns("Node",
+ Collections.singleton(node2Name));
+ loadAndStart(kernel2, clientName, clientGB);
+ loadAndStart(kernel2, node2Name, node2GB);
+ fileManager = (GFileManager) clientGB.getTarget();
+
+ Node node = (Node) node2GB.getTarget();
+ // The second ServerNode joins the first one.
+ node.join(node1Info);
Topology topology = new Topology();
PathWeight weight = new PathWeight(10);
- NodePath path = new NodePath(nodeInfo1, nodeInfo2, weight, weight);
+ NodePath path = new NodePath(node1Info, node2Info, weight, weight);
topology.addPath(path);
- server2.setTopology(topology);
- server1.setTopology(topology);
+
+ kernel1.setAttribute(node1Name, "Topology", topology);
+ kernel2.setAttribute(node2Name, "Topology", topology);
}
}
1.2 +11 -11
incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/local/AbstractUseCaseTest.java
Index: AbstractUseCaseTest.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/local/AbstractUseCaseTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractUseCaseTest.java 29 Feb 2004 13:14:11 -0000 1.1
+++ AbstractUseCaseTest.java 24 Mar 2004 11:42:57 -0000 1.2
@@ -40,16 +40,16 @@
byte[] content = "Dummy content".getBytes();
- fileManager.start();
- GFile file = fileManager.factoryGFile("test");
- fileManager.persistNew(file);
+ Object interactId = fileManager.startInteraction();
+ GFile file = fileManager.factoryGFile(interactId, "test");
+ fileManager.persistNew(interactId, file);
file.addProperty("name1", "value1");
file.addProperty("name2", "value2");
file.addProperty("name3", "value3");
file.setContent(new ByteArrayInputStream(content));
- fileManager.end();
+ fileManager.endInteraction(interactId);
- fileManager.start();
+ interactId = fileManager.startInteraction();
InputStream in = file.getInputStream();
int read;
int nbRead = 0;
@@ -64,17 +64,17 @@
assertEquals("Properties issue", "value3", properties.get("name3"));
file.addProperty("name4", "value4");
file.removeProperty("name3");
- fileManager.persistUpdate(file);
- fileManager.end();
+ fileManager.persistUpdate(interactId, file);
+ fileManager.endInteraction(interactId);
- fileManager.start();
+ interactId = fileManager.startInteraction();
properties = file.getProperties();
assertEquals("Properties issue", 3, properties.size());
assertEquals("Properties issue", "value1", properties.get("name1"));
assertEquals("Properties issue", "value2", properties.get("name2"));
assertEquals("Properties issue", "value4", properties.get("name4"));
- fileManager.persistDelete(file);
- fileManager.end();
+ fileManager.persistDelete(interactId, file);
+ fileManager.endInteraction(interactId);
}
}
1.5 +36 -75
incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore/GFileManagerClient.java
Index: GFileManagerClient.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore/GFileManagerClient.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- GFileManagerClient.java 11 Mar 2004 15:36:13 -0000 1.4
+++ GFileManagerClient.java 24 Mar 2004 11:42:57 -0000 1.5
@@ -22,23 +22,19 @@
import org.apache.geronimo.datastore.GFile;
import org.apache.geronimo.datastore.GFileManager;
import org.apache.geronimo.datastore.GFileManagerException;
+import org.apache.geronimo.datastore.impl.remote.messaging.AbstractConnector;
import org.apache.geronimo.datastore.impl.remote.messaging.CommandRequest;
import org.apache.geronimo.datastore.impl.remote.messaging.CommandResult;
import org.apache.geronimo.datastore.impl.remote.messaging.Connector;
import
org.apache.geronimo.datastore.impl.remote.messaging.HeaderOutInterceptor;
import org.apache.geronimo.datastore.impl.remote.messaging.Msg;
-import org.apache.geronimo.datastore.impl.remote.messaging.MsgBody;
-import org.apache.geronimo.datastore.impl.remote.messaging.MsgHeader;
import
org.apache.geronimo.datastore.impl.remote.messaging.MsgHeaderConstants;
-import org.apache.geronimo.datastore.impl.remote.messaging.MsgOutInterceptor;
+import org.apache.geronimo.datastore.impl.remote.messaging.Node;
import org.apache.geronimo.datastore.impl.remote.messaging.NodeInfo;
-import org.apache.geronimo.datastore.impl.remote.messaging.RequestSender;
-import org.apache.geronimo.datastore.impl.remote.messaging.ServerNodeContext;
+import org.apache.geronimo.datastore.impl.remote.messaging.NodeContext;
import org.apache.geronimo.gbean.GBean;
-import org.apache.geronimo.gbean.GBeanContext;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
-import org.apache.geronimo.gbean.WaitingException;
/**
* GFileManager mirroring a GFileManagerProxy mounted by a remote node.
@@ -49,6 +45,7 @@
* @version $Revision$ $Date$
*/
public class GFileManagerClient
+ extends AbstractConnector
implements GBean, GFileManager, Connector
{
@@ -65,37 +62,22 @@
private final NodeInfo node;
/**
- * Context of the ServerNode which has mounted this instance.
- */
- protected ServerNodeContext serverNodeContext;
-
- /**
- * Msg output to be used by this client to communicate with its proxy.
- */
- private MsgOutInterceptor out;
-
- /**
- * Requests sender.
- */
- private RequestSender sender;
-
- private GBeanContext context;
-
- /**
* Creates a client having the specified name. The name MUST be the name
* of the proxy to be mirrored.
*
* @param aName Name of the proxy to be mirrored.
- * @param aNodeName Name of the node hosting the proxy.
+ * @param aNode Node hosting the proxy.
*/
- public GFileManagerClient(String aName, NodeInfo aNode) {
+ public GFileManagerClient(Node aNode,
+ String aName, NodeInfo aNodeInfo) {
+ super(aNode);
if ( null == aName ) {
throw new IllegalArgumentException("Name is required.");
} else if ( null == aNode ) {
throw new IllegalArgumentException("Node is required.");
}
name = aName;
- node = aNode;
+ node = aNodeInfo;
}
public String getName() {
@@ -112,57 +94,48 @@
return node;
}
- public void start() {
- sender.sendSyncRequest(new CommandRequest("start", null), out, node);
+ public Object startInteraction() {
+ return sender.sendSyncRequest(
+ new CommandRequest("startInteraction", null), out, node);
}
- public GFile factoryGFile(String aPath) {
+ public GFile factoryGFile(Object anOpaque, String aPath) {
GFileStub result = (GFileStub)
sender.sendSyncRequest(
- new CommandRequest("factoryGFile", new Object[] {aPath}),
out,
+ new CommandRequest("factoryGFile",
+ new Object[] {anOpaque, aPath}), out,
node);
result.setGFileManagerClient(this);
return result;
}
- public void persistNew(GFile aFile) {
+ public void persistNew(Object anOpaque, GFile aFile) {
sender.sendSyncRequest(
- new CommandRequest("persistNew", new Object[] {aFile}), out,
node);
+ new CommandRequest("persistNew",
+ new Object[] {anOpaque, aFile}), out, node);
}
- public void persistUpdate(GFile aFile) {
+ public void persistUpdate(Object anOpaque, GFile aFile) {
sender.sendSyncRequest(
- new CommandRequest("persistUpdate", new Object[] {aFile}), out,
+ new CommandRequest("persistUpdate",
+ new Object[] {anOpaque, aFile}), out,
node);
}
- public void persistDelete(GFile aFile) {
+ public void persistDelete(Object anOpaque, GFile aFile) {
sender.sendSyncRequest(
- new CommandRequest("persistDelete", new Object[] {aFile}), out,
+ new CommandRequest("persistDelete",
+ new Object[] {anOpaque, aFile}), out,
node);
}
- public void end() throws GFileManagerException {
- sender.sendSyncRequest(new CommandRequest("end", null), out, node);
+ public void endInteraction(Object anOpaque) throws GFileManagerException
{
+ sender.sendSyncRequest(new CommandRequest("endInteraction",
+ new Object[] {anOpaque}), out, node);
}
- public void setGBeanContext(GBeanContext aContext) {
- context = aContext;
- }
-
- public void doStart() throws WaitingException, Exception {
- }
-
- public void doStop() throws WaitingException, Exception {
- }
-
- public void doFail() {
- }
-
- public void setContext(ServerNodeContext aContext) {
- serverNodeContext = aContext;
- sender = aContext.getRequestSender();
- out = aContext.getOutput();
+ public void setContext(NodeContext aContext) {
+ super.setContext(aContext);
if ( null != out ) {
out =
new HeaderOutInterceptor(
@@ -171,13 +144,8 @@
}
}
- public void deliver(Msg aMsg) {
- MsgHeader header = aMsg.getHeader();
- MsgBody body = aMsg.getBody();
-
- CommandResult result = (CommandResult) body.getContent();
- sender.setResponse(
- header.getHeader(MsgHeaderConstants.CORRELATION_ID), result);
+ protected void handleRequest(Msg aMsg) {
+ throw new IllegalArgumentException("Client-side does not handle
requests.");
}
/**
@@ -201,18 +169,11 @@
public static final GBeanInfo GBEAN_INFO;
static {
- GBeanInfoFactory factory = new
GBeanInfoFactory(GFileManagerClient.class);
+ GBeanInfoFactory factory = new
GBeanInfoFactory(GFileManagerClient.class, AbstractConnector.GBEAN_INFO);
factory.setConstructor(
- new String[] {"Name", "NodeName"},
- new Class[] {String.class, String.class});
- factory.addAttribute("Name", true);
- factory.addAttribute("NodeName", true);
- factory.addOperation("start");
- factory.addOperation("factoryGFile", new Class[]{String.class});
- factory.addOperation("persistNew", new Class[]{GFile.class});
- factory.addOperation("persistUpdate", new Class[]{GFile.class});
- factory.addOperation("persistDelete", new Class[]{GFile.class});
- factory.addOperation("end");
+ new String[] {"Node", "Name", "HostingNode"},
+ new Class[] {Node.class, String.class, NodeInfo.class});
+ factory.addAttribute("HostingNode", true);
GBEAN_INFO = factory.getBeanInfo();
}
1.4 +33 -57
incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore/GFileManagerProxy.java
Index: GFileManagerProxy.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore/GFileManagerProxy.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GFileManagerProxy.java 11 Mar 2004 15:36:13 -0000 1.3
+++ GFileManagerProxy.java 24 Mar 2004 11:42:57 -0000 1.4
@@ -25,6 +25,7 @@
import org.apache.geronimo.datastore.GFile;
import org.apache.geronimo.datastore.GFileManager;
import org.apache.geronimo.datastore.GFileManagerException;
+import org.apache.geronimo.datastore.impl.remote.messaging.AbstractConnector;
import org.apache.geronimo.datastore.impl.remote.messaging.CommandRequest;
import org.apache.geronimo.datastore.impl.remote.messaging.CommandResult;
import org.apache.geronimo.datastore.impl.remote.messaging.Connector;
@@ -34,12 +35,10 @@
import org.apache.geronimo.datastore.impl.remote.messaging.MsgHeader;
import
org.apache.geronimo.datastore.impl.remote.messaging.MsgHeaderConstants;
import org.apache.geronimo.datastore.impl.remote.messaging.MsgOutInterceptor;
-import org.apache.geronimo.datastore.impl.remote.messaging.ServerNodeContext;
+import org.apache.geronimo.datastore.impl.remote.messaging.Node;
import org.apache.geronimo.gbean.GBean;
-import org.apache.geronimo.gbean.GBeanContext;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
-import org.apache.geronimo.gbean.WaitingException;
/**
* It is a wrapper/proxy for a GFileManager, whose services need to be
exposed
@@ -48,6 +47,7 @@
* @version $Revision$ $Date$
*/
public class GFileManagerProxy
+ extends AbstractConnector
implements GBean, GFileManager, Connector
{
@@ -64,86 +64,62 @@
private final GFileManager fileManager;
/**
- * Context of the ServerNode which has mounted this instance.
- */
- protected ServerNodeContext serverNodeContext;
-
- /**
- * Output to be used by the proxy to communicate with the clients
mirroring
- * this proxy.
- */
- private MsgOutInterceptor out;
-
- /**
* It is a mapping of GFileStub identifiers to actual GFiles.
*/
private Map gFiles;
- private GBeanContext context;
-
/**
* Builds a proxy for the provided GFileManager.
*
+ * @param aNode Node containing this instance.
* @param aFileManager GFileManager to be proxied by this instance.
*/
- public GFileManagerProxy(GFileManager aFileManager) {
+ public GFileManagerProxy(Node aNode,
+ GFileManager aFileManager) {
+ super(aNode);
+ if ( null == aFileManager ) {
+ throw new IllegalArgumentException("GFileManager is required.");
+ }
fileManager = aFileManager;
gFiles = new HashMap();
gFileSeq = 0;
}
- public void setGBeanContext(GBeanContext aContext) {
- context = aContext;
- }
-
- public void doStart() throws WaitingException, Exception {
- }
-
- public void doStop() throws WaitingException, Exception {
- }
-
- public void doFail() {
- }
-
public String getName() {
return fileManager.getName();
}
- public GFile factoryGFile(String aPath) throws GFileManagerException {
- GFile gFile = fileManager.factoryGFile(aPath);
+ public GFile factoryGFile(Object anOpaque, String aPath)
+ throws GFileManagerException {
+ GFile gFile = fileManager.factoryGFile(anOpaque, aPath);
Integer id = registerGFile(gFile);
return new GFileStub(aPath, id);
}
- public void persistNew(GFile aFile) {
+ public void persistNew(Object anOpaque, GFile aFile) {
GFileStub stub = (GFileStub) aFile;
GFile actualGFile = retrieveGFile(stub.getID());
- fileManager.persistNew(actualGFile);
+ fileManager.persistNew(anOpaque, actualGFile);
}
- public void persistUpdate(GFile aFile) {
+ public void persistUpdate(Object anOpaque, GFile aFile) {
GFileStub stub = (GFileStub) aFile;
GFile actualGFile = retrieveGFile(stub.getID());
- fileManager.persistUpdate(actualGFile);
+ fileManager.persistUpdate(anOpaque, actualGFile);
}
- public void persistDelete(GFile aFile) {
+ public void persistDelete(Object anOpaque, GFile aFile) {
GFileStub stub = (GFileStub) aFile;
GFile actualGFile = retrieveGFile(stub.getID());
- fileManager.persistDelete(actualGFile);
+ fileManager.persistDelete(anOpaque, actualGFile);
}
- public void start() {
- fileManager.start();
+ public Object startInteraction() {
+ return fileManager.startInteraction();
}
- public void end() throws GFileManagerException {
- fileManager.end();
- }
-
- public void setContext(ServerNodeContext aContext) {
- serverNodeContext = aContext;
- out = aContext.getOutput();
+ public void endInteraction(Object anOpaque) throws GFileManagerException
{
+ fileManager.endInteraction(anOpaque);
}
/**
@@ -160,12 +136,12 @@
return aRequest.execute();
}
- public void deliver(Msg aMsg) {
+ protected void handleRequest(Msg aMsg) {
MsgHeader header = aMsg.getHeader();
MsgBody body = aMsg.getBody();
Object id = header.getHeader(MsgHeaderConstants.CORRELATION_ID);
- Object node = header.getHeader(MsgHeaderConstants.SRC_NODE);
+ Object srcNode = header.getHeader(MsgHeaderConstants.SRC_NODE);
CommandRequest command = (CommandRequest) body.getContent();
@@ -184,11 +160,12 @@
getName(),
new HeaderOutInterceptor(
MsgHeaderConstants.DEST_NODES,
- node,
+ srcNode,
out)));
reqOut.push(msg);
}
-
+
+
/**
* Registers a GFile.
*
@@ -225,12 +202,11 @@
public static final GBeanInfo GBEAN_INFO;
static {
- GBeanInfoFactory factory = new
GBeanInfoFactory(GFileManagerProxy.class);
+ GBeanInfoFactory factory = new
GBeanInfoFactory(GFileManagerProxy.class, AbstractConnector.GBEAN_INFO);
factory.setConstructor(
- new String[] {"Client"},
- new Class[] {GFileManager.class});
- factory.addReference("Client", GFileManager.class);
- factory.addAttribute("Name", true);
+ new String[] {"Node", "Delegate"},
+ new Class[] {Node.class, GFileManager.class});
+ factory.addReference("Delegate", GFileManager.class);
GBEAN_INFO = factory.getBeanInfo();
}
1.3 +59 -68
incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/AbstractGFileManager.java
Index: AbstractGFileManager.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/AbstractGFileManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractGFileManager.java 3 Mar 2004 13:10:07 -0000 1.2
+++ AbstractGFileManager.java 24 Mar 2004 11:42:57 -0000 1.3
@@ -19,9 +19,11 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.geronimo.datastore.GFile;
@@ -52,9 +54,14 @@
private final LockManager lockManager;
/**
- * State managers currently registered by this instance.
+ * Used to create interaction identifiers.
*/
- private final Set stateManagers;
+ private volatile int seqInterac = 0;
+
+ /**
+ * Interaction identifier to Set of StateManagers.
+ */
+ private final Map interToStateManagers;
/**
* Indicates if an interaction is started. We are between a start and a
@@ -86,7 +93,7 @@
}
name = aName;
lockManager = aLockManager;
- stateManagers = new HashSet();
+ interToStateManagers = new HashMap();
}
/**
@@ -98,7 +105,9 @@
return name;
}
- public GFile factoryGFile(String aPath) throws GFileManagerException {
+ public GFile factoryGFile(Object anOpaque, String aPath)
+ throws GFileManagerException {
+ retrieveStateManagers(anOpaque);
GFileImpl gFile;
try {
// TODO Refactor; this is too intertwined.
@@ -114,40 +123,43 @@
return gFile;
}
- public void persistNew(GFile aFile) {
- checkState(true);
+ public void persistNew(Object anOpaque, GFile aFile) {
+ Set stateManagers = retrieveStateManagers(anOpaque);
StateManager stateManager = ((GFileImpl)aFile).getStateManager();
stateManager.setIsNew(true);
stateManagers.add(stateManager);
}
- public void persistUpdate(GFile aFile) {
- checkState(true);
+ public void persistUpdate(Object anOpaque, GFile aFile) {
+ Set stateManagers = retrieveStateManagers(anOpaque);
StateManager stateManager = ((GFileImpl)aFile).getStateManager();
stateManager.setIsDirty(true);
stateManagers.add(stateManager);
}
- public void persistDelete(GFile aFile) {
- checkState(true);
+ public void persistDelete(Object anOpaque, GFile aFile) {
+ Set stateManagers = retrieveStateManagers(anOpaque);
StateManager stateManager = ((GFileImpl)aFile).getStateManager();
stateManager.setIsDelete(true);
stateManagers.add(stateManager);
}
- public void start() {
- switchState(true);
+ public Object startInteraction() {
+ Integer id = new Integer(seqInterac++);
+ synchronized (interToStateManagers) {
+ interToStateManagers.put(id, new HashSet());
+ }
+ return id;
}
- public void end() throws GFileManagerException {
- checkState(true);
+ public void endInteraction(Object anOpaque) throws GFileManagerException
{
+ Set stateManagers = retrieveStateManagers(anOpaque);
try {
- doInternalEnd();
+ doInteractionEnd(stateManagers);
} finally {
- synchronized(stateManagers) {
- stateManagers.clear();
+ synchronized(interToStateManagers) {
+ interToStateManagers.remove(anOpaque);
}
- switchState(false);
}
}
@@ -167,14 +179,17 @@
* If a StateManager is not able to prepare its state, all the previously
* StateManagers are unflushed.
*
+ * @param aStateManagers StateManagers related to the interaction
+ * being completed.
* @throws GFileManagerException Indicates that a StateManager is not
able
* to flush its state.
*/
- private void doInternalEnd() throws GFileManagerException {
+ private void doInteractionEnd(Set aStateManagers)
+ throws GFileManagerException {
List flushedManagers = new ArrayList();
try {
// Prepare all the state to be flushed.
- for (Iterator iter = stateManagers.iterator(); iter.hasNext();) {
+ for (Iterator iter = aStateManagers.iterator(); iter.hasNext();)
{
StateManager stateManager = (StateManager) iter.next();
flushedManagers.add(stateManager);
stateManager.prepare();
@@ -189,7 +204,7 @@
throw new GFileManagerException("Can not flush GFile", e);
}
// One can flush all the states.
- for (Iterator iter = stateManagers.iterator(); iter.hasNext();) {
+ for (Iterator iter = aStateManagers.iterator(); iter.hasNext();) {
StateManager stateManager = (StateManager) iter.next();
flushedManagers.add(stateManager);
stateManager.flush();
@@ -197,50 +212,26 @@
}
/**
- * Registers a new StateManagers for the current interaction.
- *
- * @param aStateManager StateManager to be registered.
- */
- protected void registerStateManager(StateManager aStateManager) {
- synchronized (stateManagers) {
- stateManagers.add(aStateManager);
- }
- }
-
- /**
- * Checks the state (inside a start/end call or not) of this instance.
+ * Retrieves the StateManagers related to the interaction identified by
+ * anOpaque.
*
- * @param anExpectedState Expected state.
- * @throws IllegalStateException Indicates that the current state is not
- * the expected one.
- */
- private final void checkState(boolean anExpectedState) {
- synchronized (stateLock) {
- if ( isStarted == anExpectedState ) {
- return;
- }
- throw new IllegalStateException(
- anExpectedState?"Already started":"Not yet started");
- }
- }
-
- /**
- * Switches the state of this instance.
- *
- * @param anExpectedState New state.
- * @throws IllegalStateException Indicates that the current state is not
- * compliant with the new state.
- */
- private final void switchState(boolean aTargetState) {
- synchronized (stateLock) {
- if ( isStarted == aTargetState ) {
+ * @param anOpaque An opaque object identifying the interaction whose
+ * StateManagers need to be retrieved.
+ * @throws IllegalStateException Indicates that the provided identifier
+ * does not define an interaction.
+ */
+ private final Set retrieveStateManagers(Object anOpaque) {
+ Set stateManagers;
+ synchronized (interToStateManagers) {
+ stateManagers = (Set) interToStateManagers.get(anOpaque);
+ if ( null == stateManagers ) {
throw new IllegalStateException(
- isStarted?"Already started":"Not yet started");
+ "Unknow interaction identifier.");
}
- isStarted = aTargetState;
}
+ return stateManagers;
}
-
+
public void setGBeanContext(GBeanContext context) {}
public void doStart() throws WaitingException, Exception{}
@@ -248,19 +239,19 @@
public void doStop() throws WaitingException, Exception {}
public void doFail() {};
-
+
public static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoFactory factory = new
GBeanInfoFactory(AbstractGFileManager.class);
factory.addAttribute("Name", true);
factory.addAttribute("LockManager", true);
- factory.addOperation("start");
- factory.addOperation("factoryGFile", new Class[]{String.class});
- factory.addOperation("persistNew", new Class[]{GFile.class});
- factory.addOperation("persistUpdate", new Class[]{GFile.class});
- factory.addOperation("persistDelete", new Class[]{GFile.class});
- factory.addOperation("end");
+ factory.addOperation("startInteraction");
+ factory.addOperation("factoryGFile", new Class[]{Object.class,
String.class});
+ factory.addOperation("persistNew", new Class[]{Object.class,
GFile.class});
+ factory.addOperation("persistUpdate", new Class[]{Object.class,
GFile.class});
+ factory.addOperation("persistDelete", new Class[]{Object.class,
GFile.class});
+ factory.addOperation("endInteraction", new Class[]{Object.class});
GBEAN_INFO = factory.getBeanInfo();
}
1.3 +20 -9
incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/GFileManager.java
Index: GFileManager.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/GFileManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- GFileManager.java 3 Mar 2004 13:10:07 -0000 1.2
+++ GFileManager.java 24 Mar 2004 11:42:57 -0000 1.3
@@ -40,53 +40,64 @@
/**
* Builds a GFile.
*
+ * @param anOpaque An opaque object identifying the interaction.
* @param aPath Path of the GFile.
* @return A GFile managed by this GFileManager.
* @throws GFileManagerException Indicates that the resource can not be
* created.
*/
- public GFile factoryGFile(String aPath) throws GFileManagerException;
+ public GFile factoryGFile(Object anOpaque, String aPath)
+ throws GFileManagerException;
/**
* Flags the provided GFile as new.
* <BR>
* This operation must be performed in the scope of a start/stop
sequence.
*
+ * @param anOpaque An opaque object identifying the interaction.
* @param aFile GFile to be created.
*/
- public void persistNew(GFile aFile);
+ public void persistNew(Object anOpaque, GFile aFile);
/**
* Flags the provided GFile as updated.
* <BR>
* This operation must be performed in the scope of a start/stop
sequence.
*
+ * @param anOpaque An opaque object identifying the interaction.
* @param aFile GFile to be updated.
*/
- public void persistUpdate(GFile aFile);
+ public void persistUpdate(Object anOpaque, GFile aFile);
/**
* Flags the provided GFile as deleted.
* <BR>
* This operation must be performed in the scope of a start/stop
sequence.
*
+ * @param anOpaque An opaque object identifying the interaction.
* @param aFile GFile to be deleted.
*/
- public void persistDelete(GFile aFile);
+ public void persistDelete(Object anOpaque, GFile aFile);
/**
* Starts an interaction with this manager. persistXXX operations must
* be performed in the scope of a start/end sequence.
+ *
+ * @return An opaque object identifying the interaction. This object must
+ * be provided to the persistXXX operations in order to relate an
operation
+ * to an interaction.
*/
- public void start();
+ public Object startInteraction();
/**
* Ends the interaction and "commits" all the updates performed between
- * the last start call and now to the underlying data store.
+ * the last startInteraction call and now to the underlying data store.
+ *
+ * @param anOpaque An opaque object identifying the interaction.
*
* @throws GFileManagerException Indicates a problem when "commiting" the
- * operations.
+ * operations.
*/
- public void end() throws GFileManagerException;
+ public void endInteraction(Object anOpaque) throws GFileManagerException;
}