org.apache.hadoop.hbase.ipc
Class HBaseClient

java.lang.Object
  extended by org.apache.hadoop.hbase.ipc.HBaseClient

public class HBaseClient
extends Object

A client for an IPC service. IPC calls take a single Writable as a parameter, and return a Writable as their value. A service runs on a port and is defined by a parameter class and a value class.

This is the org.apache.hadoop.ipc.Client renamed as HBaseClient and moved into this package so can access package-private methods.

See Also:
HBaseServer

Nested Class Summary
protected  class HBaseClient.Call
          A call waiting for a value.
static class HBaseClient.CallTimeoutException
          Client-side call timeout
protected  class HBaseClient.Connection
          Thread that reads responses and notifies callers.
protected static class HBaseClient.ConnectionId
          This class holds the address and the user ticket.
static class HBaseClient.FailedServerException
           
protected  class HBaseClient.ParallelCall
          Call implementation used for parallel calls.
protected static class HBaseClient.ParallelResults
          Result collector for parallel calls.
 
Field Summary
protected  String clusterId
           
protected  org.apache.hadoop.conf.Configuration conf
           
protected  PoolMap<HBaseClient.ConnectionId,HBaseClient.Connection> connections
           
protected  int counter
           
static int FAILED_SERVER_EXPIRY_DEFAULT
           
static String FAILED_SERVER_EXPIRY_KEY
           
protected  org.apache.hadoop.hbase.ipc.HBaseClient.FailedServers failedServers
           
protected  long failureSleep
           
protected  int maxIdleTime
           
protected  int maxRetries
           
protected  int pingInterval
           
protected  AtomicBoolean running
           
protected  SocketFactory socketFactory
           
protected  int socketTimeout
           
protected  boolean tcpKeepAlive
           
protected  boolean tcpNoDelay
           
protected  Class<? extends org.apache.hadoop.io.Writable> valueClass
           
 
Constructor Summary
HBaseClient(Class<? extends org.apache.hadoop.io.Writable> valueClass, org.apache.hadoop.conf.Configuration conf)
          Construct an IPC client with the default SocketFactory
HBaseClient(Class<? extends org.apache.hadoop.io.Writable> valueClass, org.apache.hadoop.conf.Configuration conf, SocketFactory factory)
          Construct an IPC client whose values are of the given Writable class.
 
Method Summary
 org.apache.hadoop.io.Writable[] call(org.apache.hadoop.io.Writable[] params, InetSocketAddress[] addresses)
          Deprecated. Use call(Writable[], InetSocketAddress[], Class, User) instead
 org.apache.hadoop.io.Writable[] call(org.apache.hadoop.io.Writable[] params, InetSocketAddress[] addresses, Class<? extends VersionedProtocol> protocol, User ticket)
          Makes a set of calls in parallel.
 org.apache.hadoop.io.Writable call(org.apache.hadoop.io.Writable param, InetSocketAddress address)
          Make a call, passing param, to the IPC server running at address, returning the value.
 org.apache.hadoop.io.Writable call(org.apache.hadoop.io.Writable param, InetSocketAddress addr, Class<? extends VersionedProtocol> protocol, User ticket, int rpcTimeout)
          Make a call, passing param, to the IPC server running at address which is servicing the protocol protocol, with the ticket credentials, returning the value.
 org.apache.hadoop.io.Writable call(org.apache.hadoop.io.Writable param, InetSocketAddress addr, User ticket, int rpcTimeout)
           
protected  HBaseClient.Connection createConnection(HBaseClient.ConnectionId remoteId)
          Creates a connection.
 String getClusterId()
           
protected  HBaseClient.Connection getConnection(InetSocketAddress addr, Class<? extends VersionedProtocol> protocol, User ticket, int rpcTimeout, HBaseClient.Call call)
           
protected static int getPoolSize(org.apache.hadoop.conf.Configuration config)
          Return the pool size specified in the configuration, which is applicable only if the pool type is PoolMap.PoolType.RoundRobin.
protected static PoolMap.PoolType getPoolType(org.apache.hadoop.conf.Configuration config)
          Return the pool type specified in the configuration, which must be set to either PoolMap.PoolType.RoundRobin or PoolMap.PoolType.ThreadLocal, otherwise default to the former.
static void setPingInterval(org.apache.hadoop.conf.Configuration conf, int pingInterval)
          set the ping interval value in configuration
static void setSocketTimeout(org.apache.hadoop.conf.Configuration conf, int socketTimeout)
          Set the socket timeout
 void stop()
          Stop all threads related to this client.
protected  IOException wrapException(InetSocketAddress addr, IOException exception)
          Take an IOException and the address we were trying to connect to and return an IOException with the input exception as the cause.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connections

protected final PoolMap<HBaseClient.ConnectionId,HBaseClient.Connection> connections

valueClass

protected final Class<? extends org.apache.hadoop.io.Writable> valueClass

counter

protected int counter

running

protected final AtomicBoolean running

conf

protected final org.apache.hadoop.conf.Configuration conf

maxIdleTime

protected final int maxIdleTime

maxRetries

protected final int maxRetries

failureSleep

protected final long failureSleep

tcpNoDelay

protected final boolean tcpNoDelay

tcpKeepAlive

protected final boolean tcpKeepAlive

pingInterval

protected int pingInterval

socketTimeout

protected int socketTimeout

failedServers

protected org.apache.hadoop.hbase.ipc.HBaseClient.FailedServers failedServers

socketFactory

protected final SocketFactory socketFactory

clusterId

protected String clusterId

FAILED_SERVER_EXPIRY_KEY

public static final String FAILED_SERVER_EXPIRY_KEY
See Also:
Constant Field Values

FAILED_SERVER_EXPIRY_DEFAULT

public static final int FAILED_SERVER_EXPIRY_DEFAULT
See Also:
Constant Field Values
Constructor Detail

HBaseClient

public HBaseClient(Class<? extends org.apache.hadoop.io.Writable> valueClass,
                   org.apache.hadoop.conf.Configuration conf,
                   SocketFactory factory)
Construct an IPC client whose values are of the given Writable class.

Parameters:
valueClass - value class
conf - configuration
factory - socket factory

HBaseClient

public HBaseClient(Class<? extends org.apache.hadoop.io.Writable> valueClass,
                   org.apache.hadoop.conf.Configuration conf)
Construct an IPC client with the default SocketFactory

Parameters:
valueClass - value class
conf - configuration
Method Detail

setPingInterval

public static void setPingInterval(org.apache.hadoop.conf.Configuration conf,
                                   int pingInterval)
set the ping interval value in configuration

Parameters:
conf - Configuration
pingInterval - the ping interval

setSocketTimeout

public static void setSocketTimeout(org.apache.hadoop.conf.Configuration conf,
                                    int socketTimeout)
Set the socket timeout

Parameters:
conf - Configuration
socketTimeout - the socket timeout

createConnection

protected HBaseClient.Connection createConnection(HBaseClient.ConnectionId remoteId)
                                           throws IOException
Creates a connection. Can be overridden by a subclass for testing.

Parameters:
remoteId - - the ConnectionId to use for the connection creation.
Throws:
IOException

getPoolType

protected static PoolMap.PoolType getPoolType(org.apache.hadoop.conf.Configuration config)
Return the pool type specified in the configuration, which must be set to either PoolMap.PoolType.RoundRobin or PoolMap.PoolType.ThreadLocal, otherwise default to the former. For applications with many user threads, use a small round-robin pool. For applications with few user threads, you may want to try using a thread-local pool. In any case, the number of HBaseClient instances should not exceed the operating system's hard limit on the number of connections.

Parameters:
config - configuration
Returns:
either a PoolMap.PoolType.RoundRobin or PoolMap.PoolType.ThreadLocal

getPoolSize

protected static int getPoolSize(org.apache.hadoop.conf.Configuration config)
Return the pool size specified in the configuration, which is applicable only if the pool type is PoolMap.PoolType.RoundRobin.

Parameters:
config -
Returns:
the maximum pool size

stop

public void stop()
Stop all threads related to this client. No further calls may be made using this client.


call

public org.apache.hadoop.io.Writable call(org.apache.hadoop.io.Writable param,
                                          InetSocketAddress address)
                                   throws IOException,
                                          InterruptedException
Make a call, passing param, to the IPC server running at address, returning the value. Throws exceptions if there are network problems or if the remote code threw an exception.

Parameters:
param - writable parameter
address - network address
Returns:
Writable
Throws:
IOException - e
InterruptedException

call

public org.apache.hadoop.io.Writable call(org.apache.hadoop.io.Writable param,
                                          InetSocketAddress addr,
                                          User ticket,
                                          int rpcTimeout)
                                   throws IOException,
                                          InterruptedException
Throws:
IOException
InterruptedException

call

public org.apache.hadoop.io.Writable call(org.apache.hadoop.io.Writable param,
                                          InetSocketAddress addr,
                                          Class<? extends VersionedProtocol> protocol,
                                          User ticket,
                                          int rpcTimeout)
                                   throws InterruptedException,
                                          IOException
Make a call, passing param, to the IPC server running at address which is servicing the protocol protocol, with the ticket credentials, returning the value. Throws exceptions if there are network problems or if the remote code threw an exception.

Throws:
InterruptedException
IOException

wrapException

protected IOException wrapException(InetSocketAddress addr,
                                    IOException exception)
Take an IOException and the address we were trying to connect to and return an IOException with the input exception as the cause. The new exception provides the stack trace of the place where the exception is thrown and some extra diagnostics information. If the exception is ConnectException or SocketTimeoutException, return a new one of the same type; Otherwise return an IOException.

Parameters:
addr - target address
exception - the relevant exception
Returns:
an exception to throw

call

@Deprecated
public org.apache.hadoop.io.Writable[] call(org.apache.hadoop.io.Writable[] params,
                                                       InetSocketAddress[] addresses)
                                     throws IOException,
                                            InterruptedException
Deprecated. Use call(Writable[], InetSocketAddress[], Class, User) instead

Makes a set of calls in parallel. Each parameter is sent to the corresponding address. When all values are available, or have timed out or errored, the collected results are returned in an array. The array contains nulls for calls that timed out or errored.

Parameters:
params - writable parameters
addresses - socket addresses
Returns:
Writable[]
Throws:
IOException - e
InterruptedException

call

public org.apache.hadoop.io.Writable[] call(org.apache.hadoop.io.Writable[] params,
                                            InetSocketAddress[] addresses,
                                            Class<? extends VersionedProtocol> protocol,
                                            User ticket)
                                     throws IOException,
                                            InterruptedException
Makes a set of calls in parallel. Each parameter is sent to the corresponding address. When all values are available, or have timed out or errored, the collected results are returned in an array. The array contains nulls for calls that timed out or errored.

Throws:
IOException
InterruptedException

getConnection

protected HBaseClient.Connection getConnection(InetSocketAddress addr,
                                               Class<? extends VersionedProtocol> protocol,
                                               User ticket,
                                               int rpcTimeout,
                                               HBaseClient.Call call)
                                        throws IOException,
                                               InterruptedException
Throws:
IOException
InterruptedException

getClusterId

public String getClusterId()
Returns:
the clusterId


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.