[Mulgara-svn] r252 - in branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed: . rmi
pag at mulgara.org
pag at mulgara.org
Tue Apr 24 21:00:17 UTC 2007
Author: pag
Date: 2007-04-24 16:00:17 -0500 (Tue, 24 Apr 2007)
New Revision: 252
Added:
branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/
branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/ShortStatementSet.java
branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/StatementSetFactory.java
Modified:
branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/AnswerResolution.java
branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/Delegator.java
branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolver.java
branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolverFactory.java
branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/NetworkDelegator.java
Log:
Partial implementation to allow for remote inserts. Still need to create StatementSets
Modified: branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/AnswerResolution.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/AnswerResolution.java 2007-04-24 12:14:21 UTC (rev 251)
+++ branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/AnswerResolution.java 2007-04-24 21:00:17 UTC (rev 252)
@@ -58,6 +58,7 @@
*/
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;
Modified: branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/Delegator.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/Delegator.java 2007-04-24 12:14:21 UTC (rev 251)
+++ branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/Delegator.java 2007-04-24 21:00:17 UTC (rev 252)
@@ -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: branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolver.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolver.java 2007-04-24 12:14:21 UTC (rev 251)
+++ branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolver.java 2007-04-24 21:00:17 UTC (rev 252)
@@ -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: branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolverFactory.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolverFactory.java 2007-04-24 12:14:21 UTC (rev 251)
+++ branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/DistributedResolverFactory.java 2007-04-24 21:00:17 UTC (rev 252)
@@ -81,6 +81,7 @@
* {@inheritDoc ResolverFactory}
*/
public void close() {
+ logger.debug("Closing distributed resolvers");
for (DistributedResolver r: openResolvers) r.close();
}
@@ -100,6 +101,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 +120,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;
Modified: branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/NetworkDelegator.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/NetworkDelegator.java 2007-04-24 12:14:21 UTC (rev 251)
+++ branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/NetworkDelegator.java 2007-04-24 21:00:17 UTC (rev 252)
@@ -30,10 +30,14 @@
import org.mulgara.server.NonRemoteSessionException;
import org.mulgara.server.driver.SessionFactoryFinder;
import org.mulgara.server.driver.SessionFactoryFinderException;
+import org.mulgara.resolver.distributed.rmi.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;
@@ -46,14 +50,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;
@@ -81,30 +85,92 @@
* @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);
- URI serverUri = getServerUri(modelUri);
- Answer ans = getServerSession(serverUri).query(globalizedQuery(localConstraint, model));
+ 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
+ Set statementSet = StatementSetFactory.newStatementSet(statements);
+ getServerSession(serverUri).insert(modelRef.getURI(), statementSet);
+ }
+
+
+ /**
+ * 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
+ Set statementSet = StatementSetFactory.newStatementSet(statements);
+ getServerSession(serverUri).delete(modelRef.getURI(), statementSet);
+ }
+
+
+ /**
+ * 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)),
@@ -124,13 +190,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 +215,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 +240,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,7 +251,7 @@
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.");
}
}
}
@@ -188,11 +261,15 @@
* 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 static URI getServerUri(URI modelUri) {
- try {
+ 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 new URI(modelUri.getScheme(), modelUri.getSchemeSpecificPart(), null);
+ return new URI(modelUri.getScheme(), modelUri.getSchemeSpecificPart(), null);
} catch (URISyntaxException use) {
throw new AssertionError(use);
}
Added: branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/ShortStatementSet.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/ShortStatementSet.java 2007-04-24 12:14:21 UTC (rev 251)
+++ branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/ShortStatementSet.java 2007-04-24 21:00:17 UTC (rev 252)
@@ -0,0 +1,28 @@
+package org.mulgara.resolver.distributed.rmi;
+
+import java.util.AbstractSet;
+import java.util.Iterator;
+
+import org.mulgara.resolver.spi.Statements;
+
+public class ShortStatementSet extends AbstractSet {
+
+
+
+ public ShortStatementSet(Statements statements) {
+
+ }
+
+ @Override
+ public Iterator iterator() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int size() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+}
Added: branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/StatementSetFactory.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/StatementSetFactory.java 2007-04-24 12:14:21 UTC (rev 251)
+++ branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/rmi/StatementSetFactory.java 2007-04-24 21:00:17 UTC (rev 252)
@@ -0,0 +1,33 @@
+/*
+ * 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.rmi;
+
+import java.util.Set;
+
+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 {
+
+ public static Set newStatementSet(Statements statements) {
+ return null;
+ }
+}
More information about the Mulgara-svn
mailing list