package com.cloudera.flume.agent.durability;
import java.io.IOException;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.cloudera.flume.core.Event;
import com.cloudera.flume.core.EventSource;
import com.cloudera.flume.reporter.ReportEvent;
static final Logger LOG = LoggerFactory.getLogger(WALSource.class);
final WALManager walMan;
EventSource curSource;
this.walMan = walMan;
curSource = null;
}
while (curSource == null) {
curSource = walMan.getUnackedSource();
if (curSource == null) {
return null;
}
try {
curSource.open();
} catch (Exception ex) {
LOG.warn("Exception opening underlaying source", ex);
curSource = null;
}
}
return curSource;
}
try {
Event e = curSource.next();
return e;
} catch (Exception ex) {
LOG.warn("Exception getting next", ex);
return null;
}
}
@Override
public Event
next()
throws IOException {
curSource = getValidSource();
if (curSource == null)
return null;
Event e = getValidNext();
if (e != null) {
updateEventProcessingStats(e);
return e;
}
do {
LOG.info("end of file " + curSource);
try {
curSource.close();
} catch (Exception ex) {
LOG.warn("Exception closing (just continue)", ex);
}
curSource = walMan.getUnackedSource();
if (curSource == null)
return null;
try {
curSource.open();
} catch (IOException ex) {
LOG.warn("Exception opening", ex);
continue;
}
e = getValidNext();
} while (e == null);
updateEventProcessingStats(e);
return e;
}
@Override
public void getReports(String namePrefix, Map<String, ReportEvent> reports) {
super.getReports(namePrefix, reports);
if (curSource != null) {
curSource.getReports(namePrefix + getName() + ".", reports);
}
}
public void recover()
throws IOException {
walMan.recover();
}
@Override
public void close()
throws IOException {
walMan.stopDrains();
}
@Override
public void open()
throws IOException {
walMan.open();
walMan.recover();
}
}