View Javadoc

1   /** HBaseWriterPool
2    *
3    * $Id$
4    *
5    * Created on June 23rd, 2007
6    *
7    * This file is part of the Heritrix web crawler (crawler.archive.org).
8    *
9    * Heritrix is free software; you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser Public License as published by
11   * the Free Software Foundation; either version 2.1 of the License, or
12   * any later version.
13   *
14   * Heritrix is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU Lesser Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser Public License
20   * along with Heritrix; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22   */
23  package com.powerset.heritrix.writer;
24  
25  import java.util.concurrent.atomic.AtomicInteger;
26  
27  import org.apache.commons.pool.BasePoolableObjectFactory;
28  import org.archive.io.DefaultWriterPoolSettings;
29  import org.archive.io.WriterPool;
30  import org.archive.io.WriterPoolMember;
31  
32  // TODO: Auto-generated Javadoc
33  /**
34   * A pool of HBaseWriters.
35   */
36  public class HBaseWriterPool extends WriterPool {
37  	
38  	/**
39  	 * Constructor.
40  	 * 
41  	 * @param zkQuorum the list of zookeeper quorum servers that serve HBase, comma seperated.
42  	 * i.e.:  zkHost1,zkHost2,zkHost3
43  	 * @param zkClientPort the port that clients should connect to on the given zk quorum servers.
44  	 * i.e.:  2181
45  	 * @param table the table name in HBase
46  	 * @param poolMaximumActive the maximum number of writers in the writer pool.
47  	 * @param poolMaximumWait the maximum waittime for all writers in the pool.
48  	 */
49  	public HBaseWriterPool(final String zkQuorum, final int zkClientPort, final String table, final int poolMaximumActive, final int poolMaximumWait) {
50  		// Below is hard to follow. Its invocation of this classes super
51  		// constructor passing a serial, an instance of BasePoolable.. that
52  		// is defined in line, followed by settings, max and wait.
53  		super(
54  			// a serial	
55  			new AtomicInteger(), 
56  			// Poolable factory
57  			new BasePoolableObjectFactory() {
58  				public Object makeObject() throws Exception {
59  					return new HBaseWriter(zkQuorum, zkClientPort, table);
60  				}
61  
62  				public void destroyObject(Object arcWriter) throws Exception {
63  					((WriterPoolMember) arcWriter).close();
64  					super.destroyObject(arcWriter);
65  				}
66  			}, 
67  			// default writer pool settings...
68  			new DefaultWriterPoolSettings(), 
69  			// maximum active writers in the writer pool
70  			poolMaximumActive,
71  			// maximum wait time
72  			poolMaximumWait);
73  	}
74  }