gracefulPeriodExpired = 0L;
attempts = 0;
return false;
}
ChukwaAgent agent = ChukwaAgent.getAgent();
if (agent != null) {
agent.stopAdaptor(adaptorID, false);
} else {
log.info("Agent is null, running in default mode");
}
return false;
} else if (!toWatch.exists() || !toWatch.canRead()) {
if (adaptorInError == false) {
long now = System.currentTimeMillis();
gracefulPeriodExpired = now + GRACEFUL_PERIOD;
adaptorInError = true;
attempts = 0;
log.warn("failed to stream data for: " + toWatch.getAbsolutePath()
+ ", graceful period will Expire at now:" + now + " + "
+ GRACEFUL_PERIOD + " secs, i.e:" + gracefulPeriodExpired);
} else if (attempts % 10 == 0) {
log.info("failed to stream data for: " + toWatch.getAbsolutePath()
+ ", attempt: " + attempts);
}
attempts++;
return false; // no more data
}
if (reader == null) {
reader = new RandomAccessFile(toWatch, "r");
log.info("Adaptor|" + adaptorID
+ "|Opening the file for the first time|seek|" + fileReadOffset);
}
long len = 0L;
try {
RandomAccessFile newReader = new RandomAccessFile(toWatch, "r");
len = reader.length();
long newLength = newReader.length();
if (newLength < len && fileReadOffset >= len) {
if (reader != null) {
reader.close();
}
reader = newReader;
fileReadOffset = 0L;
log.debug("Adaptor|" + adaptorID
+ "| File size mismatched, rotating: "
+ toWatch.getAbsolutePath());
} else {
try {
if (newReader != null) {
newReader.close();
}
newReader =null;
} catch (Throwable e) {
// do nothing.
}
}
} catch (IOException e) {
// do nothing, if file doesn't exist.
}
if (len >= fileReadOffset) {
if (offsetOfFirstByte > fileReadOffset) {
// If the file rotated, the recorded offsetOfFirstByte is greater than
// file size,
// reset the first byte position to beginning of the file.
fileReadOffset = 0;
offsetOfFirstByte = 0L;
log.warn("offsetOfFirstByte>fileReadOffset, resetting offset to 0");
}
log.debug("Adaptor|" + adaptorID + "|seeking|" + fileReadOffset);
reader.seek(fileReadOffset);
long bufSize = len - fileReadOffset;
if (conf == null) {
ChukwaAgent agent = ChukwaAgent.getAgent();
if (agent != null) {
conf = agent.getConfiguration();
if (conf != null) {
MAX_READ_SIZE = conf.getInt(
"chukwaAgent.fileTailingAdaptor.maxReadSize",
DEFAULT_MAX_READ_SIZE);
log.info("chukwaAgent.fileTailingAdaptor.maxReadSize: "