All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.datasift.dropwizard.hbase.ManagedHBaseClient Maven / Gradle / Ivy

There is a newer version: 0.7.1-1
Show newest version
package com.datasift.dropwizard.hbase;

import com.yammer.dropwizard.lifecycle.Managed;
import com.yammer.dropwizard.util.Duration;

/**
 * Manages the lifecycle of an {@link HBaseClient}.
 */
public class ManagedHBaseClient implements Managed {

    private final HBaseClient client;
    private final Duration connectionTimeout;

    /**
     * Manage the specified {@link HBaseClient} with the given {@code connectionTimeout}.
     *
     * @param client the {@link HBaseClient} to manage.
     * @param connectionTimeout the maximum time to wait for a connection to a region server or
     *                          ZooKeeper quorum.
     */
    public ManagedHBaseClient(final HBaseClient client, final Duration connectionTimeout) {
        this.client = client;
        this.connectionTimeout = connectionTimeout;
    }

    /**
     * Forces connection of the {@link HBaseClient}.
     *
     * To force the connection, we look for the prescence of the .META. table.
     *
     * @throws com.stumbleupon.async.TimeoutException if there is a problem connecting to HBase.
     * @throws org.hbase.async.TableNotFoundException if the .META. table can't be found.
     * @throws Exception if there is a problem verifying the .META. table exists.
     */
    public void start() throws Exception {
        client.ensureTableExists(".META.").joinUninterruptibly(connectionTimeout.toMilliseconds());
    }

    /**
     * Shutsdown the {@link HBaseClient}, waiting until shutdown is complete.
     *
     * @throws Exception if there is a problem shutting the {@link HBaseClient} down.
     */
    public void stop() throws Exception {
        client.shutdown().joinUninterruptibly();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy