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 poolMaximumActive the pool maximum active
42 * @param poolMaximumWait the pool maximum wait
43 * @param master the master
44 * @param table the table
45 */
46 public HBaseWriterPool(final String master, 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(new AtomicInteger(), new BasePoolableObjectFactory() {
51 public Object makeObject() throws Exception {
52 return new HBaseWriter(master, table);
53 }
54
55 public void destroyObject(Object arcWriter) throws Exception {
56 ((WriterPoolMember) arcWriter).close();
57 super.destroyObject(arcWriter);
58 }
59 }, new DefaultWriterPoolSettings(), poolMaximumActive, poolMaximumWait);
60 }
61 }