01: /* ARCWriterPool
02: *
03: * $Id: ARCWriterPool.java 4535 2006-08-25 00:14:29Z stack-sf $
04: *
05: * Created on Jan 22, 2004
06: *
07: * Copyright (C) 2004 Internet Archive.
08: *
09: * 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: * A pool of ARCWriters.
36: *
37: * @author stack
38: */
39: public class ARCWriterPool extends WriterPool {
40: /**
41: * Constructor
42: *
43: * @param settings Settings for this pool.
44: * @param poolMaximumActive
45: * @param poolMaximumWait
46: */
47: public ARCWriterPool(final WriterPoolSettings settings,
48: final int poolMaximumActive, final int poolMaximumWait) {
49: this (new AtomicInteger(), settings, poolMaximumActive,
50: 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: }
|