Permalink
Browse files

rfe10505: use session to get new blankNodeIds

In Events.java:
Instead of using shared backends for queries, and dedicated
for add and delete phases, use dedicated for all.
Ensure connections are closed.
Count errors from threads and exit app with error if any.

tests-added:   none
tests-run:     prepush

<release-note>
rfe10505: use session to get new blankNodeIds

AGValueFactory was using the main repository url to get
blank node ids.  Use connection session instead if available.
Using the session can reduce load on the primary server.

If the ValueFactory was created by Repository instead
of RepositoryConnection, the old behavior remains.
</release-note>

Change-Id: If39bdc52ed4804e1bfb7e772a14e74e0f3aeb08c
Reviewed-on: https://gerrit.franz.com:9080/1258
Tested-by: Kevin Layer <layer@franz.com>
Reviewed-by: Kevin Layer <layer@franz.com>
  • Loading branch information...
1 parent 2280c13 commit 98190966ee56a698e5cb8f69ff25072131d930b7 Mike Hinchey committed with dklayer Mar 22, 2011
@@ -1783,4 +1783,13 @@ public void disableTripleCache() throws RepositoryException {
throw new RepositoryException(e);
}
}
+
+ public String[] getBlankNodes(int blankNodeAmount) throws RepositoryException {
+ try {
+ return getHTTPClient().getBlankNodes(getRoot(), blankNodeAmount);
+ } catch (IOException e) {
+ throw new RepositoryException(e);
+ }
+ }
+
}
@@ -107,11 +107,20 @@
private final AGAbstractRepository repository;
private final AGHttpRepoClient repoclient;
+ private final AGValueFactory vf;
- public AGRepositoryConnection(AGAbstractRepository repository, AGHttpRepoClient client) {
+ public AGRepositoryConnection(AGRepository repository, AGHttpRepoClient client) {
super(repository);
this.repository = repository;
this.repoclient = client;
+ vf = new AGValueFactory(repository, this);
+ }
+
+ public AGRepositoryConnection(AGVirtualRepository repository, AGHttpRepoClient client) {
+ super(repository);
+ this.repository = repository;
+ this.repoclient = client;
+ vf = new AGValueFactory(repository.wrapped, this);
}
/*
@@ -130,7 +139,7 @@ public AGHttpRepoClient getHttpRepoClient() {
@Override
public AGValueFactory getValueFactory() {
- return getRepository().getValueFactory();
+ return vf;
}
@Override
@@ -1207,4 +1216,5 @@ public int getUploadCommitPeriod() throws RepositoryException {
return getHttpRepoClient().getUploadCommitPeriod();
}
+
}
@@ -29,6 +29,7 @@
public class AGValueFactory extends ValueFactoryImpl {
private final AGRepository repository;
+ private final AGRepositoryConnection conn;
private int blankNodeAmount = 100;
private String[] blankNodeIds;
@@ -37,7 +38,13 @@
public AGValueFactory(AGRepository repository) {
super();
this.repository = repository;
- blankNodeIds = new String[blankNodeAmount];
+ this.conn = null;
+ }
+
+ public AGValueFactory(AGRepository repository, AGRepositoryConnection conn) {
+ super();
+ this.repository = repository;
+ this.conn = conn;
}
public AGRepository getRepository() {
@@ -50,15 +57,19 @@ public AGHTTPClient getHTTPClient() {
private void getBlankNodeIds() {
try {
- blankNodeIds = getHTTPClient().getBlankNodes(getRepository().getRepositoryURL(),blankNodeAmount);
+ if (conn == null) {
+ blankNodeIds = getHTTPClient().getBlankNodes(getRepository().getRepositoryURL(), blankNodeAmount);
+ } else {
+ blankNodeIds = conn.getHttpRepoClient().getBlankNodes(blankNodeAmount);
+ }
index = blankNodeIds.length - 1;
} catch (UnauthorizedException e) {
// TODO: check on the proper exceptions to throw here
throw new IllegalStateException(e);
- } catch (IOException e) {
- throw new IllegalStateException(e);
} catch (RepositoryException e) {
throw new IllegalStateException(e);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
}
}
@@ -10,10 +10,10 @@
import com.franz.util.Closeable;
public class AGVirtualRepository implements AGAbstractRepository, Closeable {
- private AGServer server;
- private AGRepository wrapped;
- private String spec;
- private AGValueFactory vf;
+ private final AGServer server;
+ final AGRepository wrapped;
+ private final String spec;
+ private final AGValueFactory vf;
public AGVirtualRepository(AGServer server, String spec, AGRepository wrapped) {
this.server = server;
@@ -151,7 +151,7 @@ public void tearDown() throws Exception {
@AfterClass
public static void tearDownOnce() throws Exception {
cat = null;
- server = Closer.close(server);
+ server = Util.close(server);
}
AGRepositoryConnection getConnection() throws RepositoryException {
@@ -290,7 +290,7 @@ public static void printRows(CloseableIteration rows) throws Exception {
while (rows.hasNext()) {
println(rows.next());
}
- close(rows);
+ Util.close(rows);
}
public static void printRows(String headerMsg, int limit, CloseableIteration rows) throws Exception {
@@ -301,7 +301,7 @@ public static void printRows(String headerMsg, int limit, CloseableIteration row
count++;
}
println("Number of results: " + count);
- close(rows);
+ Util.close(rows);
}
// static void close(RepositoryConnection conn) {
View
@@ -1,7 +1,6 @@
package test;
-import info.aduna.iteration.CloseableIteration;
-
+import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
@@ -29,50 +28,31 @@ Obj closeLater(Obj o) {
* Must be called in a finally block, to close all resources
* added with closeLater().
*/
+ @Override
public void close() {
while (toClose.isEmpty() == false) {
- Object o = toClose.get(0);
- close(o);
- while (toClose.remove(o)) {
- }
+ close( toClose.get(0) );
}
}
-
+
/**
- * TODO: move to com.franz.util.Util
+ * Close all objects immediately, will not be closed "later".
*/
- public static <Elem extends Object, Exc extends Exception>
- CloseableIteration<Elem, Exc> close(CloseableIteration<Elem, Exc> o) {
- if (o != null) {
- try {
- o.close();
- } catch (Exception e) {
- System.err.println("ignoring error with close:" + e);
- e.printStackTrace();
- }
- }
- return null;
+ public Collection closeAll(Collection objects) {
+ for (Object object : objects) {
+ close(object);
+ }
+ return null;
}
/**
- * TODO: move to com.franz.util.Util
+ * Close an object immediately, will not be closed "later".
*/
- public static <Obj extends Object>
+ public <Obj extends Object>
Obj close(Obj o) {
- if (o instanceof Closeable) {
- com.franz.util.Util.close((Closeable)o);
- } else if (o instanceof java.io.Closeable) {
- com.franz.util.Util.close((java.io.Closeable)o);
- } else if (o instanceof CloseableIteration) {
- close((CloseableIteration)o);
- } else if (o != null) {
- try {
- o.getClass().getMethod("close").invoke(o);
- } catch (Exception e) {
- System.err.println("ignoring error with close:" + e);
- e.printStackTrace();
- }
- }
+ test.Util.close(o);
+ while (toClose.remove(o)) {
+ }
return null;
}
View
@@ -8,6 +8,8 @@
package test;
+import info.aduna.iteration.CloseableIteration;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@@ -19,6 +21,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Random;
import java.util.zip.GZIPOutputStream;
import com.franz.util.Closeable;
@@ -33,11 +36,33 @@ public static String get(String[] arr, int i, String defaultVal) {
return defaultVal;
}
- public static Object close(Object o) {
+ /**
+ * TODO: move to com.franz.util.Util
+ */
+ public static <Elem extends Object, Exc extends Exception>
+ CloseableIteration<Elem, Exc> close(CloseableIteration<Elem, Exc> o) {
+ if (o != null) {
+ try {
+ o.close();
+ } catch (Exception e) {
+ System.err.println("ignoring error with close:" + e);
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * TODO: move to com.franz.util.Util
+ */
+ public static <Obj extends Object>
+ Obj close(Obj o) {
if (o instanceof Closeable) {
- close((Closeable)o);
+ com.franz.util.Util.close((Closeable)o);
} else if (o instanceof java.io.Closeable) {
- close((java.io.Closeable)o);
+ com.franz.util.Util.close((java.io.Closeable)o);
+ } else if (o instanceof CloseableIteration) {
+ close((CloseableIteration)o);
} else if (o != null) {
try {
o.getClass().getMethod("close").invoke(o);
@@ -200,5 +225,5 @@ public static List reverse(List list) {
Collections.reverse(list);
return list;
}
-
+
}
Oops, something went wrong.

0 comments on commit 9819096

Please sign in to comment.