/** * Flush the logs from the temporary vector into the table. * * <p>New logs are appended in the temporary vector <code>rowsToAdd</code> to limit the frequency * of updating the table model. This method flushes the logs from the temporary vector into the * model vector (<code>rows</code>). * * @return <code>true</code> if at least one log has been added to the model */ private void flushLogs() { // rowsToAdd is reduced then copied into temp: // it is possible to append logs again without waiting for the flush // i.e. modification of the model inside EDT do not block rowsToAdd final List<ILogEntry> temp; synchronized (rowsToAdd) { if (rowsToAdd.isEmpty()) { return; } // try to apply reduction rules only in OPERATOR mode try { if (loggingClient.getEngine().getAudience().getInfo() == AudienceInfo.OPERATOR) { logProcessor.reduce(rowsToAdd); } } catch (Throwable t) { System.err.println( "Exception caught (" + t.getMessage() + ")while reducing logs: reduction disabled this time"); t.printStackTrace(System.err); } temp = new Vector<ILogEntry>(rowsToAdd); rowsToAdd.clear(); } // Add the reduced logs into the model (from inside the EDT) try { EDTExecutor.instance() .executeSync( new Runnable() { @Override public void run() { for (int t = temp.size() - 1; t >= 0; t--) { ILogEntry log = temp.get(t); Integer key; try { key = Integer.valueOf(allLogs.add(log)); } catch (LogCacheException lce) { System.err.println( "Exception caught while inserting a new log entry in cache:"); System.err.println(lce.getLocalizedMessage()); lce.printStackTrace(System.err); continue; } rows.add(key); } // Finally notify the change fireTableRowsInserted(0, temp.size() - 1); } }); } catch (InvocationTargetException e) { System.out.println("!!! Exception: " + e.getMessage() + "; model size=" + rows.size()); e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
/** * Override <code>setVisible()</code> to move the statistic window over the logging client and in * front of other windows */ @Override public void setVisible(boolean visible) { super.setVisible(visible); // Move the statistic win on top of jlog if (visible && isShowing()) { Point loggingPos = loggingClient.getLocationOnScreen(); setLocation(loggingPos); toFront(); } // Refresh the state of the switches to disconnec and clear the table guiSwitches.checkControlsState(); }
/** Submit a query to the archive and insert the logs in the main window */ private void submitQuery() { if (!checkFields()) { JOptionPane.showMessageDialog( this, "Error getting values from the form", "Input error!", JOptionPane.ERROR_MESSAGE); return; } loggingClient.reportStatus("Submitting a query"); guiSwitches.execute(); // Clear the logs and disconnect from the NC StringBuilder from = new StringBuilder(fromYY.getText()); from.append('-'); if (fromMM.getText().length() == 1) { from.append('0'); } from.append(fromMM.getText()); from.append('-'); if (fromDD.getText().length() == 1) { from.append('0'); } from.append(fromDD.getText()); from.append('T'); if (fromHr.getText().length() == 1) { from.append('0'); } from.append(fromHr.getText()); from.append(':'); if (fromMin.getText().length() == 1) { from.append('0'); } from.append(fromMin.getText()); from.append(':'); if (fromSec.getText().length() == 1) { from.append('0'); } from.append(fromSec.getText()); StringBuilder to = new StringBuilder(toYY.getText()); to.append('-'); if (toMM.getText().length() == 1) { to.append('0'); } to.append(toMM.getText()); to.append('-'); if (toDD.getText().length() == 1) { to.append('0'); } to.append(toDD.getText()); to.append('T'); if (toHr.getText().length() == 1) { to.append('0'); } to.append(toHr.getText()); to.append(':'); if (toMin.getText().length() == 1) { to.append('0'); } to.append(toMin.getText()); to.append(':'); if (toSec.getText().length() == 1) { to.append('0'); } to.append(toSec.getText()); short minType = (short) LogTypeHelper.values()[minLogLevelCB.getSelectedIndex()].acsCoreLevel.value; short maxType = (short) LogTypeHelper.values()[maxLogLevelCB.getSelectedIndex()].acsCoreLevel.value; String routine = routineName.getText(); if (routine.length() == 0) { routine = "*"; } String source = sourceName.getText(); if (source.length() == 0) { source = "*"; } String process = procName.getText(); if (process.length() == 0) { process = "*"; } int maxRows = Integer.parseInt(rowLimit.getText()); // The collection where the logs read from the DB are stored Collection logs = null; updateStatusLbl("Submitting query"); try { logs = archive.getLogs( from.toString() + ".000", to.toString() + ".000", minType, maxType, routine, source, process, maxRows); } catch (Throwable t) { System.err.println("Error executing the query: " + t.getMessage()); t.printStackTrace(System.err); JOptionPane.showMessageDialog( this, formatErrorMsg("Error executing the query:\n" + t.getMessage()), "Database error!", JOptionPane.ERROR_MESSAGE); loggingClient.reportStatus("Query terminated with error"); } if (logs != null && !logs.isEmpty()) { loggingClient.reportStatus("Num. of logs read from DB: " + logs.size()); LogMatcher matcher = new LogMatcher(); matcher.setAudience(loggingClient.getEngine().getAudience()); matcher.setFilters(loggingClient.getEngine().getFilters()); matcher.setDiscardLevel(loggingClient.getEngine().getDiscardLevel()); Iterator iter = logs.iterator(); int count = 0; while (iter.hasNext() && !terminateThread) { if ((++count) % 1000 == 0) { updateStatusLbl("Flushing logs " + count + "/" + logs.size()); } String str = (String) iter.next(); ILogEntry logEntry = null; try { logEntry = parser.parse(str); } catch (Exception e) { errorListener.errorReceived(str); continue; } if (matcher.match(logEntry)) { logListener.logEntryReceived(logEntry); } } logs.clear(); logs = null; } updateStatusLbl(""); // Update the state of the switches guiSwitches.checkControlsState(); }