com.caucho.log
Class RotateStream

java.lang.Object
  extended by com.caucho.vfs.StreamImpl
      extended by com.caucho.log.RotateStream
All Implemented Interfaces:
AlarmListener, java.util.EventListener

public class RotateStream
extends StreamImpl
implements AlarmListener

Automatically-rotating streams. Normally, clients will call getStream instead of using the StreamImpl interface.


Field Summary
 
Fields inherited from class com.caucho.vfs.StreamImpl
_nullPath, _path
 
Method Summary
 boolean canWrite()
          True if the stream can write
static void clear()
          Clears the streams.
 void close()
          The close call does nothing since the rotate stream is shared for many logs.
static RotateStream create(Path path)
          Returns the rotate stream corresponding to this path
static RotateStream create(java.lang.String path)
          Returns the rotate stream corresponding to this path
 void finalize()
          finalize.
 void flush()
          Flushes the underlying stream.
 Path getPath()
          Returns the Path associated with the stream.
 AbstractRolloverLog getRolloverLog()
          Returns the rollover log.
 WriteStream getStream()
          Gets the current write stream
 void handleAlarm(Alarm alarm)
          Handles a callback from an alarm.
 void init()
          Initialize the stream, setting any logStream, System.out and System.err as necessary.
 void setArchiveFormat(java.lang.String format)
          Sets the archive format.
 void setMaxRolloverCount(int count)
          Sets the maximum number of rolled logs.
 void setRolloverPeriod(long period)
          Sets the log rollover period, rounded up to the nearest hour.
 void write(byte[] buffer, int offset, int length, boolean isEnd)
          Writes to the stream
 
Methods inherited from class com.caucho.vfs.StreamImpl
canRead, clearWrite, closeWrite, flushBuffer, flushToDisk, getAttribute, getAttributeNames, getAvailable, getFlushOnNewline, getNewline, getReadBuffer, getReadPosition, hasSkip, read, readNonBlock, readTimeout, removeAttribute, seekEnd, seekStart, setAttribute, setPath, setWriteEncoding, skip, write
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static RotateStream create(Path path)
Returns the rotate stream corresponding to this path


create

public static RotateStream create(java.lang.String path)
                           throws ConfigException
Returns the rotate stream corresponding to this path

Throws:
ConfigException

clear

public static void clear()
Clears the streams.


getRolloverLog

public AbstractRolloverLog getRolloverLog()
Returns the rollover log.


setMaxRolloverCount

public void setMaxRolloverCount(int count)
Sets the maximum number of rolled logs.


setRolloverPeriod

public void setRolloverPeriod(long period)
Sets the log rollover period, rounded up to the nearest hour.

Parameters:
period - the new rollover period in milliseconds.

setArchiveFormat

public void setArchiveFormat(java.lang.String format)
Sets the archive format.

Parameters:
format - the archive format.

init

public void init()
          throws java.io.IOException
Initialize the stream, setting any logStream, System.out and System.err as necessary.

Throws:
java.io.IOException

getPath

public Path getPath()
Returns the Path associated with the stream.

Overrides:
getPath in class StreamImpl

canWrite

public boolean canWrite()
True if the stream can write

Overrides:
canWrite in class StreamImpl

write

public void write(byte[] buffer,
                  int offset,
                  int length,
                  boolean isEnd)
           throws java.io.IOException
Writes to the stream

Overrides:
write in class StreamImpl
Parameters:
buffer - the byte array to write.
offset - the offset into the byte array.
length - the number of bytes to write.
isEnd - true when the write is flushing a close.
Throws:
java.io.IOException

getStream

public WriteStream getStream()
Gets the current write stream


flush

public void flush()
           throws java.io.IOException
Flushes the underlying stream.

Overrides:
flush in class StreamImpl
Throws:
java.io.IOException

close

public void close()
The close call does nothing since the rotate stream is shared for many logs.

Overrides:
close in class StreamImpl

handleAlarm

public void handleAlarm(Alarm alarm)
Description copied from interface: AlarmListener
Handles a callback from an alarm.

Specified by:
handleAlarm in interface AlarmListener

finalize

public void finalize()
finalize.

Overrides:
finalize in class java.lang.Object