public Object visit(ConnectionStartEvent event) {
   final MutableConnectionInfo conn = new MutableConnectionInfo(event.stack);
   connectionMap.put(event.connectionId, conn);
   foo(conn, event);
   foo(server.aggConn, event);
   if (RolapUtil.MONITOR_LOGGER.isTraceEnabled()) {
     RolapUtil.MONITOR_LOGGER.trace(
         "Connection(" + event.connectionId + ") created. stack is:" + Util.nl + event.stack);
   }
   return null;
 }
 protected boolean removeEldestEntry(Map.Entry<Long, MutableExecutionInfo> e) {
   if (size() > maxSize) {
     if (RolapUtil.MONITOR_LOGGER.isTraceEnabled()) {
       RolapUtil.MONITOR_LOGGER.trace(
           "Retired ExecutionInfo("
               + e.getKey()
               + ") evicted. Stack is:"
               + Util.nl
               + e.getValue().stack);
     }
     return true;
   }
   return false;
 }
 public void run() {
   try {
     for (; ; ) {
       try {
         final Pair<Handler, Message> entry = eventQueue.take();
         final Handler handler = entry.left;
         final Message message = entry.right;
         final Object result = message.accept(handler);
         if (message instanceof Command) {
           responseMap.put((Command) message, result);
         } else {
           // Broadcast the event to anyone who is interested.
           RolapUtil.MONITOR_LOGGER.debug(message);
         }
         if (message instanceof ShutdownCommand) {
           LOGGER.debug("ShutdownCommand received. Monitor thread is shutting down.");
           return;
         }
       } catch (InterruptedException e) {
         Thread.currentThread().interrupt();
         LOGGER.warn("Monitor thread interrupted.", e);
         return;
       } catch (Throwable t) {
         LOGGER.error("Runtime error on the monitor thread.", t);
       }
     }
   } finally {
     running = false;
   }
 }
 public Object visit(StatementStartEvent event) {
   final MutableConnectionInfo conn = connectionMap.get(event.connectionId);
   if (conn == null) {
     return missing(event);
   }
   final MutableStatementInfo stmt =
       new MutableStatementInfo(conn, event.statementId, event.stack);
   statementMap.put(event.statementId, stmt);
   foo(stmt, event);
   foo(conn.aggStmt, event);
   foo(server.aggStmt, event);
   if (RolapUtil.MONITOR_LOGGER.isTraceEnabled()) {
     RolapUtil.MONITOR_LOGGER.trace(
         "Statement(" + event.statementId + ") created. stack is:" + Util.nl + event.stack);
   }
   return null;
 }
    public Object visit(ExecutionStartEvent event) {
      MutableStatementInfo stmt = statementMap.get(event.statementId);
      if (stmt == null) {
        return missing(event);
      }
      final MutableExecutionInfo exec =
          new MutableExecutionInfo(stmt, event.executionId, event.stack);
      executionMap.put(event.executionId, exec);

      foo(exec, event);
      foo(stmt.aggExec, event);
      foo(stmt.conn.aggExec, event);
      foo(server.aggExec, event);
      if (RolapUtil.MONITOR_LOGGER.isTraceEnabled()) {
        RolapUtil.MONITOR_LOGGER.trace(
            "Execution(" + event.executionId + ") created. stack is:" + Util.nl + event.stack);
      }
      return null;
    }
 public Object visit(SqlStatementStartEvent event) {
   final MutableStatementInfo stmt = statementMap.get(event.getStatementId());
   if (stmt == null) {
     return missing(event);
   }
   final MutableSqlStatementInfo sql =
       new MutableSqlStatementInfo(stmt, event.sqlStatementId, event.sql, event.stack);
   sqlStatementMap.put(event.sqlStatementId, sql);
   foo(sql, event);
   foo(sql.stmt.aggSql, event);
   foo(server.aggSql, event);
   if (RolapUtil.MONITOR_LOGGER.isTraceEnabled()) {
     RolapUtil.MONITOR_LOGGER.trace(
         "SqlStatement("
             + event.sqlStatementId
             + ") created. stack is:"
             + Util.nl
             + event.stack);
   }
   return null;
 }
    public Object visit(ConnectionEndEvent event) {
      final MutableConnectionInfo conn = connectionMap.remove(event.connectionId);
      if (conn == null) {
        return missing(event);
      }
      foo(conn, event);
      foo(server.aggConn, event);

      // Since the connection info will no longer be in the table,
      // broadcast the final info to anyone who is interested.
      RolapUtil.MONITOR_LOGGER.debug(conn.fix());
      return null;
    }
    public Object visit(SqlStatementEndEvent event) {
      final MutableSqlStatementInfo sql = sqlStatementMap.remove(event.sqlStatementId);
      if (sql == null) {
        return missing(event);
      }
      foo(sql, event);
      foo(sql.stmt.aggSql, event);
      foo(server.aggSql, event);

      // Since the SQL statement info will no longer be in the table,
      // broadcast the final info to anyone who is interested.
      RolapUtil.MONITOR_LOGGER.debug(sql.fix());
      return null;
    }
    public Object visit(ExecutionEndEvent event) {
      final MutableExecutionInfo exec = executionMap.remove(event.executionId);
      if (exec == null) {
        return missing(event);
      }
      retiredExecutionMap.put(exec.executionId, exec);
      foo(exec, event);
      foo(exec.stmt.aggExec, event);
      foo(exec.stmt.conn.aggExec, event);
      foo(server.aggExec, event);

      // Since the execution info will no longer be in the table,
      // broadcast the final info to anyone who is interested.
      RolapUtil.MONITOR_LOGGER.debug(exec.fix());
      return null;
    }
    public void run() {
      try {
        for (; ; ) {
          final Pair<Handler, Message> entry = eventQueue.take();
          final Handler handler = entry.left;
          final Message message = entry.right;
          try {
            // A message is either a command or an event.
            // A command returns a value that must be read by
            // the caller.
            if (message instanceof Command<?>) {
              Command<?> command = (Command<?>) message;
              try {
                Locus.push(command.getLocus());
                Object result = command.call();
                responseQueue.put(command, Pair.of(result, (Throwable) null));
              } catch (PleaseShutdownException e) {
                responseQueue.put(command, Pair.of(null, (Throwable) null));
                return; // exit event loop
              } catch (Throwable e) {
                responseQueue.put(command, Pair.of(null, e));
              } finally {
                Locus.pop(command.getLocus());
              }
            } else {
              Event event = (Event) message;
              event.acceptWithoutResponse(handler);

              // Broadcast the event to anyone who is interested.
              RolapUtil.MONITOR_LOGGER.debug(message);
            }
          } catch (Throwable e) {
            // REVIEW: Somewhere better to send it?
            e.printStackTrace();
          }
        }
      } catch (InterruptedException e) {
        // REVIEW: Somewhere better to send it?
        e.printStackTrace();
      } catch (Throwable e) {
        e.printStackTrace();
      }
    }