You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hbase.apache.org by Ioan Eugen Stan <st...@gmail.com> on 2012/01/10 11:57:08 UTC

HTableInterface to extend java.io.Closeable

Hello,

In my code I get to write a lot of boilerplate code to close a HTable
instance (see below snippet). Making HTableInterface extent
java.io.Closeable would allow developers to use IOUtils.closeQuietly()
from appache-commons or a similar method to cose a HTable instance
without the extra code. What do you think?

       HTable table = null;
        try {
            table = new HTable(conf , "some table");
            ResultScanner scanner = table.getScanner(scan);
            Result result;
            while ((result = scanner.next()) != null) {
                 // do something
            }
            scanner.close();  // close the scanner
        } catch (IOException e) {
            LOG.error("Exception scanning in table");
        } finally {
         // close the table
            if (table != null) {
                try {
                    table.close();
                } catch (IOException e) {

                }
            }
        }


Cheers,

-- 
Ioan Eugen Stan
http://ieugen.blogspot.com/

Re: HTableInterface to extend java.io.Closeable

Posted by Ted Yu <yu...@gmail.com>.
This is an interesting idea.

HTable already implements Closeable.

Do you mind filing a JIRA (and optionally a patch) ?

Thanks

On Tue, Jan 10, 2012 at 2:57 AM, Ioan Eugen Stan <st...@gmail.com>wrote:

> Hello,
>
> In my code I get to write a lot of boilerplate code to close a HTable
> instance (see below snippet). Making HTableInterface extent
> java.io.Closeable would allow developers to use IOUtils.closeQuietly()
> from appache-commons or a similar method to cose a HTable instance
> without the extra code. What do you think?
>
>       HTable table = null;
>        try {
>            table = new HTable(conf , "some table");
>            ResultScanner scanner = table.getScanner(scan);
>            Result result;
>            while ((result = scanner.next()) != null) {
>                 // do something
>            }
>            scanner.close();  // close the scanner
>        } catch (IOException e) {
>            LOG.error("Exception scanning in table");
>        } finally {
>         // close the table
>            if (table != null) {
>                try {
>                    table.close();
>                } catch (IOException e) {
>
>                }
>            }
>        }
>
>
> Cheers,
>
> --
> Ioan Eugen Stan
> http://ieugen.blogspot.com/
>