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 /**
33 * A pool of HBaseWriters.
34 */
35 public class HBaseWriterPool extends WriterPool {
36
37 /**
38 * Constructor.
39 *
40 * @param zkQuorum the list of zookeeper quorum servers that serve HBase, comma seperated.
41 * i.e.: zkHost1,zkHost2,zkHost3
42 * @param table the table name in HBase
43 * @param poolMaximumActive the pool maximum active
44 * @param poolMaximumWait the pool maximum wait
45 */
46 public HBaseWriterPool(final String zkQuorum, final int zkClientPort, final String table, final int poolMaximumActive, final int poolMaximumWait) {
47 // Below is hard to follow. Its invocation of this classes super
48 // constructor passing a serial, an instance of BasePoolable.. that
49 // is defined in line, followed by settings, max and wait.
50 super(
51 // a serial
52 new AtomicInteger(),
53 // Poolable factory
54 new BasePoolableObjectFactory() {
55 public Object makeObject() throws Exception {
56 return new HBaseWriter(zkQuorum, zkClientPort, table);
57 }
58
59 public void destroyObject(Object arcWriter) throws Exception {
60 ((WriterPoolMember) arcWriter).close();
61 super.destroyObject(arcWriter);
62 }
63 },
64 // default writer pool settings...
65 new DefaultWriterPoolSettings(),
66 // maximum active writers in the writer pool
67 poolMaximumActive,
68 // maximum wait time
69 poolMaximumWait);
70 }
71 }