Package org.apache.bookkeeper.proto
Class DefaultPerChannelBookieClientPool
- java.lang.Object
-
- org.apache.bookkeeper.proto.DefaultPerChannelBookieClientPool
-
- All Implemented Interfaces:
BookkeeperInternalCallbacks.GenericCallback<PerChannelBookieClient>
,PerChannelBookieClientPool
class DefaultPerChannelBookieClientPool extends java.lang.Object implements PerChannelBookieClientPool, BookkeeperInternalCallbacks.GenericCallback<PerChannelBookieClient>
Provide a simple round-robin style channel pool. We could improve it later to do more fantastic things.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) BookieId
address
(package private) PerChannelBookieClient[]
clients
(package private) PerChannelBookieClient[]
clientsV3Enforced
(package private) ClientConfiguration
conf
(package private) java.util.concurrent.atomic.AtomicInteger
counter
(package private) java.util.concurrent.atomic.AtomicLong
errorCounter
(package private) PerChannelBookieClientFactory
factory
(package private) static org.slf4j.Logger
LOG
(package private) SecurityHandlerFactory
shFactory
-
Constructor Summary
Constructors Constructor Description DefaultPerChannelBookieClientPool(ClientConfiguration conf, PerChannelBookieClientFactory factory, BookieId address, int coreSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkTimeoutOnPendingOperations()
Check if any ops on any channel needs to be timed out.void
close(boolean wait)
Close the pool.void
disconnect(boolean wait)
Disconnect the connections in the pool.long
getNumPendingCompletionRequests()
Get the number of pending completion requests in the channel.void
initialize()
initialize the pool.boolean
isWritable(long key)
Returns status of a client.void
obtain(BookkeeperInternalCallbacks.GenericCallback<PerChannelBookieClient> callback, long key)
Obtain a channel from channel pool to execute operations.void
obtain(BookkeeperInternalCallbacks.GenericCallback<PerChannelBookieClient> callback, long key, boolean forceUseV3)
Obtain a channel from channel pool by version to execute operations.void
operationComplete(int rc, PerChannelBookieClient pcbc)
void
recordError()
record any read/write error onPerChannelBookieClientPool
.
-
-
-
Field Detail
-
LOG
static final org.slf4j.Logger LOG
-
factory
final PerChannelBookieClientFactory factory
-
address
final BookieId address
-
clients
final PerChannelBookieClient[] clients
-
clientsV3Enforced
final PerChannelBookieClient[] clientsV3Enforced
-
conf
final ClientConfiguration conf
-
shFactory
SecurityHandlerFactory shFactory
-
counter
final java.util.concurrent.atomic.AtomicInteger counter
-
errorCounter
final java.util.concurrent.atomic.AtomicLong errorCounter
-
-
Constructor Detail
-
DefaultPerChannelBookieClientPool
DefaultPerChannelBookieClientPool(ClientConfiguration conf, PerChannelBookieClientFactory factory, BookieId address, int coreSize) throws SecurityException
- Throws:
SecurityException
-
-
Method Detail
-
operationComplete
public void operationComplete(int rc, PerChannelBookieClient pcbc)
- Specified by:
operationComplete
in interfaceBookkeeperInternalCallbacks.GenericCallback<PerChannelBookieClient>
-
initialize
public void initialize()
Description copied from interface:PerChannelBookieClientPool
initialize the pool. the implementation should not be blocked.- Specified by:
initialize
in interfacePerChannelBookieClientPool
-
obtain
public void obtain(BookkeeperInternalCallbacks.GenericCallback<PerChannelBookieClient> callback, long key)
Description copied from interface:PerChannelBookieClientPool
Obtain a channel from channel pool to execute operations.- Specified by:
obtain
in interfacePerChannelBookieClientPool
- Parameters:
callback
- callback to return channel from channel pool.
-
obtain
public void obtain(BookkeeperInternalCallbacks.GenericCallback<PerChannelBookieClient> callback, long key, boolean forceUseV3)
Description copied from interface:PerChannelBookieClientPool
Obtain a channel from channel pool by version to execute operations.- Specified by:
obtain
in interfacePerChannelBookieClientPool
- Parameters:
callback
- callback to return channel from channel poolforceUseV3
- whether or not use v3 protocol for connection
-
isWritable
public boolean isWritable(long key)
Description copied from interface:PerChannelBookieClientPool
Returns status of a client. It is suggested to delay/throttle requests to this channel if isWritable is false.- Specified by:
isWritable
in interfacePerChannelBookieClientPool
- Returns:
-
checkTimeoutOnPendingOperations
public void checkTimeoutOnPendingOperations()
Description copied from interface:PerChannelBookieClientPool
Check if any ops on any channel needs to be timed out. This is called on all channels, even if the channel is not yet connected.- Specified by:
checkTimeoutOnPendingOperations
in interfacePerChannelBookieClientPool
-
recordError
public void recordError()
Description copied from interface:PerChannelBookieClientPool
record any read/write error onPerChannelBookieClientPool
.- Specified by:
recordError
in interfacePerChannelBookieClientPool
-
disconnect
public void disconnect(boolean wait)
Description copied from interface:PerChannelBookieClientPool
Disconnect the connections in the pool.- Specified by:
disconnect
in interfacePerChannelBookieClientPool
- Parameters:
wait
- whether need to wait until pool disconnected.
-
close
public void close(boolean wait)
Description copied from interface:PerChannelBookieClientPool
Close the pool.- Specified by:
close
in interfacePerChannelBookieClientPool
- Parameters:
wait
- whether need to wait until pool closed.
-
getNumPendingCompletionRequests
public long getNumPendingCompletionRequests()
Description copied from interface:PerChannelBookieClientPool
Get the number of pending completion requests in the channel.- Specified by:
getNumPendingCompletionRequests
in interfacePerChannelBookieClientPool
-
-