/** Returns the {@link SegmentCacheIndex} for a given {@link SegmentHeader}. */
 private SegmentCacheIndex getIndex(SegmentHeader header) {
   // First we check the indexes that already exist.
   // This is fast.
   for (Entry<RolapStar, SegmentCacheIndex> entry : indexes.entrySet()) {
     final String factTableName = entry.getKey().getFactTable().getTableName();
     final ByteString schemaChecksum = entry.getKey().getSchema().getChecksum();
     if (!factTableName.equals(header.rolapStarFactTableName)) {
       continue;
     }
     if (!schemaChecksum.equals(header.schemaChecksum)) {
       continue;
     }
     return entry.getValue();
   }
   // The index doesn't exist. Let's create it.
   for (RolapSchema schema : RolapSchema.getRolapSchemas()) {
     if (!schema.getChecksum().equals(header.schemaChecksum)) {
       continue;
     }
     // We have a schema match.
     RolapStar star = schema.getStar(header.rolapStarFactTableName);
     if (star != null) {
       // Found it.
       indexes.put(star, new SegmentCacheIndexImpl(thread));
     }
     return indexes.get(star);
   }
   return null;
 }
    public Object visit(CellCacheSegmentCreateEvent event) {
      MutableExecutionInfo exec = executionMap.get(event.executionId);
      if (exec == null) {
        // Cache events can sometimes arrive after the execution has
        // ended. So, look into the retired map.
        exec = retiredExecutionMap.get(event.executionId);
        if (exec == null) {
          return missing(event);
        }
      }

      foo(exec, event);
      foo(exec.stmt.aggExec, event);
      foo(exec.stmt.conn.aggExec, event);
      foo(server.aggExec, event);
      return null;
    }
 public Object visit(SqlStatementExecuteEvent event) {
   final MutableSqlStatementInfo sql = sqlStatementMap.get(event.sqlStatementId);
   if (sql == null) {
     return missing(event);
   }
   foo(sql, event);
   foo(sql.stmt.aggSql, event);
   foo(server.aggSql, event);
   return null;
 }
    public Object visit(CellCacheSegmentDeleteEvent event) {
      final MutableExecutionInfo exec = executionMap.get(event.executionId);
      if (exec == null) {
        return missing(event);
      }

      foo(exec, event);
      foo(exec.stmt.aggExec, event);
      foo(exec.stmt.conn.aggExec, event);
      foo(server.aggExec, event);
      return null;
    }
    public Object visit(ExecutionPhaseEvent event) {
      final MutableExecutionInfo exec = executionMap.get(event.executionId);
      if (exec == null) {
        return missing(event);
      }
      executionMap.put(event.executionId, exec);

      foo(exec, event);
      foo(exec.stmt.aggExec, event);
      foo(exec.stmt.conn.aggExec, event);
      foo(server.aggExec, event);
      return null;
    }
 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;
 }
 /** Returns the {@link SegmentCacheIndex} for a given {@link RolapStar}. */
 public SegmentCacheIndex getIndex(RolapStar star) {
   if (!indexes.containsKey(star)) {
     indexes.put(star, new SegmentCacheIndexImpl(thread));
   }
   return indexes.get(star);
 }