i have small hbase cluster running java frontend. have working test code establishes connection, runs test data, , disconnects, need extend webapp part of larger project. suggested use tomcat http service interface database, , part of need set connection pool.
i understand connection pools on conceptual level (a pile of persistent connections db handed out clients needed , returned pool when discarded), i've never written webapp before , tomcat vexxing me. can find loads of documentation on how setup connection pool sql server using jdbc, nothing on hbase (or, matter, sql) , nothing on how (or whether can or should) write custom interface working tomcat. doable, or possible, or should taking different approach?
i think hard find made tomcat, don't think such thing exist. people using custom classes. being said, should build around htablepool comes hbase.
here example of can use in project :
public class htablemanager { public static int htable_pool_size = 15; private static htablemanager instance; private static htablepool htablepool; /** * private constructor */ private htablemanager() { try { configuration config = hbaseconfiguration.create(); config.set("hbase.defaults.for.version.skip", "false"); htablepool = new htablepool(config, htable_pool_size); } catch (ioexception ex) { // error handling } } /** * @return hbasetablemanager instance */ public static htablemanager getinstance() { if (instance == null) { instance = new htablemanager(); } return instance; } /** * method used retrieve htable instance. * * @param tablename table name * @return htableinterface instance * @throws ioexception */ public synchronized htableinterface gethtable(string tablename) throws ioexception { return htablepool.gettable(tablename); } } and can use :
htablemanager htablemanager = htablemanager.getinstance(); htableinterface htable = htablemanager.gethtable("yourtablename"); ... // work htable instance ... // call close method returns pool htable.close();
Comments
Post a Comment