View Javadoc

1   /* ARCWriterPool
2    *
3    * $Id: ARCWriterPool.java 4535 2006-08-25 00:14:29Z stack-sf $
4    *
5    * Created on Jan 22, 2004
6    *
7    * Copyright (C) 2004 Internet Archive.
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 org.archive.io.arc;
26  
27  import java.util.concurrent.atomic.AtomicInteger;
28  
29  import org.apache.commons.pool.BasePoolableObjectFactory;
30  import org.archive.io.WriterPool;
31  import org.archive.io.WriterPoolMember;
32  import org.archive.io.WriterPoolSettings;
33  
34  
35  /***
36   * A pool of ARCWriters.
37   *
38   * @author stack
39   */
40  public class ARCWriterPool extends WriterPool {
41      /***
42       * Constructor
43       *
44       * @param settings Settings for this pool.
45       * @param poolMaximumActive
46       * @param poolMaximumWait
47       */
48      public ARCWriterPool(final WriterPoolSettings settings,
49              final int poolMaximumActive, final int poolMaximumWait) {
50          this(new AtomicInteger(), settings, poolMaximumActive, poolMaximumWait);
51      }
52  
53      /***
54       * Constructor
55       *
56       * @param serial  Used to generate unique filename sequences
57       * @param settings Settings for this pool.
58       * @param poolMaximumActive
59       * @param poolMaximumWait
60       */
61      public ARCWriterPool(final AtomicInteger serial,
62      		final WriterPoolSettings settings,
63              final int poolMaximumActive, final int poolMaximumWait) {
64      	super(serial, new BasePoolableObjectFactory() {
65              public Object makeObject() throws Exception {
66                  return new ARCWriter(serial, settings.getOutputDirs(),
67                          settings.getPrefix(), settings.getSuffix(),
68                          settings.isCompressed(), settings.getMaxSize(),
69                          settings.getMetadata());
70              }
71  
72              public void destroyObject(Object arcWriter)
73              throws Exception {
74                  ((WriterPoolMember)arcWriter).close();
75                  super.destroyObject(arcWriter);
76              }
77      	}, settings, poolMaximumActive, poolMaximumWait);
78      }
79  }