示例#1
0
  private JComboBox setupTypeCB(JComboBox box) {
    String Descritpions[] = new String[LogTypeHelper.values().length];
    int t = 0;
    for (LogTypeHelper log : LogTypeHelper.values()) {
      Descritpions[t++] = log.logEntryType;
    }
    JComboBox logLevelCB = new JComboBox(Descritpions);

    // Build the renderer for the combo boxesx
    LogTypeRenderer rendererCB = new LogTypeRenderer();

    logLevelCB.setEditable(false);
    logLevelCB.setMaximumRowCount(LogTypeHelper.values().length);
    logLevelCB.setRenderer(rendererCB);
    return logLevelCB;
  }
示例#2
0
  /**
   * Test setting and getting of the discard level.
   *
   * @throws Exception
   */
  public void testGetSetDiscardLevel() throws Exception {
    ACSListenersDispatcher listenerDispatcher = new ACSListenersDispatcher();
    assertNotNull("Null listener dispatcher!", listenerDispatcher);
    ACSLogRetrieval logDispatcher = new ACSLogRetrieval(listenerDispatcher);
    assertNotNull("Null log dispatcher!", logDispatcher);
    logDispatcher.start();

    logDispatcher.setDiscardLevel(null);
    assertNull(logDispatcher.getDiscardLevel());

    for (LogTypeHelper logType : LogTypeHelper.values()) {
      logDispatcher.setDiscardLevel(logType);
      assertEquals(logType, logDispatcher.getDiscardLevel());
    }
    logDispatcher.close(true);
  }
示例#3
0
  /**
   * Test the changing of the discard level by simulating a low memory situation
   *
   * @throws Exception
   */
  public void testDynamicDiscardLevel() throws Exception {
    Checker checker = new Checker();
    assertNotNull(checker);
    ACSListenersDispatcher listenerDispatcher = new ACSListenersDispatcher();
    assertNotNull("Null listener dispatcher!", listenerDispatcher);
    ACSLogRetrieval logDispatcher = new ACSLogRetrieval(listenerDispatcher, false, null, checker);
    assertNotNull("Null log dispatcher!", logDispatcher);
    logDispatcher.start();

    // Check increasing of the discard level
    logDispatcher.setDiscardLevel(null);
    checker.freemMem = Long.MAX_VALUE;
    // Changes of the discard level should happens every 2 seconds
    logDispatcher.enableDynamicDiscarding(8192, 1024, 2);
    // When the available memory is greater then the threshold,
    // the discard level does not change
    try {
      Thread.sleep(5);
    } catch (InterruptedException ie) {
    }
    assertNull(logDispatcher.getActualDiscardLevel());
    assertNull(logDispatcher.getDiscardLevel());

    // The index of the next log type
    int type = 0;

    // Time to wait for the next change before giving up
    int timeout = 10;

    // start dynamic changes of discard level
    checker.freemMem = 4096;
    while (logDispatcher.getActualDiscardLevel()
        != LogTypeHelper.values()[LogTypeHelper.values().length - 1]) {
      long to = System.currentTimeMillis() + 1000 * timeout;
      boolean found = false;
      while (!found && System.currentTimeMillis() < to) {
        found = logDispatcher.getActualDiscardLevel() == LogTypeHelper.values()[type];
        Thread.yield();
      }
      assertTrue("timeout waiting for level " + LogTypeHelper.values()[type], found);
      // Original discard level does not change
      assertNull(logDispatcher.getDiscardLevel());
      type++;
    }
    // Now the level is the topmost and it should not change...
    try {
      Thread.sleep(10000);
    } catch (InterruptedException ie) {
    }
    assertEquals(
        LogTypeHelper.values()[LogTypeHelper.values().length - 1],
        logDispatcher.getActualDiscardLevel());
    assertNull(logDispatcher.getDiscardLevel());

    // Now check the decreasing

    // First set the free memory to a value between the threshold and the damping
    checker.freemMem = 8192 + 512;
    // The level does not change
    try {
      Thread.sleep(10000);
    } catch (InterruptedException ie) {
    }
    assertEquals(
        LogTypeHelper.values()[LogTypeHelper.values().length - 1],
        logDispatcher.getActualDiscardLevel());
    assertNull(logDispatcher.getDiscardLevel());

    // Increase the free memory ===> the level start decreasing
    type = LogTypeHelper.values()[LogTypeHelper.values().length - 1].ordinal();
    checker.freemMem = 2 * 8192;
    while (logDispatcher.getActualDiscardLevel() != null) {
      long to = System.currentTimeMillis() + 1000 * timeout;
      boolean found = false;
      while (!found && System.currentTimeMillis() < to) {
        if (type >= 0) {
          found = logDispatcher.getActualDiscardLevel() == LogTypeHelper.values()[type];
        } else {
          found = logDispatcher.getActualDiscardLevel() == null;
        }
        Thread.yield();
      }
      if (type >= 0) {
        assertTrue("timeout waiting for level " + LogTypeHelper.values()[type], found);
      }
      // Original discard level does not change
      assertNull(logDispatcher.getDiscardLevel());
      type--;
    }
    assertNull(logDispatcher.getActualDiscardLevel());
    logDispatcher.close(true);
  }
示例#4
0
  /** 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();
  }