public abstract class WriterPool
extends java.lang.Object
WriterPoolMember implementations.| Modifier and Type | Field and Description |
|---|---|
protected java.util.concurrent.BlockingQueue<WriterPoolMember> |
availableWriters
round-robin queue of available writers
|
protected int |
currentActive
current count of active writers; only read/mutated in synchronized blocks
|
static int |
DEFAULT_MAX_ACTIVE
Default maximum active number of files in the pool.
|
static int |
DEFAULT_MAX_WAIT_FOR_IDLE
Maximum time to wait on a free file before considering
making a new one (if not already at max)
|
protected static int |
LARGEST_MAX_ACTIVE
Assumed largest possible value of maxActive; pool will have this
maximum capacity, so dynamic changes beyond this number won't work.
|
protected long |
lastWriterNeededTime
system time when writer was last wanted (because one was not ready in time)
|
protected long |
lastWriterRolloverTime
system time when writer was last 'rolled over' (imminent creation of new file)
|
protected int |
maxActive
maximum number of writers to create at a time
|
protected int |
maxWait
maximum ms to wait before considering creation of a writer
|
protected java.util.concurrent.atomic.AtomicInteger |
serialNo
Used to generate unique filename sequences.
|
protected WriterPoolSettings |
settings
File settings.
|
| Constructor and Description |
|---|
WriterPool(java.util.concurrent.atomic.AtomicInteger serial,
WriterPoolSettings settings,
int poolMaximumActive,
int poolMaximumWait)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
WriterPoolMember |
borrowFile()
Check out a
WriterPoolMember. |
void |
close()
Close all
WriterPoolMembers in pool. |
void |
destroyWriter(WriterPoolMember writer)
Discard a previously-used writer, cleanly closing it and leaving it out
of the pool.
|
protected java.util.Collection<WriterPoolMember> |
drainAllWriters()
Drains all the active writers from
availableWriters, blocking to
wait for any writers currently in use to become available. |
void |
flush() |
int |
getNumActive() |
int |
getNumIdle() |
protected java.lang.String |
getPoolState() |
java.util.concurrent.atomic.AtomicInteger |
getSerialNo()
Returns the atomic integer used to generate serial numbers
for files.
|
WriterPoolSettings |
getSettings() |
void |
invalidateFile(WriterPoolMember f)
Close and discard a writer that experienced a potentially-corrupting
error.
|
org.json.JSONArray |
jsonStatus() |
protected WriterPoolMember |
makeNewWriterIfAppropriate()
Create a new writer instance, if still below maxActive count.
|
protected abstract WriterPoolMember |
makeWriter() |
void |
returnFile(WriterPoolMember writer)
Return a writer, for likely reuse unless (1) writer's current file has
reached its target size; and (2) there's been no demand for additional
writers since the last time a new writer-file was rolled-over.
|
protected final java.util.concurrent.atomic.AtomicInteger serialNo
public static final int DEFAULT_MAX_ACTIVE
protected static final int LARGEST_MAX_ACTIVE
public static final int DEFAULT_MAX_WAIT_FOR_IDLE
protected final WriterPoolSettings settings
protected int maxActive
protected int maxWait
protected int currentActive
protected java.util.concurrent.BlockingQueue<WriterPoolMember> availableWriters
protected long lastWriterNeededTime
protected long lastWriterRolloverTime
public WriterPool(java.util.concurrent.atomic.AtomicInteger serial,
WriterPoolSettings settings,
int poolMaximumActive,
int poolMaximumWait)
serial - Used to generate unique filename sequencesfactory - Factory that knows how to make a WriterPoolMember.settings - Settings for this pool.poolMaximumActive - poolMaximumWait - public WriterPoolMember borrowFile() throws java.io.IOException
WriterPoolMember.
This method should be followed by a call to
returnFile(WriterPoolMember) or
invalidateFile(WriterPoolMember) else pool starts leaking.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).protected WriterPoolMember makeNewWriterIfAppropriate()
protected abstract WriterPoolMember makeWriter()
public void destroyWriter(WriterPoolMember writer) throws java.io.IOException
writer - java.io.IOExceptionpublic void returnFile(WriterPoolMember writer) throws java.io.IOException
writer - Writer to return to the pool.java.io.IOException - Problem returning File to pool.public void invalidateFile(WriterPoolMember f) throws java.io.IOException
f - writer with problemjava.io.IOExceptionpublic int getNumActive()
throws java.lang.UnsupportedOperationException
WriterPoolMembers checked out of pool.java.lang.UnsupportedOperationExceptionpublic int getNumIdle()
throws java.lang.UnsupportedOperationException
WriterPoolMember instances still in the pool.java.lang.UnsupportedOperationExceptionpublic void close()
WriterPoolMembers in pool.public WriterPoolSettings getSettings()
protected java.lang.String getPoolState()
public java.util.concurrent.atomic.AtomicInteger getSerialNo()
protected java.util.Collection<WriterPoolMember> drainAllWriters()
availableWriters, blocking to
wait for any writers currently in use to become available.
When finished with writers, call availableWriters.addAll(...) to put them back into the rotation.
public void flush()
public org.json.JSONArray jsonStatus()
throws org.json.JSONException
org.json.JSONExceptionCopyright © 2019 The International Internet Preservation Consortium. All Rights Reserved.