zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iv...@apache.org
Subject svn commit: r1355467 - in /zookeeper/bookkeeper/trunk: CHANGES.txt bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ReadOnlyLedgerHandle.java
Date Fri, 29 Jun 2012 16:43:58 GMT
Author: ivank
Date: Fri Jun 29 16:43:54 2012
New Revision: 1355467

URL: http://svn.apache.org/viewvc?rev=1355467&view=rev
Log:
BOOKKEEPER-280: LedgerHandle.addEntry() should return an entryId (mmerli via ivank)

Modified:
    zookeeper/bookkeeper/trunk/CHANGES.txt
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ReadOnlyLedgerHandle.java

Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1355467&r1=1355466&r2=1355467&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Fri Jun 29 16:43:54 2012
@@ -28,6 +28,8 @@ Trunk (unreleased changes)
 
         BOOKKEEPER-322: New protobufs generates findbugs errors (ivank)
 
+        BOOKKEEPER-280: LedgerHandle.addEntry() should return an entryId (mmerli via ivank)
+
       hedwig-client:
 
         BOOKKEEPER-274: Hedwig cpp client library should not link to cppunit which is just
used for test. (sijie via ivank)

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java?rev=1355467&r1=1355466&r2=1355467&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
Fri Jun 29 16:43:54 2012
@@ -387,9 +387,10 @@ public class LedgerHandle {
      *
      * @param data
      *         array of bytes to be written to the ledger
+     * @return the entryId of the new inserted entry
      */
-    public void addEntry(byte[] data) throws InterruptedException, BKException {
-        addEntry(data, 0, data.length);
+    public long addEntry(byte[] data) throws InterruptedException, BKException {
+        return addEntry(data, 0, data.length);
     }
 
     /**
@@ -401,24 +402,24 @@ public class LedgerHandle {
      *          offset from which to take bytes from data
      * @param length
      *          number of bytes to take from data
+     * @return the entryId of the new inserted entry
      */
-    public void addEntry(byte[] data, int offset, int length)
+    public long addEntry(byte[] data, int offset, int length)
             throws InterruptedException, BKException {
         LOG.debug("Adding entry {}", data);
 
         SyncCounter counter = new SyncCounter();
         counter.inc();
 
-        asyncAddEntry(data, offset, length, new SyncAddCallback(), counter);
+        SyncAddCallback callback = new SyncAddCallback();
+        asyncAddEntry(data, offset, length, callback, counter);
         counter.block(0);
         
         if (counter.getrc() != BKException.Code.OK) {
             throw BKException.create(counter.getrc());
         }
 
-        if(counter.getrc() != BKException.Code.OK) {
-            throw BKException.create(counter.getrc());
-        }
+        return callback.entryId;
     }
 
     /**
@@ -823,6 +824,8 @@ public class LedgerHandle {
     }
 
     private static class SyncAddCallback implements AddCallback {
+        long entryId = -1;
+
         /**
          * Implementation of callback interface for synchronous read method.
          *
@@ -837,7 +840,8 @@ public class LedgerHandle {
          */
         public void addComplete(int rc, LedgerHandle lh, long entry, Object ctx) {
             SyncCounter counter = (SyncCounter) ctx;
-            
+
+            this.entryId = entry;
             counter.setrc(rc);
             counter.dec();
         }

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ReadOnlyLedgerHandle.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ReadOnlyLedgerHandle.java?rev=1355467&r1=1355466&r2=1355467&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ReadOnlyLedgerHandle.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ReadOnlyLedgerHandle.java
Fri Jun 29 16:43:54 2012
@@ -52,12 +52,12 @@ class ReadOnlyLedgerHandle extends Ledge
     }
     
     @Override
-    public void addEntry(byte[] data) throws InterruptedException, BKException {
-        addEntry(data, 0, data.length);
+    public long addEntry(byte[] data) throws InterruptedException, BKException {
+        return addEntry(data, 0, data.length);
     }
     
     @Override
-    public void addEntry(byte[] data, int offset, int length)
+    public long addEntry(byte[] data, int offset, int length)
             throws InterruptedException, BKException {
         LOG.error("Tried to add entry on a Read-Only ledger handle, ledgerid=" + ledgerId);
       
         throw BKException.create(BKException.Code.IllegalOpException);



Mime
View raw message