org.apache.bookkeeper.proto
Class BookieClient

java.lang.Object
  extended by java.lang.Thread
      extended by org.apache.bookkeeper.proto.BookieClient
All Implemented Interfaces:
Runnable

public class BookieClient
extends Thread

Implements the client-side part of the BookKeeper protocol.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BookieClient(InetSocketAddress addr, int recvTimeout)
           
BookieClient(String host, int port, int recvTimeout)
           
 
Method Summary
 void addEntry(long ledgerId, byte[] masterKey, long entryId, ByteBuffer entry, WriteCallback cb, Object ctx)
          Send addEntry operation to bookie.
 void errorOut()
          Errors out pending entries.
 MessageDigest getDigestInstance(String alg)
          Get digest instance if there is none.
 Mac getMac(String alg, byte[] key)
           
 void halt()
          Halts client.
 boolean isConnected()
          Returns the status of the socket of this bookie client.
static void main(String[] args)
           
 void readEntry(long ledgerId, long entryId, ReadEntryCallback cb, Object ctx)
          Send readEntry operation to bookie.
 void run()
           
 void startConnection(InetSocketAddress addr, int recvTimeout)
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BookieClient

public BookieClient(InetSocketAddress addr,
                    int recvTimeout)
             throws IOException,
                    ConnectException
Throws:
IOException
ConnectException

BookieClient

public BookieClient(String host,
                    int port,
                    int recvTimeout)
             throws IOException,
                    ConnectException
Throws:
IOException
ConnectException
Method Detail

startConnection

public void startConnection(InetSocketAddress addr,
                            int recvTimeout)
                     throws IOException,
                            ConnectException
Throws:
IOException
ConnectException

getDigestInstance

public MessageDigest getDigestInstance(String alg)
                                throws NoSuchAlgorithmException
Get digest instance if there is none.

Throws:
NoSuchAlgorithmException

getMac

public Mac getMac(String alg,
                  byte[] key)
           throws NoSuchAlgorithmException,
                  InvalidKeyException
Throws:
NoSuchAlgorithmException
InvalidKeyException

addEntry

public void addEntry(long ledgerId,
                     byte[] masterKey,
                     long entryId,
                     ByteBuffer entry,
                     WriteCallback cb,
                     Object ctx)
              throws IOException,
                     InterruptedException
Send addEntry operation to bookie. It throws an IOException if either the write to the socket fails or it takes too long to obtain a permit to send another request, which possibly implies that the corresponding bookie is down.

Parameters:
ledgerId - ledger identifier
entryId - entry identifier
cb - object implementing callback method
ctx - control object
Throws:
IOException
InterruptedException

readEntry

public void readEntry(long ledgerId,
                      long entryId,
                      ReadEntryCallback cb,
                      Object ctx)
               throws IOException,
                      InterruptedException
Send readEntry operation to bookie. It throws an IOException if either the write to the socket fails or it takes too long to obtain a permit to send another request, which possibly implies that the corresponding bookie is down.

Parameters:
ledgerId - ledger identifier
entryId - entry identifier
cb - object implementing callback method
ctx - control object
Throws:
IOException
InterruptedException

run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread

errorOut

public void errorOut()
Errors out pending entries. We call this method from one thread to avoid concurrent executions to QuorumOpMonitor (implements callbacks). It seems simpler to call it from BookieHandle instead of calling directly from here.


halt

public void halt()
Halts client.


isConnected

public boolean isConnected()
Returns the status of the socket of this bookie client.

Returns:
boolean

main

public static void main(String[] args)
                 throws NumberFormatException,
                        IOException,
                        InterruptedException
Parameters:
args -
Throws:
IOException
NumberFormatException
InterruptedException