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