@SuppressWarnings("unchecked")
@Override
public void onCheckOut(ConnectionHandle connection) {
if (connection.getDebugHandle() == HACK_PARTITION_FLAG) {
try {
final ConnectionPartition partition = connection.getOriginatingPartition();
final Method getFreeConnections = partition.getClass().getDeclaredMethod("getFreeConnections");
getFreeConnections.setAccessible(true);
TransferQueue<ConnectionHandle> connections = (TransferQueue<ConnectionHandle>) getFreeConnections.invoke(partition);
if (!(connections instanceof TransferQueueWithBlockingOperationHook)) {
synchronized (partition) {
connections = (TransferQueue<ConnectionHandle>) getFreeConnections.invoke(partition);
if (!(connections instanceof TransferQueueWithBlockingOperationHook)) {
final Method setFreeConnections = partition.getClass().getDeclaredMethod("setFreeConnections", TransferQueue.class);
setFreeConnections.setAccessible(true);
setFreeConnections.invoke(partition, new TransferQueueWithBlockingOperationHook<ConnectionHandle>(connections));
}
}
}