Permalink
Browse files

rfe10512: Java JNDI connection pool

This is a new, optional feature, has no impact for
existing users. Tested for functionality and performance
with an uncommitted change to Events.java.

tests-added:   none
tests-run:     prepush, manual test with tomcat, glassfish
performance:   no impact

<release-notes>
rfe10512: Java JNDI connection pool

Implements Pool for AllegroGraph using Apache-Commons-Pool.

Implements JNDI ObjectFactory to provide a
connection pool to AllegroGraph server.

See javadocs for package: com.franz.agraph.pool.
</release-notes>

Change-Id: I2afbc0bce37db9afb5b3c11004a73012b81188e6
Reviewed-on: https://gerrit.franz.com:9080/1588
Reviewed-by: Kevin Layer <layer@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
  • Loading branch information...
1 parent 21db3ea commit 50ae9c2d55207b5157fb6dd010ede3e2d18fbdcb Mike Hinchey committed with dklayer Sep 29, 2011
View
@@ -20,5 +20,7 @@
<classpathentry kind="lib" path="lib/logging/commons-logging-1.1.1.jar" sourcepath="lib/logging/commons-logging-1.1.1-sources.jar"/>
<classpathentry kind="lib" path="lib/logging/slf4j-api-1.6.1.jar" sourcepath="lib/logging/slf4j-api-1.6.1-sources.jar"/>
<classpathentry kind="lib" path="lib/logging/slf4j-jcl-1.6.1.jar" sourcepath="lib/logging/slf4j-jcl-1.6.1-sources.jar"/>
+ <classpathentry kind="lib" path="lib/servlet-api-2.5.jar"/>
+ <classpathentry kind="lib" path="lib/commons-pool-1.5.6.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
@@ -52,6 +52,8 @@
<path location="${lib}/jena-2.6.2/wstx-asl-3.2.9.jar"/>
<path location="${lib}/jena-2.6.2/xercesImpl-2.7.1.jar"/>
<path location="${lib}/commons-cli-1.2.jar"/>
+ <path location="${lib}/commons-pool-1.5.6.jar"/>
+ <path location="${lib}/servlet-api-2.5.jar"/>
</path>
<target name="init">
@@ -172,7 +174,7 @@
noindex="false"
nonavbar="false"
notree="false"
- packagenames="com.franz.agraph.jena,com.franz.agraph.repository,com.franz.openrdf.rio.nquads,com.franz.util"
+ packagenames="com.franz.agraph.jena,com.franz.agraph.repository,com.franz.openrdf.rio.nquads,com.franz.util,com.franz.agraph.pool"
source="1.6"
sourcepath="src"
splitindex="true"
@@ -434,5 +436,17 @@
<pom refid="sesame"/>
</artifact:install>
</target>
+
+ <target name="test-war"
+ depends="compile"
+ description="builds agraph-test.war">
+ <war destfile="target/agraph-test.war"
+ webxml="src/test/web/web.xml">
+ <classes dir="classes" includes="**/*"/>
+ <lib dir="lib" includes="*.jar" excludes="servlet-api-2.5.jar"/>
+ <lib dir="lib/sesame-2.3.2" includes="*.jar"/>
+ <lib dir="lib/logging" includes="*.jar"/>
+ </war>
+ </target>
</project>
View
@@ -2,7 +2,10 @@
java -cp classes:agraph.jar\
:lib/commons-cli-1.2.jar\
-:lib/sesame-2.3.2/*\
+:lib/commons-pool-1.5.6.jar\
+:lib/sesame-2.3.2/commons-codec-1.3.jar\
+:lib/sesame-2.3.2/commons-httpclient-3.1.jar\
+:lib/sesame-2.3.2/openrdf-sesame-2.3.2-onejar.jar\
:lib/logging/*\
:lib/json.jar\
test.stress.Events $*
Binary file not shown.
Binary file not shown.
View
@@ -73,6 +73,7 @@ endif
cp agraph.jar $(DIST)/lib/agraph-$(VERSION).jar
cp agraph-src.jar $(DIST)/lib/agraph-$(VERSION)-src.jar
cp lib/json.jar $(DIST)/lib/json.jar
+ cp lib/commons-pool-1.5.6.jar $(DIST)/lib/commons-pool-1.5.6.jar
mkdir -p $(DIST)/lib/logging
cp lib/logging/*.jar $(DIST)/lib/logging
mkdir -p $(DIST)/lib/sesame-2.3.2
@@ -6,9 +6,6 @@
** http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
-/**
- *
- */
package com.franz.agraph.http;
import static com.franz.agraph.http.AGProtocol.AMOUNT_PARAM_NAME;
@@ -64,7 +61,7 @@
private final HttpClient httpClient;
private AuthScope authScope;
- final Logger logger = LoggerFactory.getLogger(this.getClass());
+ private static final Logger logger = LoggerFactory.getLogger(AGHTTPClient.class);
private MultiThreadedHttpConnectionManager mManager = null;
@@ -87,6 +84,15 @@ public AGHTTPClient(String serverURL, HttpConnectionManager manager) {
manager.setParams(params);
}
httpClient = new HttpClient(manager);
+ logger.debug("connect: " + serverURL + " " + httpClient + " " + manager);
+ }
+
+ @Override
+ public String toString() {
+ return "{" + super.toString()
+ + " " + serverURL
+ + " " + httpClient
+ + "}";
}
public String getServerURL() {
@@ -356,9 +362,9 @@ public String getString(String url) throws AGHttpException {
try {
get(url, headers, data, handler);
} catch (RepositoryException e) {
- throw new AGHttpException(e.getMessage());
+ throw new AGHttpException(e);
} catch (IOException e) {
- throw new AGHttpException(e.getMessage());
+ throw new AGHttpException(e);
}
return handler.getString();
}
@@ -384,7 +390,12 @@ public String openSession(String spec, boolean autocommit) throws RepositoryExce
@Override
public void close() {
- Util.close(this.mManager);
+ logger.debug("close: " + serverURL + " " + mManager);
+ mManager = Util.close(mManager);
+ }
+
+ boolean isClosed() {
+ return mManager == null;
}
public String[] generateURIs(String repositoryURL, String namespace,
@@ -10,9 +10,6 @@
public class AGHttpException extends Exception {
- /**
- *
- */
private static final long serialVersionUID = -2608901334300829491L;
private final AGErrorInfo errorInfo;
@@ -27,6 +24,15 @@ public AGHttpException(String message) {
errorInfo = new AGErrorInfo(message);
}
+ public AGHttpException(String message, Throwable cause) {
+ super(message, cause);
+ errorInfo = new AGErrorInfo(message);
+ }
+
+ public AGHttpException(Throwable cause) {
+ this(cause.getMessage(), cause);
+ }
+
public AGErrorInfo getErrorInfo() {
return errorInfo;
}
@@ -123,6 +123,15 @@ public AGHttpRepoClient(Repository repo, AGHTTPClient client, String repoRoot, S
this.client = client;
savedQueryDeleteQueue = new ConcurrentLinkedQueue<String>();
}
+
+ @Override
+ public String toString() {
+ return "{" + super.toString()
+ + " " + client
+ + " rr=" + repoRoot
+ + " sr=" + sessionRoot
+ + "}";
+ }
public String getRoot() throws RepositoryException {
if (sessionRoot != null) return sessionRoot;
@@ -276,7 +285,7 @@ private void useDedicatedSession(boolean autoCommit)
private void closeSession(String sessionRoot) throws IOException,
RepositoryException, UnauthorizedException {
- if (sessionRoot != null) {
+ if (sessionRoot != null && !getHTTPClient().isClosed()) {
String url = AGProtocol.getSessionCloseLocation(sessionRoot);
Header[] headers = new Header[0];
NameValuePair[] params = new NameValuePair[0];
@@ -932,7 +941,7 @@ public void deleteSavedQuery(String queryName) throws RepositoryException {
}
}
- public void close() throws RepositoryException {
+ public synchronized void close() throws RepositoryException {
if (sessionRoot != null) {
try {
closeSession(sessionRoot);
@@ -0,0 +1,58 @@
+/******************************************************************************
+** Copyright (c) 2008-2011 Franz Inc.
+** All rights reserved. This program and the accompanying materials
+** are made available under the terms of the Eclipse Public License v1.0
+** which accompanies this distribution, and is available at
+** http://www.eclipse.org/legal/epl-v10.html
+******************************************************************************/
+
+package com.franz.agraph.pool;
+
+import java.util.Map;
+
+import com.franz.agraph.pool.AGConnProp.Session;
+
+/**
+ * @since v4.3.3
+ */
+public class AGConnConfig {
+
+ public final String serverUrl;
+ public final String username;
+ public final String password;
+ public final String catalog;
+ public final String repository;
+ public final Session session;
+ public final Integer sessionLifetime;
+
+ public AGConnConfig(Map<AGConnProp, String> props) {
+ if (props.containsKey(AGConnProp.serverUrl)) {
+ serverUrl = props.get(AGConnProp.serverUrl);
+ } else {
+ throw new IllegalArgumentException("Property required for AGConn: " + AGConnProp.serverUrl);
+ }
+ if (props.containsKey(AGConnProp.username)) {
+ username = props.get(AGConnProp.username);
+ } else {
+ throw new IllegalArgumentException("Property required for AGConn: " + AGConnProp.username);
+ }
+ if (props.containsKey(AGConnProp.password)) {
+ password = props.get(AGConnProp.password);
+ } else {
+ throw new IllegalArgumentException("Property required for AGConn: " + AGConnProp.password);
+ }
+ catalog = props.get(AGConnProp.catalog);
+ if (props.containsKey(AGConnProp.repository)) {
+ repository = props.get(AGConnProp.repository);
+ } else {
+ throw new IllegalArgumentException("Property required for AGConn: " + AGConnProp.repository);
+ }
+ session = Session.valueOfCaseInsensitive(props.get(AGConnProp.session), Session.SHARED);
+ if (props.containsKey(AGConnProp.sessionLifetime)) {
+ sessionLifetime = Integer.parseInt( props.get(AGConnProp.sessionLifetime));
+ } else {
+ sessionLifetime = null;
+ }
+ }
+
+}
Oops, something went wrong. Retry.

0 comments on commit 50ae9c2

Please sign in to comment.