use of com.emc.storageos.systemservices.impl.logsvc.marshaller.Marshaller in project coprhd-controller by CoprHD.
the class LogNetworkStreamMerger method streamLogs.
public void streamLogs(OutputStream outputStream) {
logger.trace("Entering into LogNetworkStreamMerger.streamLogs()");
CountingOutputStream cos = new CountingOutputStream(new BufferedOutputStream(outputStream, LogConstants.BUFFER_SIZE));
Marshaller marshaller = MarshallerFactory.getLogMarshaller(mediaType, cos);
int finalCount = 0;
try {
marshaller.head();
LogMessage msg = readNextMergedLogMessage();
if (msg != null) {
do {
// Maximum bytes to stream check
streamedBytes = cos.getByteCount();
if (request.getMaxBytes() > 0 && streamedBytes >= request.getMaxBytes()) {
logger.info("Streamed log size {}bytes reached maximum allowed limit {}bytes. So quitting.", streamedBytes, request.getMaxBytes());
break;
}
List<LogMessage> currentLogBatch = new ArrayList<>();
LogMessage startLogOfNextBatch = readLogBatch(msg, currentLogBatch);
if (!LogUtil.permitNextLogBatch(request.getMaxCount(), finalCount, currentLogBatch.size())) {
// discard this batch
break;
}
// current log batch has been accepted
for (String st : status.getStatus()) {
// use previous log message's timeStamp as status's timeStamp
marshaller.marshall(st, msg);
}
status.clear();
for (LogMessage logMessage : currentLogBatch) {
marshaller.marshall(logMessage);
finalCount++;
}
msg = startLogOfNextBatch;
} while (msg != null);
}
logger.info("final count={}", finalCount);
marshaller.tail();
marshaller.flush();
} catch (Exception e) {
logger.error("Exception in streamLogs:", e);
}
}
Aggregations