use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.
the class LogCache method getLog.
/**
* Return the log with the given key.
* The method is synchronized because both the HashMap and
* the LinkedList must be synchronized if there is a chance
* to acces these objects from more then one thread in the same
* time
* @see java.util.LinkedList
* @see java.util.HashMap
*
* @param pos The key of the log
* @return The LogEntryXML or null in case of error
*/
public synchronized ILogEntry getLog(Integer key) throws LogCacheException {
ILogEntry log;
log = cache.get(key);
if (log != null) {
// Hit! The log is in the cache
return log;
} else {
// Oops we need to read a log from disk!
return loadNewLog(key);
}
}
use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.
the class LogCache method loadNewLog.
/**
* Get a log from the cache on disk updating all the
* internal lists
*
* @param idx The position of the log
* @return The log read from the cache on disk
*/
private synchronized ILogEntry loadNewLog(Integer idx) throws LogCacheException {
// Read the new log from the cache on disk
ILogEntry log = super.getLog(idx);
// There is enough room in the lists?
if (cache.size() == actualCacheSize) {
// We need to create a room for the new element
Integer itemToRemove = manager.removeFirst();
cache.remove(itemToRemove);
}
// Add the log in the cache
cache.put(idx, log);
// Append the index in the manager list
manager.addLast(idx);
return log;
}
use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.
the class LogReceiver method startCaptureLogs.
/**
* Variant of {@link #startCaptureLogs(PrintWriter)} which takes an optional ThreadFactory
* which will be used to create the thread that reads out the log queue.
* This method could be used if <code>LogReceiver</code> is run inside a container
* or as part of a ComponentClientTestCase.
*/
public void startCaptureLogs(final PrintWriter logWriter, ThreadFactory threadFactory) throws IOException {
if (!isInitialized()) {
throw new IllegalStateException("First call LogReceiver#initialize(ORB, Manager), then startCaptureLogs(PrintWriter)");
}
if (listenForLogs) {
if (verbose) {
System.out.println("Ignoring call to 'startCaptureLogs' while already capturing logs.");
}
return;
}
Runnable logRetriever = new Runnable() {
public void run() {
// System.out.println("logRetriever.run called...");
try {
BlockingQueue<DelayedLogEntry> logQueue = getLogQueue();
listenForLogs = true;
// loop until "queue poison" entry is found
while (true) {
try {
// extract logs from queue
DelayedLogEntry delayedLogEntry = logQueue.take();
if (delayedLogEntry.isQueuePoison()) {
if (verbose) {
System.out.println("got queue poison, will terminate method 'startCaptureLogs'.");
}
break;
} else {
ILogEntry logEntry = delayedLogEntry.getLogEntry();
String xmlLog = logEntry.toXMLString();
// System.out.println("Yeah, got a log record: " + xmlLog);
logWriter.println(xmlLog);
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Throwable thr) {
System.out.println("Log receiver got exception " + thr);
logWriter.println("Log receiver failed with exception " + thr.toString());
} finally {
logWriter.close();
// we only call stop now, so that late arriving records could still be added
// to the queue during the whole waiting time.
stop();
}
}
};
Thread t = null;
if (threadFactory != null) {
t = threadFactory.newThread(logRetriever);
} else {
t = new Thread(logRetriever);
t.setDaemon(true);
}
t.start();
}
use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.
the class ACSLogParserDOM method parse.
/* (non-Javadoc)
* @see com.cosylab.logging.engine.ACS.ACSLogParser#parse(java.lang.String)
*/
public synchronized ILogEntry parse(String string) throws LogParseException {
Document document = null;
try {
document = builder.parse(new InputSource(new StringReader(string)));
} catch (IOException ioe) {
// cannot get here
System.err.println("Exception parsing " + ioe.getMessage());
throw new LogParseException(ioe);
} catch (Exception e) {
/* There was an exception parsing the log, but before giving up
* we try to fix markup issues inside the text that is contained in the XML */
document = null;
String newLogString = XmlNormalizer.normalizeXMLEmbeddedTextOnly(string);
try {
document = builder.parse(new InputSource(new StringReader(newLogString)));
System.out.println("Fatal error recovered:");
System.out.println("\tOriginal log entry: " + string);
System.out.println("\tCleaned log entry: " + newLogString + "\n");
} catch (IOException ex1) {
System.err.println("Failed to parse the following log entry:");
System.err.println(string);
System.err.println("with IO exception ");
throw new LogParseException(ex1);
} catch (SAXException ex2) {
System.err.println("Failed to parse the following log entry:");
System.err.println(string);
System.err.println("with parser exception ");
throw new LogParseException(ex2);
}
}
return new LogEntry(new LogEntryXML(document.getFirstChild()));
}
use of com.cosylab.logging.engine.log.ILogEntry in project ACS by ACS-Community.
the class ACSLogParserVTD method parse.
/**
* Implements required method of ACSLogParser interface.
*
* @param xmlString the XML string to parse
* @throws LogParseException when problems are encountered parsing an XML message.
* @see ACSLogParser
*/
public synchronized ILogEntry parse(String xmlString) throws LogParseException {
if (xmlString == null || xmlString.length() == 0) {
throw new IllegalArgumentException("Invalid string to parse");
}
LogEntry retVal = null;
byte[] bytesArray = xmlString.getBytes();
try {
try {
VTDGen_clear.invoke(vtdGen, nullObj);
VTDGen_setDoc.invoke(vtdGen, bytesArray);
// set namespace awareness to false for now
VTDGen_parse.invoke(vtdGen, false);
} catch (Exception e) {
/* There was an exception parsing the log, but before giving up
* we try to fix markup issues inside the text that is contained in the XML */
VTDGen_clear.invoke(vtdGen, nullObj);
xmlString = XmlNormalizer.normalizeXMLEmbeddedTextOnly(xmlString);
bytesArray = xmlString.getBytes();
VTDGen_setDoc.invoke(vtdGen, xmlString.getBytes());
VTDGen_parse.invoke(vtdGen, false);
}
retVal = makeLogEntryFromParsedXML(bytesArray, xmlString);
} catch (Exception ex) {
throw new LogParseException("Error parsing with VTD!", ex);
}
return retVal;
}
Aggregations