[Mulgara-svn] r2020 - in trunk/src/jar: content-rlog/java/org/mulgara/krule/rlog/ast krule/java/org/mulgara/krule resolver-gis/java/org/mulgara/resolver/gis resolver-spi/java/org/mulgara/resolver/spi server-rmi/java/org/mulgara/server/rmi util/java/org/mulgara/util util/java/org/mulgara/util/io util-xa/java/org/mulgara/store/xa
pag at mulgara.org
pag at mulgara.org
Thu Sep 8 15:32:38 UTC 2011
Author: pag
Date: 2011-09-08 15:32:38 +0000 (Thu, 08 Sep 2011)
New Revision: 2020
Added:
trunk/src/jar/util/java/org/mulgara/util/ObjectUtil.java
Modified:
trunk/src/jar/content-rlog/java/org/mulgara/krule/rlog/ast/Predicate.java
trunk/src/jar/krule/java/org/mulgara/krule/Rule.java
trunk/src/jar/resolver-gis/java/org/mulgara/resolver/gis/GISDistanceStatements.java
trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/Statements.java
trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/AnswerWrapperRemoteAnswerSerialised.java
trunk/src/jar/util-xa/java/org/mulgara/store/xa/AbstractBlockFile.java
trunk/src/jar/util-xa/java/org/mulgara/store/xa/MappedBlockFile.java
trunk/src/jar/util/java/org/mulgara/util/IntFile.java
trunk/src/jar/util/java/org/mulgara/util/MappedIntFile.java
trunk/src/jar/util/java/org/mulgara/util/io/MappingUtil.java
Log:
Initial cleanups for Fortify scan.
Modified: trunk/src/jar/content-rlog/java/org/mulgara/krule/rlog/ast/Predicate.java
===================================================================
--- trunk/src/jar/content-rlog/java/org/mulgara/krule/rlog/ast/Predicate.java 2011-08-05 21:15:47 UTC (rev 2019)
+++ trunk/src/jar/content-rlog/java/org/mulgara/krule/rlog/ast/Predicate.java 2011-09-08 15:32:38 UTC (rev 2020)
@@ -26,6 +26,8 @@
import org.mulgara.krule.rlog.rdf.URIReference;
import org.mulgara.krule.rlog.rdf.Var;
+import static org.mulgara.util.ObjectUtil.eq;
+
/**
* A predicate in a statement appearing in the AST.
*
@@ -171,6 +173,13 @@
return true;
}
+ /** {@inheritDoc} */
+ public boolean equals(Object o) {
+ if (!(o instanceof Predicate)) return false;
+ Predicate p = (Predicate)o;
+ return eq(predicate, p.predicate) && eq(subject, p.subject) && eq(object, p.object) && eq(graphAnnotation, p.graphAnnotation);
+ }
+
/**
* Returns a canonical version of this predicate.
* @return A new canonical predicate, with canonicalized elements.
Modified: trunk/src/jar/krule/java/org/mulgara/krule/Rule.java
===================================================================
--- trunk/src/jar/krule/java/org/mulgara/krule/Rule.java 2011-08-05 21:15:47 UTC (rev 2019)
+++ trunk/src/jar/krule/java/org/mulgara/krule/Rule.java 2011-09-08 15:32:38 UTC (rev 2020)
@@ -265,7 +265,7 @@
* by column index in the Tuples, not by a variable mapping as is the case
* in TuplesWrapperStatements.
*/
- protected static class TuplesStatements implements Statements {
+ protected static class TuplesStatements implements Statements, Cloneable {
private static List<Variable> variables =
Arrays.asList(Statements.SUBJECT, Statements.PREDICATE, Statements.OBJECT);
Modified: trunk/src/jar/resolver-gis/java/org/mulgara/resolver/gis/GISDistanceStatements.java
===================================================================
--- trunk/src/jar/resolver-gis/java/org/mulgara/resolver/gis/GISDistanceStatements.java 2011-08-05 21:15:47 UTC (rev 2019)
+++ trunk/src/jar/resolver-gis/java/org/mulgara/resolver/gis/GISDistanceStatements.java 2011-09-08 15:32:38 UTC (rev 2020)
@@ -69,7 +69,7 @@
*
* @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
*/
-public class GISDistanceStatements implements Statements {
+public class GISDistanceStatements implements Statements, Cloneable {
/** Logger. */
@SuppressWarnings("unused")
Modified: trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/Statements.java
===================================================================
--- trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/Statements.java 2011-08-05 21:15:47 UTC (rev 2019)
+++ trunk/src/jar/resolver-spi/java/org/mulgara/resolver/spi/Statements.java 2011-09-08 15:32:38 UTC (rev 2020)
@@ -47,7 +47,7 @@
* @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
*/
-public interface Statements extends Cursor {
+public interface Statements extends Cursor, Cloneable {
/** A variable for the subject position in a triple */
static final Variable SUBJECT = new Variable("subject");
Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/AnswerWrapperRemoteAnswerSerialised.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/AnswerWrapperRemoteAnswerSerialised.java 2011-08-05 21:15:47 UTC (rev 2019)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/AnswerWrapperRemoteAnswerSerialised.java 2011-09-08 15:32:38 UTC (rev 2020)
@@ -62,7 +62,7 @@
* @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
*/
public class AnswerWrapperRemoteAnswerSerialised implements RemoteAnswer,
- AnswerPage, Serializable {
+ AnswerPage, Serializable, Cloneable {
/**
* Allow newer compiled version of the stub to operate when changes
@@ -75,7 +75,7 @@
/**
* The wrapped serializable instance.
*/
- protected final Answer answer;
+ protected Answer answer;
/**
* Flag to determine availability of a next line, used to paging.
@@ -334,19 +334,15 @@
//reset the original Answer
try {
-
answerClone.beforeFirst();
-
- return new AnswerWrapperRemoteAnswerSerialised(answerClone);
- }
- catch (TuplesException tuplesException) {
-
+ AnswerWrapperRemoteAnswerSerialised c = (AnswerWrapperRemoteAnswerSerialised)super.clone();
+ c.answer = answerClone;
+ return c;
+ } catch (TuplesException tuplesException) {
throw new RuntimeException(tuplesException);
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException(e);
}
- catch (RemoteException remoteException) {
-
- throw new RuntimeException(remoteException);
- }
}
/**
Modified: trunk/src/jar/util/java/org/mulgara/util/IntFile.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/IntFile.java 2011-08-05 21:15:47 UTC (rev 2019)
+++ trunk/src/jar/util/java/org/mulgara/util/IntFile.java 2011-09-08 15:32:38 UTC (rev 2020)
@@ -352,9 +352,7 @@
while (!file.delete() && file.isFile() && retries-- > 0) {
// Causing any MappedByteBuffers to be unmapped may allow the
// file to be deleted. This may be needed for Windows.
- System.gc();
- try { Thread.sleep(100); } catch (InterruptedException ie) { }
- System.runFinalization();
+ MappingUtil.systemCleanup();
}
if (retries < 0) {
Modified: trunk/src/jar/util/java/org/mulgara/util/MappedIntFile.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/MappedIntFile.java 2011-08-05 21:15:47 UTC (rev 2019)
+++ trunk/src/jar/util/java/org/mulgara/util/MappedIntFile.java 2011-09-08 15:32:38 UTC (rev 2020)
@@ -384,9 +384,7 @@
if (retries-- == 0) throw ex;
// Let some old mappings go away and try again.
- System.gc();
- try { Thread.sleep(100); } catch (InterruptedException ie) { }
- System.runFinalization();
+ MappingUtil.systemCleanup();
}
}
}
Added: trunk/src/jar/util/java/org/mulgara/util/ObjectUtil.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/ObjectUtil.java (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/ObjectUtil.java 2011-09-08 15:32:38 UTC (rev 2020)
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2011 Revelytix, Inc.
+ *
+ * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.mulgara.util;
+
+/**
+ * Purpose: A utility class for general objects.<P>
+ *
+ * Creation Date: 7 September 2011 <P>
+ *
+ * Original Author: Paul Gearon (pgearon at revelytix.com) <P>
+ *
+ * Company: Revelytix, Inc. <P>
+ *
+ * License: LGPL by default, or as assigned
+ */
+public class ObjectUtil {
+
+ /**
+ * Simple test to see if two objects are equal, even if null.
+ * @param a The first object to test.
+ * @param b The second object to test.
+ * @return <code>true</code> only if both objects are null, or equal.
+ */
+ public static final boolean eq(Object a, Object b) {
+ return a == null ? b == null : a.equals(b);
+ }
+}
Modified: trunk/src/jar/util/java/org/mulgara/util/io/MappingUtil.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/io/MappingUtil.java 2011-08-05 21:15:47 UTC (rev 2019)
+++ trunk/src/jar/util/java/org/mulgara/util/io/MappingUtil.java 2011-09-08 15:32:38 UTC (rev 2020)
@@ -85,14 +85,29 @@
logger.error("Unable to truncate mapped file of size " + s + " to size " + size, e);
throw e;
}
- System.gc();
- try { Thread.sleep(100); } catch (InterruptedException ie) { }
- System.runFinalization();
+ systemCleanup();
}
}
}
-
+
/**
+ * Prompt the system to clean up outstanding objects, thereby releasing unique resources
+ * for re-use. This is required for MappedByteBuffers as the Java NIO cannot release the
+ * resources explicitly without putting a guard on every access (thereby compromising the
+ * speed advantages of memory mapping) or allowing continuing access to memory that is
+ * no longer accessible. Therefore, the resources must be released implicitly (by setting
+ * all references null) and then calling this code to prompt the system to clean the
+ * resources up. Depending on the host OS, this method may need to be called several times.
+ * Linux typically only requires 1 or 2 invocations, while Windows regularly needs more than
+ * 2 and can require >6.
+ */
+ public static void systemCleanup() {
+ System.gc();
+ try { Thread.sleep(100); } catch (InterruptedException ie) { }
+ System.runFinalization();
+ }
+
+ /**
* Releases the mapped byte buffer, attempting to pre-emptively clean up the associated
* mapping under Windows.
* @param buffer A mapped byte buffer.
Modified: trunk/src/jar/util-xa/java/org/mulgara/store/xa/AbstractBlockFile.java
===================================================================
--- trunk/src/jar/util-xa/java/org/mulgara/store/xa/AbstractBlockFile.java 2011-08-05 21:15:47 UTC (rev 2019)
+++ trunk/src/jar/util-xa/java/org/mulgara/store/xa/AbstractBlockFile.java 2011-09-08 15:32:38 UTC (rev 2020)
@@ -379,9 +379,7 @@
while (!file.delete() && file.isFile() && retries-- > 0) {
// Causing any MappedByteBuffers to be unmapped may allow the
// file to be deleted. This may be needed for Windows.
- System.gc();
- try { Thread.sleep(100); } catch (InterruptedException ie) { }
- System.runFinalization();
+ MappingUtil.systemCleanup();
}
if (retries < 0) {
Modified: trunk/src/jar/util-xa/java/org/mulgara/store/xa/MappedBlockFile.java
===================================================================
--- trunk/src/jar/util-xa/java/org/mulgara/store/xa/MappedBlockFile.java 2011-08-05 21:15:47 UTC (rev 2019)
+++ trunk/src/jar/util-xa/java/org/mulgara/store/xa/MappedBlockFile.java 2011-09-08 15:32:38 UTC (rev 2020)
@@ -456,9 +456,7 @@
}
// Let some old mappings go away and try again.
- System.gc();
- try { Thread.sleep(100); } catch (InterruptedException ie) { }
- System.runFinalization();
+ MappingUtil.systemCleanup();
}
}
}
More information about the Mulgara-svn
mailing list