|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.OutputStream
ch.qos.logback.ext.loggly.io.DiscardingRollingOutputStream
public class DiscardingRollingOutputStream
Capped in-memory OutputStream composed of a chain of ByteArrayOutputStream called 'buckets'.
Each 'bucket' is limited in size (see maxBucketSizeInBytes) and the total size of the OutputStream
is bounded thanks to a discarding policy. An external component is expected to consume the filled buckets thanks to
getFilledBuckets().
Implementation decisions:
FileBackedOutputStream but had the drawback to introduce a dependency. Loggly batch appender use case
should be OK with a pure in-memory approach.
| Field Summary | |
|---|---|
static String |
LINE_SEPARATOR
|
| Constructor Summary | |
|---|---|
DiscardingRollingOutputStream(int maxBucketSizeInBytes,
int maxBucketCount)
|
|
| Method Summary | |
|---|---|
void |
close()
Close all the underlying buckets (current bucket, filled buckets and buckets from the recycled buckets pool). |
void |
flush()
|
long |
getCurrentOutputStreamSize()
|
int |
getDiscardedBucketCount()
Number of discarded buckets. |
BlockingDeque<ByteArrayOutputStream> |
getFilledBuckets()
Return the filled buckets |
protected ByteArrayOutputStream |
newBucket()
Get a new bucket from the recycledBucketPool or instantiate a new one if none available
in the free bucket pool. |
protected void |
onBucketDiscard(ByteArrayOutputStream discardedBucket)
Designed for extension. |
protected void |
onBucketRoll(ByteArrayOutputStream rolledBucket)
The rolled bucket. |
void |
recycleBucket(ByteArrayOutputStream bucket)
Returns the given bucket to the pool of free buckets. |
void |
rollCurrentBucket()
Moves the current active bucket to the list of filled buckets and defines a new one. |
void |
rollCurrentBucketIfNotEmpty()
Roll current bucket if size threshold has been reached. |
String |
toString()
|
void |
write(byte[] b)
|
void |
write(byte[] b,
int off,
int len)
|
void |
write(int b)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String LINE_SEPARATOR
| Constructor Detail |
|---|
public DiscardingRollingOutputStream(int maxBucketSizeInBytes,
int maxBucketCount)
maxBucketSizeInBytes - maxBucketCount - | Method Detail |
|---|
public void write(int b)
throws IOException
write in class OutputStreamIOException
public void write(byte[] b)
throws IOException
write in class OutputStreamIOException
public void write(byte[] b,
int off,
int len)
throws IOException
write in class OutputStreamIOException
public void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOExceptionpublic void close()
close in interface Closeableclose in class OutputStreampublic void rollCurrentBucketIfNotEmpty()
public void rollCurrentBucket()
recycledBucketPool pool if one is available or recreated.
protected void onBucketDiscard(ByteArrayOutputStream discardedBucket)
discardedBucket - the discarded bucketprotected void onBucketRoll(ByteArrayOutputStream rolledBucket)
rolledBucket - the discarded bucketprotected ByteArrayOutputStream newBucket()
recycledBucketPool or instantiate a new one if none available
in the free bucket pool.
public void recycleBucket(ByteArrayOutputStream bucket)
bucket - the bucket to recyclepublic BlockingDeque<ByteArrayOutputStream> getFilledBuckets()
public int getDiscardedBucketCount()
public long getCurrentOutputStreamSize()
public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||