1 /** HBaseWriterPool
2 *
3 * $Id$
4 *
5 * Created on June 23rd, 2007
6 *
7 * Copyright (C) 2007 stack
8 *
9 * This file is part of the Heritrix web crawler (crawler.archive.org).
10 *
11 * Heritrix is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * any later version.
15 *
16 * Heritrix is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser Public License
22 * along with Heritrix; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25 package com.powerset.heritrix.writer;
26
27 import java.util.concurrent.atomic.AtomicInteger;
28
29 import org.apache.commons.pool.BasePoolableObjectFactory;
30 import org.archive.io.DefaultWriterPoolSettings;
31 import org.archive.io.WriterPool;
32 import org.archive.io.WriterPoolMember;
33
34
35 /**
36 * A pool of HBaseWriters.
37 * @author stack
38 */
39 public class HBaseWriterPool extends WriterPool {
40 /**
41 * Constructor
42 * @param poolMaximumActive
43 * @param poolMaximumWait
44 */
45 public HBaseWriterPool(final String master, final String table,
46 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)
56 throws Exception {
57 ((WriterPoolMember)arcWriter).close();
58 super.destroyObject(arcWriter);
59 }
60 }, new DefaultWriterPoolSettings(), poolMaximumActive, poolMaximumWait);
61 }
62 }