public class MFileSink extends MSink
MFileSink
is a file with an associated filename,
sink name, and role that can receive messages from a trace.
In most cases, custom adapters specify a file sink in the adapter instance description object using the Monitoring tab of the TIBCO Designer software. In that case, the SDK goes through these steps:
fileLimit
.
When fileLimit
has been reached (that is, as soon as the file is as big
as or bigger than the limit) the SDK renames the current file to
file.1 and creates a new file with the specified name.
The log file can be slightly larger than the limit because the new file is only created after the limit has been reached.
The adapter overwrites the file with the lowest number (the oldest
file) when the number of files reaches fileCount
and that last file
reaches fileLimit. To avoid that, set either fileCount
or fileLimit
to a sufficiently large value.
m_registry
Constructor and Description |
---|
MFileSink(MComponentRegistry registry,
java.lang.String sinkName,
java.lang.String fileName)
This form of the constructor creates a file sink with no size limit
and no swapping.
|
MFileSink(MComponentRegistry registry,
java.lang.String sinkName,
java.lang.String fileName,
int fileSizeLimit,
int numFiles,
boolean appendData)
Constructor.
|
MFileSink(MComponentRegistry registry,
java.lang.String sinkName,
java.lang.String fileName,
int fileSizeLimit,
int numFiles,
int timeInterval,
java.lang.String charsetName,
boolean appendData)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
closeSink()
Flush and close the file writer
|
void |
flushSink()
Flush data to the sink destination.
|
java.lang.String |
getFileEncoding()
Return the sink file encoding.
|
int |
getFileLength()
Return the limit on the file size for this file sink, as specified in the constructor.
|
java.lang.String |
getFileName()
Return the file name of this file sink.
|
int |
getNumFiles()
Return the total number of historical log files this file sink will keep,
including the file being written to.
|
int |
getTimeInterval()
Returns time interval in seconds, used for duration based rollover of sink file.
|
void |
setFileEncoding(java.lang.String fileEncoding)
Set sink file encoding
|
void |
setFileLength(int length)
Change the maximum file length for this file sink.
|
void |
setFileName(java.lang.String fileName)
Change the file name for this file sink.
|
void |
setFileName(java.lang.String fileName,
java.lang.String charsetName)
Change the file name for this file sink.
|
void |
setTimeInterval(int timeInterval)
Set time interval
|
java.lang.String |
toString() |
void |
write(java.lang.String msg,
boolean flush)
Write the specified string message to the named file
|
void |
write(java.lang.String msgPrefix,
MTree tree,
boolean flush)
Serialize the specified MTree object to this sink
|
void |
write(java.lang.Throwable ex,
boolean flush) |
activate, deactivate, getComponentRegistry, getName, getStatus, isActivated, remove
public MFileSink(MComponentRegistry registry, java.lang.String sinkName, java.lang.String fileName, int fileSizeLimit, int numFiles, boolean appendData) throws MException
registry
- Component registry in which this file sink is being created.
Use MApp.getComponentRegistry()
to retrieve the component registry for an application.sinkName
- Sink name associated with this instance of the class.
The sink name has no relationship with the role of the sink. The role is
defined when the sink and a trace are matched.fileName
- Name of the file.fileSizeLimit
- Maximum number of bytes for any file associated with this
sink. If the file becomes larger than this number, the SDK creates a new file
and writes to that file until numFiles
files have been created. A number less
than 0 means no limit.numFiles
- If the filesink becomes larger than fileSizeLimit
,
the system creates a new file and writes new data to that file until it
has created numFiles
. At that point, it starts to overwrite the first file.
A number less than 2 means no swapping.appendData
- If true
, append to this file if a file
with the specified file name already exists. If false
, erase the existing
file and create a new one.MException
- if the file cannot be opened for writing.public MFileSink(MComponentRegistry registry, java.lang.String sinkName, java.lang.String fileName, int fileSizeLimit, int numFiles, int timeInterval, java.lang.String charsetName, boolean appendData) throws MException
registry
- Component registry in which this file sink is being created.
Use MApp.getComponentRegistry()
to retrieve the component registry for an application.sinkName
- Sink name associated with this instance of the class.
The sink name has no relationship with the role of the sink. The role is
defined when the sink and a trace are matched.fileName
- Name of the file.fileSizeLimit
- Maximum number of bytes for any file associated with this
sink. If the file becomes larger than this number, the SDK creates a new file
and writes to that file until numFiles
files have been created. A number less
than 0 means no limit.numFiles
- If the filesink becomes larger than fileSizeLimit
,
the system creates a new file and writes new data to that file until it
has created numFiles
. At that point, it starts to overwrite the first file.
A number less than 2 means no swapping.timeInterval
- Time interval in seconds for any file associated with this
sink. If the current time is greater than file creation time plus this interval,
then SDK creates a new file.charsetName
- Using this encoding file write will be performed.appendData
- If true
, append to this file if a file
with the specified file name already exists. If false
, erase the existing
file and create a new one.MException
- if the file cannot be opened for writing.public MFileSink(MComponentRegistry registry, java.lang.String sinkName, java.lang.String fileName) throws MException
registry
- Component registry in which this file sink is being created.
Use app.getComponentRegistry()
to retrieve the component registry for an application.sinkName
- Sink name associated with this instance of the class.
The sink name has no relationship with the role of the sink. The role is
defined when the sink and a trace are matched.fileName
- Name of the file.MException
- if the file cannot be opened for writing.public java.lang.String getFileName()
public void setFileName(java.lang.String fileName) throws MException
fileName
- is the new name.MException
public void setFileName(java.lang.String fileName, java.lang.String charsetName) throws MException
fileName
- is the new name.charsetName
- is to set encoding to a sink fileMException
public int getFileLength()
public void setFileLength(int length)
length
- is the length in bytes.public int getNumFiles()
public java.lang.String getFileEncoding()
public void setFileEncoding(java.lang.String fileEncoding) throws MNestedException
fileEncoding
- encoding in which sink file is to be writtenMNestedException
public int getTimeInterval()
public void setTimeInterval(int timeInterval)
timeInterval
- TimeInterval after which file is to renamepublic void write(java.lang.Throwable ex, boolean flush)
public void write(java.lang.String msg, boolean flush)
public void write(java.lang.String msgPrefix, MTree tree, boolean flush)
public void closeSink()
closeSink
in class MSink
MSink.flushSink()
public void flushSink()
flushSink
in class MSink
MSink.closeSink()