org.archive.io
Class WriterPool

java.lang.Object
  extended by org.archive.io.WriterPool
Direct Known Subclasses:
ARCWriterPool, WARCWriterPool

public abstract class WriterPool
extends java.lang.Object

Pool of Writers. Abstract. Override and pass in the Constructor a factory that creates WriterPoolMember implementations.

Author:
stack

Field Summary
static int DEFAULT_MAX_ACTIVE
          Default maximum active number of files in the pool.
static int DEFAULT_MAXIMUM_WAIT
          Maximum time to wait on a free file..
(package private)  java.util.logging.Logger logger
           
protected static int NO_MAX_IDLE
          Don't enforce a maximum number of idle instances in pool.
 
Constructor Summary
WriterPool(java.util.concurrent.atomic.AtomicInteger serial, org.apache.commons.pool.BasePoolableObjectFactory factory, WriterPoolSettings settings, int poolMaximumActive, int poolMaximumWait)
          Constructor
 
Method Summary
 WriterPoolMember borrowFile()
          Check out a WriterPoolMember.
 void close()
          Close all WriterPoolMembers in pool.
 int getNumActive()
           
 int getNumIdle()
           
protected  java.lang.String getPoolState()
           
protected  java.lang.String getPoolState(long startTime)
           
 java.util.concurrent.atomic.AtomicInteger getSerialNo()
          Returns the atomic integer used to generate serial numbers for files.
 WriterPoolSettings getSettings()
           
 void invalidateFile(WriterPoolMember f)
           
 void returnFile(WriterPoolMember writer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

final java.util.logging.Logger logger

NO_MAX_IDLE

protected static final int NO_MAX_IDLE
Don't enforce a maximum number of idle instances in pool. To do so means GenericObjectPool will close files prematurely.

See Also:
Constant Field Values

DEFAULT_MAX_ACTIVE

public static final int DEFAULT_MAX_ACTIVE
Default maximum active number of files in the pool.

See Also:
Constant Field Values

DEFAULT_MAXIMUM_WAIT

public static final int DEFAULT_MAXIMUM_WAIT
Maximum time to wait on a free file..

See Also:
Constant Field Values
Constructor Detail

WriterPool

public WriterPool(java.util.concurrent.atomic.AtomicInteger serial,
                  org.apache.commons.pool.BasePoolableObjectFactory factory,
                  WriterPoolSettings settings,
                  int poolMaximumActive,
                  int poolMaximumWait)
Constructor

Parameters:
serial - Used to generate unique filename sequences
factory - Factory that knows how to make a WriterPoolMember.
settings - Settings for this pool.
poolMaximumActive -
poolMaximumWait -
Method Detail

borrowFile

public WriterPoolMember borrowFile()
                            throws java.io.IOException
Check out a WriterPoolMember. This method must be answered by a call to returnFile(WriterPoolMember) else pool starts leaking.

Returns:
Writer checked out of a pool of files.
Throws:
java.io.IOException - Problem getting Writer from pool (Converted from Exception to IOException so this pool can live as a good citizen down in depths of ARCSocketFactory).
java.util.NoSuchElementException - If we time out waiting on a pool member.

returnFile

public void returnFile(WriterPoolMember writer)
                throws java.io.IOException
Parameters:
writer - Writer to return to the pool.
Throws:
java.io.IOException - Problem returning File to pool.

invalidateFile

public void invalidateFile(WriterPoolMember f)
                    throws java.io.IOException
Throws:
java.io.IOException

getNumActive

public int getNumActive()
                 throws java.lang.UnsupportedOperationException
Returns:
Number of WriterPoolMembers checked out of pool.
Throws:
java.lang.UnsupportedOperationException

getNumIdle

public int getNumIdle()
               throws java.lang.UnsupportedOperationException
Returns:
Number of WriterPoolMember instances still in the pool.
Throws:
java.lang.UnsupportedOperationException

close

public void close()
Close all WriterPoolMembers in pool.


getSettings

public WriterPoolSettings getSettings()
Returns:
Returns settings.

getPoolState

protected java.lang.String getPoolState()
Returns:
State of the pool string

getPoolState

protected java.lang.String getPoolState(long startTime)
Parameters:
startTime - If we are passed a start time, we'll add difference between it and now to end of string. Pass -1 if don't want this added to end of state string.
Returns:
State of the pool string

getSerialNo

public java.util.concurrent.atomic.AtomicInteger getSerialNo()
Returns the atomic integer used to generate serial numbers for files.

Returns:
the serial number generator


Copyright © 2003-2011 Internet Archive. All Rights Reserved.