Hi Yang, Please use the bookkeeper-user@zookeeper list for questions about BK.

"BookieClient" is possibly a misleading name for what that class does. It is supposed to be internal to the bookkeeper client library and used for the communication of the client with the bookies. The interface you're supposed to use is available in the BookKeeper and in the LedgerHandle classes. With a BookKeeper object, one can create, open, and delete ledgers. Upon creating or opening a ledger, the call returns a ledger handle, which you use to add to the ledger or read from the ledger, depending on the state of the ledger.

You'll also find the documentation of the API here:


-Flavio


On Sep 6, 2011, at 7:02 AM, Yang wrote:

I was trying to learn how to use BookKeeper, so I started from the test code
BookieClientTest.java, and stripped it down to the
most basic form (code pasted below),

now I just have the readEntry callback print out onto screen, but it doesn't
seem to be executed. there is not much doc available,
where am I doing wrong?

I setup my separate bookie server as instructed by the README.txt , by
java -cp
$MYLIB:\$\{dist.dir\}/contrib/bookeper/zookeeper-dev-bookkeeper.jar:/home/yyang/work/zookeeper/zookeeper-3.3.3/zookeeper-3.3.3.jar
org.apache.bookkeeper.util.LocalBookKeeper 1


Thanks a lot
Yang


///////////////////////////////////////
package org.apache.bookkeeper.test;

/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you 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.
*
*/

import java.io.File;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.concurrent.Executors;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.socket.ClientSocketChannelFactory;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.junit.Test;
import org.apache.bookkeeper.client.BKException;
import org.apache.bookkeeper.proto.BookieClient;
import org.apache.bookkeeper.proto.BookieServer;
import
org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.ReadEntryCallback;
import
org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.WriteCallback;
import org.apache.bookkeeper.util.OrderedSafeExecutor;
import org.apache.log4j.Logger;

import junit.framework.TestCase;

public class SimpleClientTest extends TestCase {
   static Logger LOG = Logger.getLogger(SimpleClientTest.class);
   BookieServer bs;
   File tmpDir;
   int port = 5000;
   ClientSocketChannelFactory channelFactory;
   OrderedSafeExecutor executor;

   @Override
   protected void setUp() throws Exception {

       channelFactory = new
NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors
               .newCachedThreadPool());
       executor = new OrderedSafeExecutor(2);
   }


   ReadEntryCallback recb = new ReadEntryCallback() {

       public void readEntryComplete(int rc, long ledgerId, long entryId,
ChannelBuffer bb, Object ctx) {
           System.out.println("read something" + ledgerId + " " + entryId +
" " + bb);
       }

   };

   WriteCallback wrcb = new WriteCallback() {
       public void writeComplete(int rc, long ledgerId, long entryId,
InetSocketAddress addr, Object ctx) {
           if (ctx != null) {
               synchronized (ctx) {
                   ctx.notifyAll();
               }
           }
       }
   };

   @Test
   public void testWriteGaps() throws Exception {
       byte[] passwd = new byte[20];
       Arrays.fill(passwd, (byte) 'a');
       InetSocketAddress addr = new InetSocketAddress("127.0.0.1", port);

       BookieClient bc = new BookieClient(channelFactory, executor);
       ChannelBuffer bb;
       bb = createByteBuffer(1, 1, 1);
       bc.addEntry(addr, 1, passwd, 1, bb, wrcb, null);
           bc.readEntry(addr, 1, 1, recb, null);

   }

   private ChannelBuffer createByteBuffer(int i, long lid, long eid) {
       ByteBuffer bb;
       bb = ByteBuffer.allocate(4 + 16);
       bb.putLong(lid);
       bb.putLong(eid);
       bb.putInt(i);
       bb.flip();
       return ChannelBuffers.wrappedBuffer(bb);
   }
}

flavio
junqueira
 
research scientist
 
[email protected]
direct +34 93-183-8828
 
avinguda diagonal 177, 8th floor, barcelona, 08018, es
phone (408) 349 3300    fax (408) 349 3301


Reply via email to