Esempio n. 1
0
  /**
   * 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();
    }
  }
Esempio n. 2
0
 /**
  * Replace a log entry with another.
  *
  * @param pos The position in the cache of the log to replace
  * @param newEntry The new LogEntryXML
  */
 public void replaceLog(final int pos, final ILogEntry newEntry) {
   EDTExecutor.instance()
       .execute(
           new Runnable() {
             @Override
             public void run() {
               // Replace the entry in the list of all the logs (allLogs)
               try {
                 allLogs.replaceLog(pos, newEntry);
               } catch (LogCacheException e) {
                 System.err.println("Error replacing log " + pos);
                 e.printStackTrace();
               }
             }
           });
 }
Esempio n. 3
0
 /**
  * Check if there are too many logs in the table and if it is the case then remove the oldest.
  *
  * <p>This method must be executed inside the EDT.
  *
  * @see #maxLog
  */
 private void removeExceedingLogs() {
   try {
     EDTExecutor.instance()
         .executeSync(
             new Runnable() {
               @Override
               public void run() {
                 int sz = rows.size();
                 if (maxLog <= 0 || sz <= maxLog) {
                   // The model is unbounded or there is still enough room in the model
                   return;
                 }
                 keysDeleter.scheduleForDeletion(rows.removeLastEntries(rows.size() - maxLog));
                 fireTableDataChanged();
               }
             });
   } catch (InvocationTargetException e) {
     System.out.println("!!! Exception: " + e.getMessage() + "; model size=" + rows.size());
     e.printStackTrace();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Esempio n. 4
0
 /** Remove all the logs. */
 public void clearAll() {
   // Remove the logs waiting to be inserted
   EDTExecutor.instance()
       .execute(
           new Runnable() {
             public void run() {
               rowsToAdd.clear();
               rows.clear();
               keysDeleter.invalidate();
               try {
                 allLogs.clear();
               } catch (Throwable t) {
                 System.err.println("Exception caught clearing the cache: " + t.getMessage());
                 t.printStackTrace(System.err);
                 JOptionPane.showInternalMessageDialog(
                     loggingClient,
                     "Error clearing the cache.",
                     "Error clearing the cache",
                     JOptionPane.ERROR_MESSAGE);
               }
               fireTableDataChanged();
             }
           });
 }