[Mulgara-svn] r278 - in trunk: . src/jar/descriptor/src/java/org/mulgara/descriptor/test src/jar/resolver/java/org/mulgara/resolver src/jar/resolver-distributed/java/org/mulgara/resolver/distributed src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote src/jar/resolver-spi/java/org/mulgara/resolver/spi
pag at mulgara.org
pag at mulgara.org
Tue May 15 21:04:15 UTC 2007
Author: pag
Date: 2007-05-15 16:04:14 -0500 (Tue, 15 May 2007)
New Revision: 278
Added:
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/ForeignBlankNode.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/Config.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePager.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePagerImpl.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/SetProxy.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/ShortGlobalStatementSet.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/StatementSetFactory.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/TripleSetAdaptor.java
Removed:
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/Config.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePager.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePagerImpl.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/SetProxy.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/ShortGlobalStatementSet.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/StatementSetFactory.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/TripleSetAdaptor.java
Modified:
trunk/.classpath
trunk/.project
trunk/src/jar/descriptor/src/java/org/mulgara/descriptor/test/DescriptorUtilServiceTest.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/AnswerResolution.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/Delegator.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolver.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolverFactory.java
trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/NetworkDelegator.java
trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/LocalizedTuples.java
trunk/src/jar/resolver/java/org/mulgara/resolver/StringPoolSession.java
Log:
Added distributed resolver. Works, but insert/select suffers from MGR-54
Modified: trunk/.classpath
===================================================================
--- trunk/.classpath 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/.classpath 2007-05-15 21:04:14 UTC (rev 278)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/jar/ant-task/java"/>
+ <classpathentry kind="src" path="src/jar/resolver-distributed/java"/>
<classpathentry kind="src" path="src/jar/connector/java"/>
<classpathentry kind="src" path="src/war/webui/java"/>
<classpathentry kind="src" path="src/jar/doclet/java"/>
@@ -128,12 +129,12 @@
<classpathentry kind="lib" path="lib/xalan-2.7.0.jar"/>
<classpathentry kind="lib" path="lib/lucene-2.0.0.jar"/>
<classpathentry kind="lib" path="lib/jrdf-0.3.4.3.jar"/>
- <classpathentry kind="lib" path="lib/ant-trax-1.6.5.jar"/>
- <classpathentry kind="lib" path="lib/ant-nodeps-1.6.5.jar"/>
- <classpathentry kind="lib" path="lib/ant-launcher-1.6.5.jar"/>
- <classpathentry kind="lib" path="lib/ant-junit-1.6.5.jar"/>
- <classpathentry kind="lib" path="lib/ant-apache-bsf-1.6.5.jar"/>
- <classpathentry kind="lib" path="lib/ant-1.6.5.jar"/>
+ <classpathentry kind="lib" path="lib/ant-trax-1.7.0.jar"/>
+ <classpathentry kind="lib" path="lib/ant-nodeps-1.7.0.jar"/>
+ <classpathentry kind="lib" path="lib/ant-launcher-1.7.0.jar"/>
+ <classpathentry kind="lib" path="lib/ant-junit-1.7.0.jar"/>
+ <classpathentry kind="lib" path="lib/ant-apache-bsf-1.7.0.jar"/>
+ <classpathentry kind="lib" path="lib/ant-1.7.0.jar"/>
<classpathentry kind="lib" path="lib/DateUtils1.jar"/>
<classpathentry kind="output" path="obj/jar"/>
</classpath>
Modified: trunk/.project
===================================================================
--- trunk/.project 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/.project 2007-05-15 21:04:14 UTC (rev 278)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>Mulgara-1.2</name>
+ <name>Mulgara-1.0</name>
<comment></comment>
<projects>
</projects>
@@ -14,4 +14,11 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
+ <linkedResources>
+ <link>
+ <name>descriptor-client</name>
+ <type>2</type>
+ <location>obj/jar/descriptor-client</location>
+ </link>
+ </linkedResources>
</projectDescription>
Modified: trunk/src/jar/descriptor/src/java/org/mulgara/descriptor/test/DescriptorUtilServiceTest.java
===================================================================
--- trunk/src/jar/descriptor/src/java/org/mulgara/descriptor/test/DescriptorUtilServiceTest.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/descriptor/src/java/org/mulgara/descriptor/test/DescriptorUtilServiceTest.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -65,7 +65,8 @@
*/
public void test1DescriptorServiceInvokeToString() throws Exception {
- org.mulgara.descriptor.DescriptorServiceSoapBindingStub binding;
+ org.mulgara.descriptor.DescriptorServiceSoapBindingStub binding = null;
+ /*
try {
binding = (org.mulgara.descriptor.DescriptorServiceSoapBindingStub)
new org.mulgara.descriptor.DescriptorUtilServiceLocator().getDescriptorService();
@@ -75,6 +76,7 @@
jre.getLinkedCause().printStackTrace();
throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
}
+ */
assertNotNull("binding is null", binding);
// Time out after a minute
Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/StringPoolSession.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/StringPoolSession.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/StringPoolSession.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -129,6 +129,9 @@
/** Where to store literals which won't outlive this session. */
private final StringPool temporaryStringPool;
+
+ /** Maps blank nodes into remembered IDs. */
+ Map<BlankNode,Long> blankNodeCache = new HashMap<BlankNode,Long>();
private int state;
@@ -226,6 +229,7 @@
synchronized (this.globalLock) {
this.persistentStringPool.refresh();
this.persistentNodePool.refresh();
+ blankNodeCache.clear();
// !!Review: Call rollback on temporary? NB. Can't rollback non XA-SP/NP.
//this.temporaryStringPool.refresh();
//this.temporaryNodePool.refresh();
@@ -274,6 +278,7 @@
synchronized (globalLock) {
persistentStringPool.commit();
persistentNodePool.commit();
+ blankNodeCache.clear();
for (int i = 0; i < resources.length; i++) {
resources[i].commit();
}
@@ -292,6 +297,7 @@
state = ROLLBACK;
persistentStringPool.rollback();
persistentNodePool.rollback();
+ blankNodeCache.clear();
for (int i = 0; i < resources.length; i++) {
resources[i].rollback();
}
@@ -313,6 +319,8 @@
persistentStringPool.release();
persistentNodePool.release();
+ blankNodeCache.clear();
+
// TODO determine if release() should be called for the temp components.
//temporaryStringPool.release();
//temporaryNodePool.release();
@@ -470,8 +478,7 @@
// persisting.
if ((bi.getNodeId() < 0) && ((flags & STORE_MASK) == PERSIST)) {
bi.setNodeId(persistentNodePool.newNode());
- }
- else if (bi.getNodeId() == 0) {
+ } else if (bi.getNodeId() == 0) {
if ((flags & STORE_MASK) == TEMP) {
bi.setNodeId(-temporaryNodePool.newNode());
}
@@ -485,31 +492,42 @@
// id is negative.
throw new LocalizeException(node, "Attempt to persist a local blank " +
"node in a read phase");
- }
+ } else if ((flags & WRITE_MASK) == WRITE) {
// Some other implementation of BlankNode, so we can't access internal
// node ID and we can only create one - we must be in the WRITE phase.
- else if ((flags & WRITE_MASK) == WRITE) {
- long nodeId;
- if ((flags & STORE_MASK) == TEMP) {
- nodeId = -temporaryNodePool.newNode();
- } else {
- nodeId = persistentNodePool.newNode();
- }
+ return getAllocatedNodeId(node, flags);
- return nodeId;
- }
- // If it's a read phase and not the local BlankNode then throw an
- // exception.
- else {
+ } else {
+ // If it's a read phase and not the local BlankNode then throw an
+ // exception.
throw new LocalizeException(node, "Attempt to read BlankNode from stringpool");
}
- }
- catch (NodePoolException e) {
+ } catch (NodePoolException e) {
throw new LocalizeException(node, "Couldn't create blank node", e);
}
}
+ /**
+ * Allocates new node IDs for unknown nodes. Stores node IDs for later lookups.
+ * @param bn The blank node to get the ID for.
+ * @param flags Indicates the type of storage for the node ids.
+ * @return The node ID for this given blank node.
+ * @throws NodePoolException An error while allocating a new node.
+ */
+ protected long getAllocatedNodeId(BlankNode bn, int flags) throws NodePoolException {
+ assert !(bn instanceof BlankNodeImpl);
+ if (blankNodeCache.containsKey(bn)) return blankNodeCache.get(bn);
+ long nodeId;
+ if ((flags & STORE_MASK) == TEMP) {
+ nodeId = -temporaryNodePool.newNode();
+ } else {
+ nodeId = persistentNodePool.newNode();
+ }
+ blankNodeCache.put(bn, nodeId);
+ return nodeId;
+ }
+
protected Node globalizeBlankNode(long localNode, SPObject spObject) throws
GlobalizeException {
Modified: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/AnswerResolution.java
===================================================================
--- trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/AnswerResolution.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/AnswerResolution.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -14,26 +14,24 @@
import org.apache.log4j.Logger; // Apache Log4J
+import org.jrdf.graph.Node;
import org.mulgara.query.Answer;
import org.mulgara.query.Constraint;
-import org.mulgara.query.rdf.URIReferenceImpl;
+import org.mulgara.query.TuplesException;
+import org.mulgara.query.rdf.BlankNodeImpl;
-import org.mulgara.resolver.spi.GlobalizeException;
+import org.mulgara.resolver.spi.LocalizeException;
import org.mulgara.resolver.spi.LocalizedTuples;
import org.mulgara.resolver.spi.ResolverSession;
import org.mulgara.resolver.spi.Resolution;
-import org.mulgara.store.tuples.Annotation;
-import org.mulgara.store.tuples.RowComparator;
-import org.mulgara.store.tuples.Tuples;
+import java.net.URI;
/**
* A {@link Resolution} which extends a LocalizedTuples, which in turn wraps an Answer.
*
* @created 2007-03-23
* @author Paul Gearon
- * @version $Revision: $
- * @modified $Date: $ @maintenanceAuthor $Author: $
* @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
@@ -44,6 +42,9 @@
/** The constraint. */
private final Constraint constraint;
+
+ /** The server URI being accessed. */
+ private final URI serverUri;
/**
@@ -53,10 +54,13 @@
* @param constraint the constraint.
* @throws IllegalArgumentException if <var>constraint<var> is <code>null</code>
*/
- AnswerResolution(ResolverSession session, Answer answer, Constraint constraint) {
+ AnswerResolution(URI serverUri, ResolverSession session, Answer answer, Constraint constraint) {
super(session, answer);
+ logger.debug("Constructed AnswerResolution for distributed resolver");
if (constraint == null) throw new IllegalArgumentException("Null constraint parameter");
this.constraint = constraint;
+ this.serverUri = serverUri;
+ logger.debug("Created resolution on server: " + serverUri + " for: " + constraint);
}
@@ -76,4 +80,22 @@
return true;
}
+ /**
+ * Get the bound value for the column, converting Blank Nodes to a
+ * remote representation when needed.
+ * @param column The column of the bound value.
+ * @return the Localized long integer for the bound value.
+ * @throws TuplesException Indicates an error getting the value from the string pool.
+ */
+ public long getColumnValue(int column) throws TuplesException {
+ try {
+ Object obj = answer.getObject(column);
+ assert obj instanceof Node;
+
+ Node node = obj instanceof BlankNodeImpl ? new ForeignBlankNode(serverUri, (BlankNodeImpl)obj) : (Node)obj;
+ return session.localize(node);
+ } catch (LocalizeException e) {
+ throw new TuplesException("Couldn't localize column " + column, e);
+ }
+ }
}
Modified: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/Delegator.java
===================================================================
--- trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/Delegator.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/Delegator.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -15,6 +15,8 @@
import org.mulgara.query.Constraint;
import org.mulgara.query.LocalNode;
import org.mulgara.resolver.spi.Resolution;
+import org.mulgara.resolver.spi.ResolverException;
+import org.mulgara.resolver.spi.Statements;
import org.mulgara.query.QueryException;
@@ -36,6 +38,25 @@
* @param constraint The constraint to resolve.
* @param model The LocalNode containing the model
* @throws QueryException A delegator specific problem occurred resolving the constraint.
+ * @throws ResolverException A delegator specific problem occurred setting up the resolution.
*/
- public Resolution resolve(Constraint constraint, LocalNode model) throws QueryException;
+ public Resolution resolve(Constraint constraint, LocalNode model) throws QueryException, ResolverException;
+
+ /**
+ * Add a set of statements to a model.
+ * @param model The <code>long</code> containing the model gNode.
+ * @param statements The statements to add to the model.
+ * @throws ResolverException A delegator specific problem occurred adding the data.
+ * @throws QueryException There was an error adding data at the remote end.
+ */
+ public void add(long model, Statements statements) throws ResolverException, QueryException;
+
+ /**
+ * Remove a set of statements from a model.
+ * @param model The <code>long</code> containing the model gNode.
+ * @param statements The statements to remove from the model.
+ * @throws ResolverException A delegator specific problem occurred removing the data.
+ * @throws QueryException There was an error removing data at the remote end.
+ */
+ public void remove(long model, Statements statements) throws ResolverException, QueryException;
}
Modified: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolver.java
===================================================================
--- trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolver.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolver.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -13,7 +13,6 @@
package org.mulgara.resolver.distributed;
// Java 2 standard packages
-import java.io.*;
import java.net.*;
import java.util.*;
import javax.transaction.xa.XAResource;
@@ -41,15 +40,12 @@
*
* @created 2007-03-20
* @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
- * @version $Revision: $
- * @modified $Date: $
- * @maintenanceAuthor $Author: $
* @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public class DistributedResolver implements Resolver
-{
- /** Logger. */
+public class DistributedResolver implements Resolver {
+
+ /** Logger. */
private static Logger logger = Logger.getLogger(DistributedResolver.class.getName());
/** The delegator that resolves the constraint on another server. */
@@ -118,7 +114,13 @@
* @throws ResolverException The server should not ask this resolver to modify data.
*/
public void modifyModel(long model, Statements statements, boolean occurs) throws ResolverException {
- throw new ResolverException("Distributed models are read only");
+ if (logger.isDebugEnabled()) logger.debug(occurs ? "Adding" : "Removing" + " statements from model");
+ try {
+ if (occurs) delegator.add(model, statements);
+ else delegator.remove(model, statements);
+ } catch (QueryException qe) {
+ throw new ResolverException("Error modifying model", qe);
+ }
}
@@ -146,7 +148,11 @@
ConstraintElement modelElement = constraint.getElement(3);
if (!(modelElement instanceof LocalNode)) throw new QueryException("Constraint not set to a distributed model.");
- return delegator.resolve(constraint, (LocalNode)modelElement);
+ try {
+ return delegator.resolve(constraint, (LocalNode)modelElement);
+ } catch (ResolverException re) {
+ throw new QueryException(re.getMessage(), re);
+ }
}
Modified: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolverFactory.java
===================================================================
--- trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolverFactory.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolverFactory.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -14,8 +14,6 @@
package org.mulgara.resolver.distributed;
// Java 2 standard packages
-import java.io.*;
-import java.net.*;
import java.util.*;
// Third party packages
@@ -81,6 +79,7 @@
* {@inheritDoc ResolverFactory}
*/
public void close() {
+ logger.debug("Closing distributed resolvers");
for (DistributedResolver r: openResolvers) r.close();
}
@@ -100,6 +99,7 @@
* @throws InitializerException if the XML Schema resources can't be found or created
*/
public static ResolverFactory newInstance(ResolverFactoryInitializer initializer) throws InitializerException {
+ logger.debug("Creating new distributed resolver factory");
return new DistributedResolverFactory(initializer);
}
@@ -118,7 +118,8 @@
) throws ResolverFactoryException {
if (resolverSession == null) throw new IllegalArgumentException("No session provided for the resolver!");
- if (canWrite) throw new IllegalArgumentException("Cannot write to a remote model!");
+ logger.debug("Creating new distributed resolver");
+ if (canWrite) logger.debug("Expecting to write to distributed resolver.");
DistributedResolver r = new DistributedResolver(resolverSession);
openResolvers.add(r);
return r;
Copied: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/ForeignBlankNode.java (from rev 277, branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/ForeignBlankNode.java)
Modified: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/NetworkDelegator.java
===================================================================
--- trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/NetworkDelegator.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/NetworkDelegator.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -21,6 +21,7 @@
import org.mulgara.query.ModelResource;
import org.mulgara.query.Query;
import org.mulgara.query.QueryException;
+import org.mulgara.query.TuplesException;
import org.mulgara.query.UnconstrainedAnswer;
import org.mulgara.query.Variable;
import org.mulgara.query.rdf.URIReferenceImpl;
@@ -30,11 +31,14 @@
import org.mulgara.server.NonRemoteSessionException;
import org.mulgara.server.driver.SessionFactoryFinder;
import org.mulgara.server.driver.SessionFactoryFinderException;
+import org.mulgara.resolver.distributed.remote.StatementSetFactory;
import org.mulgara.resolver.spi.GlobalizeException;
import org.mulgara.resolver.spi.Resolution;
import org.mulgara.resolver.spi.ResolverException;
import org.mulgara.resolver.spi.ResolverSession;
+import org.mulgara.resolver.spi.Statements;
+import org.apache.log4j.Logger;
import org.jrdf.graph.Node;
import org.jrdf.graph.URIReference;
@@ -47,14 +51,14 @@
*
* @created 2007-03-20
* @author <a href="mailto:gearon at users.sourceforge.net">Paul Gearon</a>
- * @version $Revision: $
- * @modified $Date: $
- * @maintenanceAuthor $Author: $
* @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
public class NetworkDelegator implements Delegator {
+ /** Logger. */
+ private static Logger logger = Logger.getLogger(NetworkDelegator.class.getName());
+
/** The session to delegate resolutions through. */
private ResolverSession session;
@@ -82,29 +86,104 @@
* @param localConstraint The constraint to resolve in local form.
* @param localModel The LocalNode containing the model.
* @throws QueryException A error occurred resolving the constraint.
+ * @throws ResolverException A error occurred setting up the resolution.
*/
- public Resolution resolve(Constraint localConstraint, LocalNode localModel) throws QueryException {
+ public Resolution resolve(Constraint localConstraint, LocalNode localModel) throws QueryException, ResolverException {
// globalize the model
- Node modelNode = globalizeNode(localModel);
- if (!(modelNode instanceof URIReference)) throw new QueryException("Unexpected model type in constraint: (" + modelNode.getClass() + ")" + modelNode.toString());
- // convert the node to a URIReferenceImpl, which includes the Value interface
- URIReferenceImpl model = makeRefImpl((URIReference)modelNode);
+ URIReferenceImpl modelRef = getModelRef(localModel);
- // check if this model is really on a remote server
- URI modelUri = model.getURI();
- testForLocality(modelUri);
+ URI serverUri = getServerUri(modelRef);
+ logger.debug("Querying for: " + localConstraint + " in model: " + modelRef + " on server: " + serverUri);
- Answer ans = getModelSession(modelUri).query(globalizedQuery(localConstraint, model));
- return new AnswerResolution(session, ans, localConstraint);
+ Answer ans = getServerSession(serverUri).query(globalizedQuery(localConstraint, modelRef));
+ return new AnswerResolution(serverUri, session, ans, localConstraint);
}
/**
+ * Add a set of statements to a model.
+ * @param model The <code>long</code> containing the model gNode.
+ * @param statements The statements to add to the model.
+ * @throws ResolverException A delegator specific problem occurred adding the data.
+ * @throws QueryException There was an error adding data at the remote end.
+ */
+ public void add(long model, Statements statements) throws ResolverException, QueryException {
+ // globalize the model
+ URIReferenceImpl modelRef = getModelRef(model);
+ // find and verify the server
+ URI serverUri = getServerUri(modelRef);
+ logger.debug("Adding data to model: " + modelRef + " on server: " + serverUri);
+ // convert the data to something shippable
+ try {
+ Set statementSet = StatementSetFactory.newStatementSet(statements, session);
+ getServerSession(serverUri).insert(modelRef.getURI(), statementSet);
+ } catch (GlobalizeException ge) {
+ throw new ResolverException("Insertion data can't be sent over a network", ge);
+ } catch (TuplesException te) {
+ throw new ResolverException("Insertion data inaccessible", te);
+ }
+ }
+
+
+ /**
+ * Remove a set of statements from a model.
+ * @param model The <code>long</code> containing the model gNode.
+ * @param statements The statements to remove from the model.
+ * @throws ResolverException A delegator specific problem occurred removing the data.
+ * @throws QueryException There was an error removing data at the remote end.
+ */
+ public void remove(long model, Statements statements) throws ResolverException, QueryException {
+ // globalize the model
+ URIReferenceImpl modelRef = getModelRef(model);
+ // find and verify the server
+ URI serverUri = getServerUri(modelRef);
+ logger.debug("Removing data from model: " + modelRef + " on server: " + serverUri);
+ // convert the data to something shippable
+ try {
+ Set statementSet = StatementSetFactory.newStatementSet(statements, session);
+ getServerSession(serverUri).delete(modelRef.getURI(), statementSet);
+ } catch (GlobalizeException ge) {
+ throw new ResolverException("Deletion data can't be sent over a network", ge);
+ } catch (TuplesException te) {
+ throw new ResolverException("Deletion data inaccessible", te);
+ }
+ }
+
+
+ /**
+ * Convert a local node representing a model into a URIReferenceImpl.
+ * @param localModel The local node to convert.
+ * @return The URIReference for the model
+ * @throws ResolverException The Node was not recognized as a model.
+ */
+ protected URIReferenceImpl getModelRef(LocalNode localModel) throws ResolverException {
+ return getModelRef(localModel.getValue());
+ }
+
+
+ /**
+ * Convert a model gNode into a URIReferenceImpl.
+ * @param modelGNode The gNode to convert.
+ * @return The URIReference for the model
+ * @throws ResolverException The gNode was not recognized as a model.
+ */
+ protected URIReferenceImpl getModelRef(long modelGNode) throws ResolverException {
+ // globalize the model
+ Node modelNode = globalizeNode(modelGNode);
+ if (!(modelNode instanceof URIReference)) throw new ResolverException("Unexpected model type in constraint: (" + modelNode.getClass() + ")" + modelNode.toString());
+ // convert the node to a URIReferenceImpl, which includes the Value interface
+ return makeRefImpl((URIReference)modelNode);
+ }
+
+
+ /**
* Create a query for a single constraint.
* @param constraint The local constraint to query for.
* @return The globalized query, looking for the single constraint.
+ * @throws ResolverException There was an error globalizing the constraint elements.
*/
- protected Query globalizedQuery(Constraint localConstraint, URIReferenceImpl model) throws QueryException {
+ @SuppressWarnings("unchecked")
+ protected Query globalizedQuery(Constraint localConstraint, URIReferenceImpl model) throws ResolverException {
// convert the constraint to network compatible form
Constraint globalConstraint = new ConstraintImpl(
globalizeConstraintElement(localConstraint.getElement(0)),
@@ -113,7 +192,7 @@
model
);
- // convert the variable set to a variable list
+ // convert the variable set to a variable list - add types via unchecked casts
List<Variable> variables = new ArrayList<Variable>((Set<Variable>)globalConstraint.getVariables());
// build the new query
return new Query(variables, new ModelResource(model.getURI()), globalConstraint, null, Collections.EMPTY_LIST, null, 0, new UnconstrainedAnswer());
@@ -124,13 +203,24 @@
* Convert a local node to a global value.
* @param localNode The node to globalize.
* @return The globalized node, either a BlankNode, a URIReference, or a Literal.
+ * @throws ResolverException An error occurred while globalizing
+ */
+ protected Node globalizeNode(LocalNode localNode) throws ResolverException {
+ return globalizeNode(localNode.getValue());
+ }
+
+
+ /**
+ * Convert a gNode to a global node value.
+ * @param gNode The node id to globalize.
+ * @return The globalized node, either a BlankNode, a URIReference, or a Literal.
* @throws QueryException An error occurred while globalizing
*/
- protected Node globalizeNode(LocalNode localNode) throws QueryException {
+ protected Node globalizeNode(long gNode) throws ResolverException {
try {
- return session.globalize(localNode.getValue());
+ return session.globalize(gNode);
} catch (GlobalizeException ge) {
- throw new QueryException("Error globalizing node: " + localNode, ge);
+ throw new ResolverException("Error globalizing gNode: " + gNode, ge);
}
}
@@ -138,18 +228,14 @@
/**
* Converts a constraint element from local form into global form.
* @param localElement The constraint element in local form.
- * @throws QueryException The constraint element could not be globalized.
+ * @throws ResolverException The constraint element could not be globalized.
*/
- protected ConstraintElement globalizeConstraintElement(ConstraintElement localElement) throws QueryException {
+ protected ConstraintElement globalizeConstraintElement(ConstraintElement localElement) throws ResolverException {
// return the element if it does not need to be converted
if (!(localElement instanceof LocalNode) || (localElement instanceof URIReferenceImpl)) return localElement;
- // try {
- // convert the reference to a Value
- return makeRefImpl((URIReference)globalizeNode((LocalNode)localElement));
- // } catch (ResolverException re) {
- // throw new QueryException("Unable to globalize constraint element: " + localElement, re);
- // }
+ // convert the reference to a Value
+ return makeRefImpl((URIReference)globalizeNode((LocalNode)localElement));
}
@@ -167,9 +253,9 @@
/**
* Tests if a model is really on a different server. If the model is local then throw an exception.
* @param modelUri The URI of the model to test.
- * @throws QueryException Thrown when the model is on the current system.
+ * @throws ResolverException Thrown when the model is on the current system.
*/
- protected void testForLocality(URI modelUri) throws QueryException {
+ protected static void testForLocality(URI modelUri) throws ResolverException {
String protocol = modelUri.getScheme();
if (!DistributedResolverFactory.getProtocols().contains(protocol)) {
throw new IllegalStateException("Bad Protocol sent to distributed resolver.");
@@ -178,28 +264,30 @@
if (ServerInfo.getHostnameAliases().contains(host)) {
// on the same machine. Check if the server is different.
if (ServerInfo.getServerURI().getPath().equals(modelUri.getPath())) {
- throw new QueryException("Attempt to resolve a local model through the distributed resolver.");
+ throw new ResolverException("Attempt to resolve a local model through the distributed resolver.");
}
}
}
/**
- * Gets a remote session on a server specified by a given model URI.
- * @param modelUri The URI of the model to get a session for.
- * @return a remote session on the host found in the model.
- * @throws QueryException Thrown when the model is a bad URI, or the session cannot be created.
+ * Gets the URI for a server.
+ * @param modelUri The URI of the model we are getting the server for.
+ * @return A new URI containing just the server information.
+ * @throws ResolverException The model is not on a remote server.
*/
- protected Session getModelSession(URI modelUri) throws QueryException {
+ protected static URI getServerUri(URIReference model) throws ResolverException {
try {
+ // check if this model is really on a remote server
+ URI modelUri = model.getURI();
+ testForLocality(modelUri);
// use the URI without the model fragment
- return getServerSession(new URI(modelUri.getScheme(), modelUri.getSchemeSpecificPart(), null));
+ return new URI(modelUri.getScheme(), modelUri.getSchemeSpecificPart(), null);
} catch (URISyntaxException use) {
throw new AssertionError(use);
}
}
-
/**
* Retrieves a session for a given server URI, using a cached value if possible.
* @param serverUri The URI of the server to get a session for.
Copied: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote (from rev 277, branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote)
Deleted: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/Config.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/Config.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/Config.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -1,68 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.resolver.distributed.remote;
-
-/**
- * Defines a set of property names and default values for use with paged remote sets.
- *
- * @created 2007-04-23
- * @author <a href="mailto:gearon at users.sourceforge.net">Paul Gearon</a>
- * @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public class Config {
-
- /** Default maximum number of pages that may be queued. */
- private static final int DEFAULT_MAX_PAGES = 100;
-
- /** Name of the Maximum Pages property. */
- private static final String MAX_PAGES_PROPERTY = "pagedset.pages.max";
-
- /** Default maximum time to wait for a page to arrive, in milliseconds. */
- private static final long DEFAULT_TIMEOUT = 10000;
-
- /** Name of the timeout property. */
- private static final String TIMEOUT_PROPERTY = "pagedset.timeout";
-
- /** Default number of entries in a page. */
- private static final int DEFAULT_PAGE_SIZE = 128;
-
- /** Name of the page size property. */
- private static final String PAGE_SIZE_PROPERTY = "pagedset.pages.size";
-
-
- /**
- * Get the maximum number of pages to keep in memory at once.
- * @return The maximum number of pages to keep.
- */
- public static int getMaxPages() {
- return Integer.getInteger(MAX_PAGES_PROPERTY, DEFAULT_MAX_PAGES).intValue();
- }
-
- /**
- * Get the maximum time to wait for a page to arrive, in milliseconds.
- * @return The maximum timeout for a remote call.
- */
- public static long getTimeout() {
- return Long.getLong(TIMEOUT_PROPERTY, DEFAULT_TIMEOUT).longValue();
- }
-
- /**
- * Get the size of pages to transfer.
- * @return The number of entries in a page.
- */
- public static int getPageSize() {
- return Integer.getInteger(PAGE_SIZE_PROPERTY, DEFAULT_PAGE_SIZE).intValue();
- }
-
-}
Copied: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/Config.java (from rev 277, branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/Config.java)
Deleted: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePager.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePager.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePager.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -1,34 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.resolver.distributed.remote;
-
-import java.rmi.*;
-import java.io.Serializable;
-
-/**
- * The interface for paging an iterable object over RMI.
- * @param <E> The elements of the paged list.
- *
- * @created 2007-04-23
- * @author <a href="mailto:gearon at users.sourceforge.net">Paul Gearon</a>
- * @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public interface RemotePager<E extends Serializable> extends Remote {
-
- public int size() throws RemoteException;
-
- public E[] firstPage() throws RemoteException;
-
- public E[] nextPage() throws RemoteException;
-}
Copied: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePager.java (from rev 277, branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePager.java)
Deleted: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePagerImpl.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePagerImpl.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePagerImpl.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -1,126 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.resolver.distributed.remote;
-
-import java.util.*;
-import java.rmi.*;
-import java.lang.reflect.Array;
-import java.io.Serializable;
-import java.rmi.server.UnicastRemoteObject;
-import java.util.logging.*;
-
-/**
- * Implements the remote pager by iterating on a list and moving pages of elements over RMI.
- * @param <E> The elements of the paged list.
- *
- * @created 2007-04-23
- * @author <a href="mailto:gearon at users.sourceforge.net">Paul Gearon</a>
- * @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public class RemotePagerImpl<E extends Serializable> implements RemotePager<E> {
-
- /** Logger. */
- protected static final Logger logger = Logger.getLogger(RemotePagerImpl.class.getName());
-
- /** The type of the wrapped class. Used for creating pages of elements in arrays. */
- private Class<E> type;
-
- /** Stored size of the wrapped collection. */
- private final int size;
-
- /** The objects to page over RMI. */
- private Collection<E> collection;
-
- /** Internal iterator for the collection. */
- private Iterator<E> iter;
-
- /** The latest page of data. */
- private E[] currentPage;
-
- /** The size of a data page. */
- private final int pageSize = Config.getPageSize();
-
- /**
- * Creates a new remote paging object.
- * @param type The java.lang.Class of the elements to be paged.
- * @param collection The data to be paged.
- * @throws RemoteException If the data cannot be sent over RMI.
- */
- @SuppressWarnings("unchecked")
- public RemotePagerImpl(Class<E> type, Collection<E> collection) throws RemoteException {
- this.type = type;
- this.collection = collection;
- size = collection.size();
- iter = null;
- currentPage = (E[])Array.newInstance(type, pageSize);
- UnicastRemoteObject.exportObject(this);
- }
-
-
- /**
- * Gets the number of items in the underlying data.
- */
- public int size() {
- return size;
- }
-
-
- /**
- * Gets the first page of data as an array with length equal to the size of the page.
- * @return an array of elements.
- */
- public E[] firstPage() throws RemoteException {
- iter = collection.iterator();
- return fillPage();
- }
-
-
- /**
- * Gets the next page of data as an array with length equal to the size of the page.
- * @return an array of elements.
- */
- public E[] nextPage() throws RemoteException {
- return fillPage();
- }
-
-
- /**
- * Populates the current page with elements from the underlying collection.
- * @return The current page.
- */
- private E[] fillPage() {
- logger.finest("Filling page");
- for (int i = 0; i < pageSize; i++) {
- if (!iter.hasNext()) return truncatePage(i);
- currentPage[i] = iter.next();
- }
- return currentPage;
- }
-
-
- /**
- * Reduces the size of an array if there are fewer valid elements than the length of the array.
- * @param The size of the array.
- * @return A new current page.
- */
- @SuppressWarnings("unchecked")
- private E[] truncatePage(int offset) {
- if (offset == 0) return null;
- logger.finest("Building array of type: " + type +", with length: " + offset);
- E[] result = (E[])Array.newInstance(type, offset);
- System.arraycopy(currentPage, 0, result, 0, offset);
- return result;
- }
-
-}
Copied: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePagerImpl.java (from rev 277, branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePagerImpl.java)
Deleted: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/SetProxy.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/SetProxy.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/SetProxy.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -1,299 +0,0 @@
-package org.mulgara.resolver.distributed.remote;
-
-import java.util.*;
-import java.util.logging.*;
-import java.rmi.RemoteException;
-import java.io.Serializable;
-
-/**
- * Represents an iterable object on a remote system as a local Set.
- * Created at the server side, and sent across the network.
- */
-public class SetProxy<E extends Serializable> extends AbstractSet<E> implements Serializable {
-
- /** Serial ID for versioning. */
- private static final long serialVersionUID = -8343698708605937025L;
-
- /** Logger. */
- protected static final Logger logger = Logger.getLogger(RemotePagerImpl.class.getName());
-
- /** Stores the currently running iterator. */
- private static Object currentIterator = null;
-
- /** A pager for returning sequential pages of a remote collection. */
- private final RemotePager<E> remotePager;
-
- /** The size of the remote collection. */
- private final int cachedSize;
-
- /**
- * Creates a new proxy for a remote collection, meeting the Set interface.
- * @param remotePager A device for sending data from the remote collection one page at a time.
- */
- public SetProxy(RemotePager<E> remotePager) {
- this.remotePager = remotePager;
- // local call for size
- try {
- cachedSize = remotePager.size();
- } catch (RemoteException re) {
- throw new IllegalStateException("The proxy should be instantiated on the host side");
- }
- }
-
-
- /**
- * Returns the number of elements in the underlying collection.
- * @return The size of the collection.
- */
- public int size() {
- return cachedSize;
- }
-
-
- /**
- * Returns an iterator which will access all the remote data.
- * NOTE: The current implementation allows only one iterator to be active at a time!
- * @return A new iterator for the remote data.
- */
- public Iterator<E> iterator() {
- return new PagedIterator();
- }
-
-
- /**
- * An iterator class for traversing remote data. Network activity is reduced by moving
- * data in large pages at a time.
- */
- private class PagedIterator implements Iterator<E> {
-
- /** A thread for managing bringing the pages over the network. */
- private Pager pager;
-
- /** The most recent page of data. */
- private E[] currentPage;
-
- /** The current position in the current page of data. */
- int index;
-
- /**
- * Create a new iterator for traversing pages of data.
- */
- public PagedIterator() {
- currentPage = null;
- index = 0;
- currentIterator = this;
- logger.info("Starting pager");
- pager = new Pager();
- currentPage = pager.nextPage();
- logger.info("Started pager");
- }
-
-
- /**
- * Remove the current element from the data. Unsupported.
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
-
- /**
- * Queries the data to check if more data exists. Should not need to block.
- * @return <code>true</code> if more data exists.
- * @throws ConcurrentModificationException If more than one iterator is active.
- */
- public boolean hasNext() {
- logger.info("called SetProxy$Iterator.hasNext()");
- testState();
- if (currentPage != null && index < currentPage.length) return true;
- return currentPage != null;
- }
-
-
- /**
- * Returns the next element of the data. Will block until data is available.
- * @return The next item of data in sequence.
- * @throws ConcurrentModificationException If more than one iterator is active.
- */
- public E next() {
- logger.info("called SetProxy$Iterator.next()");
- testState();
- logger.info("Accessing element " + index + " of " + currentPage.length);
-
- if (currentPage != null && index < currentPage.length) return nextPageElement();
- return nextPageElement();
- }
-
-
- /**
- * Gets the next element out of the current page.
- * @return The next element from the current page.
- */
- private E nextPageElement() {
- logger.info("Getting next page element");
- E element = currentPage[index++];
- if (index == currentPage.length) updatePage();
- return element;
- }
-
-
- /**
- * Moves to the next page, if another page is available.
- */
- private void updatePage() {
- logger.info("Moving to next page");
- currentPage = pager.nextPage();
- index = 0;
- }
-
-
- /**
- * Check that this is the only iterator being accessed at the moment.
- * @throws ConcurrentModificationException If this iterator is being accessed
- * after a new iterator has been created.
- */
- private void testState() {
- if (currentIterator != this) {
- throw new ConcurrentModificationException("Unable to use more than one remote iterator on the set");
- }
- }
-
-
- /**
- * Private thread for getting the next page in the background.
- */
- private class Pager extends Thread {
-
- /** The maximum number of pages that may be queued. */
- private final int maxPages = Config.getMaxPages();
-
- /** Maximum time to wait for a page to arrive, in milliseconds. */
- private final long timeout = Config.getTimeout();
-
- /** Indicates that the thread has finished. */
- private boolean complete;
-
- /** The retrieved pages. */
- private Queue<E[]> retrievedPages;
-
- /** Stores exception when one occurs. */
- private PagerException lastException;
-
- /**
- * Initialize and start the thread.
- * Main thread.
- */
- public Pager() {
- lastException = null;
- retrievedPages = new LinkedList<E[]>();
- try {
- logger.info("Getting first page");
- E[] page = remotePager.firstPage();
- if (page != null) {
- logger.info("Got data in first page: size=" + page.length);
- retrievedPages.add(page);
- complete = false;
- start();
- } else logger.info("Empty initial page");
- } catch (RemoteException re) {
- throw new PagerException("Unable to get the first page", re);
- }
- }
-
-
- /**
- * Checks if the thread is active. Main thread.
- * @return <code>false</code> if the thread is still running, <code>true</code> when complete.
- */
- public boolean isComplete() {
- if (lastException != null) throw lastException;
- return complete;
- }
-
-
- /**
- * Pick up all the pages.
- * Runs in the background Paging thread.
- */
- public void run() {
- try {
- while (true) {
- synchronized (retrievedPages) {
- while (retrievedPages.size() >= maxPages) {
- try {
- logger.info("Waiting for queue to empty. Currently at: " + retrievedPages.size());
- retrievedPages.wait();
- } catch (InterruptedException ie) { }
- }
- }
- E[] page = remotePager.nextPage();
- if (page == null) {
- logger.info("Got final page");
- break;
- }
- logger.info("Got next page. size=" + page.length);
- synchronized (retrievedPages) {
- retrievedPages.add(page);
- logger.info("Queue now at " + retrievedPages.size() + " pages");
- }
- synchronized (this) {
- this.notify();
- }
- }
- } catch (RemoteException re) {
- logger.severe("Error retrieving remote data: " + re.getMessage());
- lastException = new PagerException("Unable to retrieve page", re);
- }
- complete = true;
- }
-
-
- /**
- * Get the next page, if available. The page will be an array of the configured length,
- * or shorter if it is the last page. If there is no more data, then <code>null</code>
- * will be returned.
- * Runs in the Main thread.
- * @return The next page of data, or <code>null</code> if no more data exists.
- */
- public E[] nextPage() {
- logger.info("Request for next page");
- if (lastException != null) throw lastException;
- E[] page;
- long startTime = System.currentTimeMillis();
- while (true) {
- synchronized (retrievedPages) {
- int oldSize = retrievedPages.size();
- logger.info("Queue has " + oldSize + " pages");
- page = retrievedPages.poll();
- if (oldSize >= maxPages) retrievedPages.notify();
- logger.info("page @" + page);
- }
- long waitTime = timeout + startTime - System.currentTimeMillis();
- if (waitTime <= 0) throw new PagerException("Timed out waiting for page");
- try {
- synchronized (this) {
- if (page == null && !complete) {
- logger.info("Waiting for more pages to arrive");
- this.wait(waitTime);
- } else break;
- }
- } catch (InterruptedException ie) { }
- if (System.currentTimeMillis() - startTime >= timeout) throw new PagerException("Timed out waiting for page");
- }
- logger.info("Returning page = " + page);
- return page;
- }
- }
- }
-
-
- /** Exception class for paging. Must be runtime so it can be thrown through Set interface. */
- @SuppressWarnings("serial")
- public static class PagerException extends RuntimeException {
- public PagerException() { }
- public PagerException(String message) { super(message); }
- public PagerException(String message, RemoteException cause) { super(message, cause); }
- public PagerException(RemoteException cause) { super(cause); }
- }
-}
-
Copied: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/SetProxy.java (from rev 277, branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/SetProxy.java)
Deleted: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/ShortGlobalStatementSet.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/ShortGlobalStatementSet.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/ShortGlobalStatementSet.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -1,87 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.resolver.distributed.remote;
-
-import java.io.Serializable;
-import java.util.AbstractSet;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.jrdf.graph.ObjectNode;
-import org.jrdf.graph.PredicateNode;
-import org.jrdf.graph.SubjectNode;
-import org.jrdf.graph.Triple;
-import org.mulgara.query.TuplesException;
-import org.mulgara.query.rdf.TripleImpl;
-import org.mulgara.resolver.spi.GlobalizeException;
-import org.mulgara.resolver.spi.ResolverSession;
-import org.mulgara.resolver.spi.Statements;
-
-/**
- * Creates a small Set of statements that be be shipped across a network.
- *
- * @created 2007-04-23
- * @author <a href="mailto:gearon at users.sourceforge.net">Paul Gearon</a>
- * @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public class ShortGlobalStatementSet extends AbstractSet<Triple> implements Serializable {
-
- /**
- * Allow newer compiled version of the stub to operate when changes
- * have not occurred with the class.
- * NOTE : update this serialVersionUID when a method or a public member is
- * deleted.
- */
- private static final long serialVersionUID = 896369800817370415L;
-
-
- /** Internally, use a list as this has a shorter serialization. */
- private ArrayList<Triple> data;
-
-
- /**
- * Builds the set of Triple data, containing globalized triples.
- * @param statements Contains the data for the set. This must not contain duplicates.
- * @throws TuplesException There was an error accessing the statements.
- * @throws GlobalizeException Some of the statements could not be globalized.
- */
- ShortGlobalStatementSet(Statements statements, ResolverSession session) throws TuplesException, GlobalizeException {
- // build the array
- long rowCount = statements.getRowCount();
- assert rowCount < StatementSetFactory.WATER_MARK;
- data = new ArrayList<Triple>((int)rowCount);
- // populate the array
- statements.beforeFirst();
- int i = 0;
- while (statements.next()) {
- Triple t = new TripleImpl(
- (SubjectNode)session.globalize(statements.getSubject()),
- (PredicateNode)session.globalize(statements.getPredicate()),
- (ObjectNode)session.globalize(statements.getObject())
- );
- data.set(i++, t);
- }
- }
-
- @Override
- public Iterator<Triple> iterator() {
- return data.iterator();
- }
-
- @Override
- public int size() {
- return data.size();
- }
-
-}
Copied: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/ShortGlobalStatementSet.java (from rev 277, branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/ShortGlobalStatementSet.java)
Deleted: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/StatementSetFactory.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/StatementSetFactory.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/StatementSetFactory.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -1,49 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- */
-
-package org.mulgara.resolver.distributed.remote;
-
-import java.rmi.RemoteException;
-import java.util.Set;
-
-import org.jrdf.graph.Triple;
-import org.mulgara.query.TuplesException;
-import org.mulgara.resolver.spi.GlobalizeException;
-import org.mulgara.resolver.spi.ResolverSession;
-import org.mulgara.resolver.spi.Statements;
-
-/**
- * Creates a Set of statements that be be shipped across a network.
- *
- * @created 2007-04-23
- * @author <a href="mailto:gearon at users.sourceforge.net">Paul Gearon</a>
- * @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public class StatementSetFactory {
-
- /** The size for transitioning between a serializable set and a remote set. */
- static final long WATER_MARK = 2048L;
-
- public static Set newStatementSet(Statements statements, ResolverSession session) throws TuplesException, GlobalizeException {
- // make sure the WATER_MARK refers to a set that is indexable by integer
- assert (long)(int)WATER_MARK == WATER_MARK;
- if (statements.getRowUpperBound() < WATER_MARK) return new ShortGlobalStatementSet(statements, session);
- try {
- RemotePager<Triple> pager = new RemotePagerImpl<Triple>(Triple.class, new TripleSetAdaptor(statements, session));
- return new SetProxy<Triple>(pager);
- } catch (RemoteException re) {
- throw new TuplesException("Error accessing remote data", re);
- }
- }
-}
Copied: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/StatementSetFactory.java (from rev 277, branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/StatementSetFactory.java)
Deleted: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/TripleSetAdaptor.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/TripleSetAdaptor.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/TripleSetAdaptor.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -1,116 +0,0 @@
-/*
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-
-package org.mulgara.resolver.distributed.remote;
-
-import java.util.AbstractSet;
-import java.util.Iterator;
-
-import org.jrdf.graph.ObjectNode;
-import org.jrdf.graph.PredicateNode;
-import org.jrdf.graph.SubjectNode;
-import org.jrdf.graph.Triple;
-import org.mulgara.query.TuplesException;
-import org.mulgara.query.rdf.TripleImpl;
-import org.mulgara.resolver.spi.GlobalizeException;
-import org.mulgara.resolver.spi.ResolverSession;
-import org.mulgara.resolver.spi.Statements;
-
-/**
- * Converts a StatementSet into a List of Triple.
- *
- * @created 2007-05-14
- * @author <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
- * @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public class TripleSetAdaptor extends AbstractSet<Triple> {
-
- /** The underlying set of statements. */
- private Statements statements;
-
- /** A ResolverSession for use in globalizing nodes. */
- private ResolverSession session;
-
- /**
- * Builds a new iterable List of Triple, based on a Statements.
- * @param statements The statements to adapt to a List.
- */
- public TripleSetAdaptor(Statements statements, ResolverSession session) {
- this.statements = statements;
- this.session = session;
- }
-
-
- @Override
- public int size() {
- try {
- long size = statements.getRowCount();
- return (long)(int)size == size ? (int)size : Integer.MAX_VALUE;
- } catch (TuplesException te) {
- throw new RuntimeException("Unable to get result size", te);
- }
- }
-
-
- @Override
- public Iterator<Triple> iterator() {
- return new TripleCursorIterator(statements);
- }
-
-
- /**
- * An iterator class for Cursor objects.
- */
- public class TripleCursorIterator implements Iterator<Triple> {
-
- /** The cursor to iterate on. */
- private Statements s;
-
- /** A flag to indicate if there is more data. */
- private boolean hasNext;
-
- TripleCursorIterator(Statements s) {
- this.s = s;
- try {
- hasNext = s.getRowCardinality() != 0;
- } catch (TuplesException te) {
- throw new RuntimeException("Unable to access result size", te);
- }
- }
-
- public boolean hasNext() {
- return hasNext;
- }
-
- public Triple next() {
- try {
- hasNext = s.next();
- return new TripleImpl(
- (SubjectNode)session.globalize(statements.getSubject()),
- (PredicateNode)session.globalize(statements.getPredicate()),
- (ObjectNode)session.globalize(statements.getObject())
- );
- } catch (TuplesException te) {
- throw new RuntimeException("Unable to access result data", te);
- } catch (GlobalizeException ge) {
- throw new RuntimeException("Unable to globalize result data", ge);
- }
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-
-
-}
Copied: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/TripleSetAdaptor.java (from rev 277, branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/TripleSetAdaptor.java)
Modified: trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/LocalizedTuples.java
===================================================================
--- trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/LocalizedTuples.java 2007-05-15 19:34:11 UTC (rev 277)
+++ trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/LocalizedTuples.java 2007-05-15 21:04:14 UTC (rev 278)
@@ -68,7 +68,7 @@
Logger.getLogger(LocalizedTuples.class.getName());
/** The session to localize into. */
- private final ResolverSession session;
+ protected final ResolverSession session;
/**
* The wrapped {@link Answer} instance.
More information about the Mulgara-svn
mailing list