camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r936762 - in /camel/trunk/components/camel-hawtdb/src: main/java/org/apache/camel/component/hawtdb/ test/java/org/apache/camel/component/hawtdb/
Date Thu, 22 Apr 2010 10:36:25 GMT
Author: davsclaus
Date: Thu Apr 22 10:36:24 2010
New Revision: 936762

URL: http://svn.apache.org/viewvc?rev=936762&view=rev
Log:
In read only operations avoid creating new index if index did not exist already.

Modified:
    camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBAggregationRepository.java
    camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBFile.java
    camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateNotLostRemovedWhenConfirmedTest.java
    camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateNotLostTest.java

Modified: camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBAggregationRepository.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBAggregationRepository.java?rev=936762&r1=936761&r2=936762&view=diff
==============================================================================
--- camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBAggregationRepository.java
(original)
+++ camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBAggregationRepository.java
Thu Apr 22 10:36:24 2010
@@ -35,7 +35,6 @@ import org.apache.camel.util.ServiceHelp
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.fusesource.hawtdb.api.Index;
-import org.fusesource.hawtdb.api.IndexVisitor;
 import org.fusesource.hawtdb.api.Transaction;
 import org.fusesource.hawtdb.util.buffer.Buffer;
 
@@ -114,7 +113,7 @@ public class HawtDBAggregationRepository
             final Buffer exchangeBuffer = marshaller.marshallExchange(camelContext, exchange);
             Buffer rc = hawtDBFile.execute(new Work<Buffer>() {
                 public Buffer execute(Transaction tx) {
-                    Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx,
repositoryName);
+                    Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx,
repositoryName, true);
                     return index.put(keyBuffer, exchangeBuffer);
                 }
 
@@ -144,7 +143,10 @@ public class HawtDBAggregationRepository
             final Buffer keyBuffer = marshaller.marshallKey(key);
             Buffer rc = hawtDBFile.execute(new Work<Buffer>() {
                 public Buffer execute(Transaction tx) {
-                    Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx,
repositoryName);
+                    Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx,
repositoryName, false);
+                    if (index == null) {
+                        return null;
+                    }
                     return index.get(keyBuffer);
                 }
 
@@ -176,12 +178,12 @@ public class HawtDBAggregationRepository
             final Buffer exchangeBuffer = marshaller.marshallExchange(camelContext, exchange);
             hawtDBFile.execute(new Work<Buffer>() {
                 public Buffer execute(Transaction tx) {
-                    Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx,
repositoryName);
+                    Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx,
repositoryName, true);
                     // remove from the in progress index
                     index.remove(keyBuffer);
 
                     // and add it to the confirmed index
-                    Index<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx,
getRepositoryNameCompleted());
+                    Index<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx,
getRepositoryNameCompleted(), true);
                     indexCompleted.put(confirmKeyBuffer, exchangeBuffer);
                     return null;
                 }
@@ -205,7 +207,7 @@ public class HawtDBAggregationRepository
             final Buffer confirmKeyBuffer = marshaller.marshallKey(exchangeId);
             hawtDBFile.execute(new Work<Buffer>() {
                 public Buffer execute(Transaction tx) {
-                    Index<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx,
getRepositoryNameCompleted());
+                    Index<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx,
getRepositoryNameCompleted(), true);
                     return indexCompleted.remove(confirmKeyBuffer);
                 }
 
@@ -230,9 +232,12 @@ public class HawtDBAggregationRepository
                     return null;
                 }
 
-                Index<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx,
getRepositoryName());
+                Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, repositoryName,
false);
+                if (index == null) {
+                    return null;
+                }
 
-                Iterator<Map.Entry<Buffer, Buffer>> it = indexCompleted.iterator();
+                Iterator<Map.Entry<Buffer, Buffer>> it = index.iterator();
                 // scan could potentially be running while we are shutting down so check
for that
                 while (it.hasNext() && isRunAllowed()) {
                     Map.Entry<Buffer, Buffer> entry = it.next();
@@ -273,7 +278,10 @@ public class HawtDBAggregationRepository
                     return null;
                 }
 
-                Index<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx,
getRepositoryNameCompleted());
+                Index<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx,
getRepositoryNameCompleted(), false);
+                if (indexCompleted == null) {
+                    return null;
+                }
 
                 Iterator<Map.Entry<Buffer, Buffer>> it = indexCompleted.iterator();
                 // scan could potentially be running while we are shutting down so check
for that
@@ -320,7 +328,10 @@ public class HawtDBAggregationRepository
             final Buffer confirmKeyBuffer = marshaller.marshallKey(exchangeId);
             Buffer rc = hawtDBFile.execute(new Work<Buffer>() {
                 public Buffer execute(Transaction tx) {
-                    Index<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx,
getRepositoryNameCompleted());
+                    Index<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx,
getRepositoryNameCompleted(), false);
+                    if (indexCompleted == null) {
+                        return null;
+                    }
                     return indexCompleted.get(confirmKeyBuffer);
                 }
 

Modified: camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBFile.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBFile.java?rev=936762&r1=936761&r2=936762&view=diff
==============================================================================
--- camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBFile.java
(original)
+++ camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBFile.java
Thu Apr 22 10:36:24 2010
@@ -121,13 +121,13 @@ public class HawtDBFile extends TxPageFi
         return answer;
     }
 
-    public Index<Buffer, Buffer> getRepositoryIndex(Transaction tx, String name) {
-        Index<Buffer, Buffer> answer;
+    public Index<Buffer, Buffer> getRepositoryIndex(Transaction tx, String name, boolean
create) {
+        Index<Buffer, Buffer> answer = null;
 
         Index<String, Integer> indexes = ROOT_INDEXES_FACTORY.open(tx, 0);
         Integer location = indexes.get(name);
 
-        if (location == null) {
+        if (create && location == null) {
             // create it..
             int page = tx.allocator().alloc(1);
             Index<Buffer, Buffer> created = INDEX_FACTORY.create(tx, page);
@@ -140,7 +140,7 @@ public class HawtDBFile extends TxPageFi
             }
 
             answer = created;
-        } else {
+        } else if (location != null) {
             if (LOG.isTraceEnabled()) {
                 LOG.trace("Repository index with name " + name + " at location " + location);
             }

Modified: camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateNotLostRemovedWhenConfirmedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateNotLostRemovedWhenConfirmedTest.java?rev=936762&r1=936761&r2=936762&view=diff
==============================================================================
--- camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateNotLostRemovedWhenConfirmedTest.java
(original)
+++ camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateNotLostRemovedWhenConfirmedTest.java
Thu Apr 22 10:36:24 2010
@@ -56,7 +56,7 @@ public class HawtDBAggregateNotLostRemov
         final Buffer confirmKeyBuffer = marshaller.marshallKey(exchangeId);
         Buffer bf = hawtDBFile.execute(new Work<Buffer>() {
             public Buffer execute(Transaction tx) {
-                Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, "repo1-completed");
+                Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, "repo1-completed",
false);
                 return index.get(confirmKeyBuffer);
             }
         });

Modified: camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateNotLostTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateNotLostTest.java?rev=936762&r1=936761&r2=936762&view=diff
==============================================================================
--- camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateNotLostTest.java
(original)
+++ camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateNotLostTest.java
Thu Apr 22 10:36:24 2010
@@ -57,7 +57,7 @@ public class HawtDBAggregateNotLostTest 
         final Buffer confirmKeyBuffer = marshaller.marshallKey(exchangeId);
         Buffer bf = hawtDBFile.execute(new Work<Buffer>() {
             public Buffer execute(Transaction tx) {
-                Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, "repo1-completed");
+                Index<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, "repo1-completed",
false);
                 return index.get(confirmKeyBuffer);
             }
         });



Mime
View raw message