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  /**
33   * A pool of HBaseWriters.
34   */
35  public class HBaseWriterPool extends WriterPool {
36  	/**
37  	 * Constructor
38  	 * 
39  	 * @param poolMaximumActive
40  	 * @param poolMaximumWait
41  	 */
42  	public HBaseWriterPool(final String master, final String table, final int poolMaximumActive, final int poolMaximumWait) {
43  		// Below is hard to follow. Its invocation of this classes super
44  		// constructor passing a serial, an instance of BasePoolable.. that
45  		// is defined in line, followed by settings, max and wait.
46  		super(new AtomicInteger(), new BasePoolableObjectFactory() {
47  			public Object makeObject() throws Exception {
48  				return new HBaseWriter(master, table);
49  			}
50  
51  			public void destroyObject(Object arcWriter) throws Exception {
52  				((WriterPoolMember) arcWriter).close();
53  				super.destroyObject(arcWriter);
54  			}
55  		}, new DefaultWriterPoolSettings(), poolMaximumActive, poolMaximumWait);
56  	}
57  }