Ejemplo n.º 1
0
  /**
   * Gets the filtered notification tasks from all the post record task list.
   *
   * @return the filtered notification tasks
   */
  private List<RecordTask> getFilterNotificationTask() {
    List<RecordTask> events = new ArrayList<RecordTask>();
    for (int i = 0; i < recordList.size(); i++) {
      ActivityRecord record = recordList.get(i);
      if (record instanceof AbstractElementRecord)
        events.addAll(getNotificationTask(record.getPostTasks()));
      else if (record instanceof CompoundRecord) {
        // only collect those event will hold till the transaction stack
        // is empty; otherwise the notifications must already be send

        CompoundRecord cr = (CompoundRecord) record;

        if ((cr instanceof FilterEventsCompoundRecord) || (cr instanceof LayoutCompoundRecord)) {
          if (!((FilterEventsCompoundRecord) cr).isOutermostFilterTrans)
            events.addAll(cr.getFilterNotificationTask());
        } else {
          TransactionOption options = cr.getOptions();
          if (options != null
              && options.getSendTime() == TransactionOption.OUTMOST_TRANSACTION_SEND_TIME)
            events.addAll(cr.getFilterNotificationTask());
        }
      }
    }

    // filter all the collected events

    if (options != null) {
      IEventFilter filter = options.getEventFilter();
      if (filter != null) events = filter.filter(events);
    }
    return events;
  }
Ejemplo n.º 2
0
 /**
  * Checks the state of the contained records. Used in assert statements to validate the compound
  * record state.
  *
  * @param state the state to check.
  * @return True if all records are in that state, false otherwise.
  */
 private boolean checkState(int state) {
   Iterator<ActivityRecord> iter = recordList.iterator();
   while (iter.hasNext()) {
     ActivityRecord cmd = iter.next();
     if (cmd.getState() != state) return false;
   }
   return true;
 }
Ejemplo n.º 3
0
 public List<ValidationNode> getValidators() {
   List<ValidationNode> list = new ArrayList<ValidationNode>();
   Iterator<ActivityRecord> iter = recordList.iterator();
   while (iter.hasNext()) {
     ActivityRecord record = iter.next();
     list.addAll(record.getValidators());
   }
   return list;
 }
Ejemplo n.º 4
0
 /**
  * Reports if this record can be redone. A composite record can be redone only if each of the
  * sub-records can be redone.
  *
  * @see ActivityRecord#canRedo()
  */
 public boolean canRedo() {
   for (Iterator<ActivityRecord> records = recordList.listIterator(); records.hasNext(); ) {
     ActivityRecord record = records.next();
     if (!record.canRedo()) {
       return false;
     }
   }
   return true;
 }
Ejemplo n.º 5
0
  protected List<RecordTask> getPostTasks() {
    List<RecordTask> retList = new ArrayList<RecordTask>();

    for (int i = recordList.size() - 1; i >= 0; i--) {
      ActivityRecord record = recordList.get(i);
      if (record != null) {
        retList.addAll(record.getPostTasks());
      }
    }
    return retList;
  }
Ejemplo n.º 6
0
  public void rollback() {
    // Since undo/redo has no information about the transaction stack,
    // establish a tricky way to restore the information about the
    // transaction stack. Because filter/layout compound record only
    // includes filter/layout compound record, records in
    // <code>recordList</code> only need to know the compound record they
    // reside in. That is, "this".

    Stack<CompoundRecord> stack = new Stack<CompoundRecord>();
    stack.push(this);

    for (int i = recordList.size() - 1; i >= 0; i--) {
      ActivityRecord record = recordList.get(i);
      if (!record.isPersistent()) {
        record.rollback();
        record.performPostTasks(stack);
      }
    }
  }
Ejemplo n.º 7
0
  /**
   * Redoes the composite record. This implementation redoes each sub-record in the order they were
   * originally executed.
   *
   * @see ActivityRecord#redo()
   * @see org.eclipse.birt.report.model.activity.ActivityStack#redo()
   */
  public void redo() {
    // Since undo/redo has no information about the transaction stack,
    // establish a tricky way to restore the information about the
    // transaction stack. Because filter/layout compound record only
    // includes filter/layout compound record, records in
    // <code>recordList</code> only need to know the compound record they
    // reside in. That is, "this".

    Stack<CompoundRecord> stack = new Stack<CompoundRecord>();
    stack.push(this);

    for (int i = 0; i < recordList.size(); i++) {
      ActivityRecord record = recordList.get(i);
      assert record.getState() == ActivityRecord.UNDONE_STATE;
      record.redo();
      record.setState(ActivityRecord.REDONE_STATE);
      record.performPostTasks(stack);
    }
  }
    /** Creates an activity record from a text line created by toString() */
    public static ActivityRecord parseActivityRecord(String textLine) {

      ActivityRecord result = null;
      String[] fields = null;

      if (textLine != null) {
        try {
          // Splits the string
          fields = textLine.split(FIELDS_REGEXP);

          // Parses fixed lenght part
          if (fields.length > 3) {
            result = new ActivityRecord();

            // Parses the date
            result.date =
                !fields[0].equals(NULL_STRING) ? new Date(Long.parseLong(fields[0])) : null;

            // Parses the state
            result.state = !fields[1].equals(NULL_STRING) ? State.valueOf(fields[1]) : null;

            // Parses the action
            result.action = !fields[2].equals(NULL_STRING) ? StateAction.valueOf(fields[2]) : null;

            // Parses the requested action
            result.requestedAction =
                !fields[3].equals(NULL_STRING) ? RequestedAction.valueOf(fields[3]) : null;
          }

          // Parses variable length part
          if (fields.length > 4) {
            result.payload = new Object[fields.length - 4];
            System.arraycopy(fields, 4, result.payload, 0, fields.length - 4);
            parsePayload(result.payload);
          }

        } catch (Exception e) {
          Log.e(LOGTAG, "Error parsing activity record: " + textLine);
          Log.e(LOGTAG, Log.getStackTraceString(e));
          result = null;
        }
      }

      return result;
    }
  boolean handleAppCrashLocked(
      ProcessRecord app,
      String reason,
      String shortMsg,
      String longMsg,
      String stackTrace,
      AppErrorDialog.Data data) {
    long now = SystemClock.uptimeMillis();

    Long crashTime;
    Long crashTimePersistent;
    if (!app.isolated) {
      crashTime = mProcessCrashTimes.get(app.info.processName, app.uid);
      crashTimePersistent = mProcessCrashTimesPersistent.get(app.info.processName, app.uid);
    } else {
      crashTime = crashTimePersistent = null;
    }
    if (crashTime != null && now < crashTime + ProcessList.MIN_CRASH_INTERVAL) {
      // This process loses!
      Slog.w(TAG, "Process " + app.info.processName + " has crashed too many times: killing!");
      EventLog.writeEvent(
          EventLogTags.AM_PROCESS_CRASHED_TOO_MUCH, app.userId, app.info.processName, app.uid);
      mService.mStackSupervisor.handleAppCrashLocked(app);
      if (!app.persistent) {
        // We don't want to start this process again until the user
        // explicitly does so...  but for persistent process, we really
        // need to keep it running.  If a persistent process is actually
        // repeatedly crashing, then badness for everyone.
        EventLog.writeEvent(EventLogTags.AM_PROC_BAD, app.userId, app.uid, app.info.processName);
        if (!app.isolated) {
          // XXX We don't have a way to mark isolated processes
          // as bad, since they don't have a peristent identity.
          mBadProcesses.put(
              app.info.processName,
              app.uid,
              new BadProcessInfo(now, shortMsg, longMsg, stackTrace));
          mProcessCrashTimes.remove(app.info.processName, app.uid);
        }
        app.bad = true;
        app.removed = true;
        // Don't let services in this process be restarted and potentially
        // annoy the user repeatedly.  Unless it is persistent, since those
        // processes run critical code.
        mService.removeProcessLocked(app, false, false, "crash");
        mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
        return false;
      }
      mService.mStackSupervisor.resumeFocusedStackTopActivityLocked();
    } else {
      TaskRecord affectedTask =
          mService.mStackSupervisor.finishTopRunningActivityLocked(app, reason);
      if (data != null) {
        data.task = affectedTask;
      }
      if (data != null
          && crashTimePersistent != null
          && now < crashTimePersistent + ProcessList.MIN_CRASH_INTERVAL) {
        data.repeating = true;
      }
    }

    // Bump up the crash count of any services currently running in the proc.
    for (int i = app.services.size() - 1; i >= 0; i--) {
      // Any services running in the application need to be placed
      // back in the pending list.
      ServiceRecord sr = app.services.valueAt(i);
      sr.crashCount++;
    }

    // If the crashing process is what we consider to be the "home process" and it has been
    // replaced by a third-party app, clear the package preferred activities from packages
    // with a home activity running in the process to prevent a repeatedly crashing app
    // from blocking the user to manually clear the list.
    final ArrayList<ActivityRecord> activities = app.activities;
    if (app == mService.mHomeProcess
        && activities.size() > 0
        && (mService.mHomeProcess.info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
      for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
        final ActivityRecord r = activities.get(activityNdx);
        if (r.isHomeActivity()) {
          Log.i(TAG, "Clearing package preferred activities from " + r.packageName);
          try {
            ActivityThread.getPackageManager().clearPackagePreferredActivities(r.packageName);
          } catch (RemoteException c) {
            // pm is in same process, this will never happen.
          }
        }
      }
    }

    if (!app.isolated) {
      // XXX Can't keep track of crash times for isolated processes,
      // because they don't have a perisistent identity.
      mProcessCrashTimes.put(app.info.processName, app.uid, now);
      mProcessCrashTimesPersistent.put(app.info.processName, app.uid, now);
    }

    if (app.crashHandler != null) mService.mHandler.post(app.crashHandler);
    return true;
  }
  /**
   * Loads a number of records into cache starting from oldest record of oldest file that has not
   * been already loaded.
   */
  private boolean loadRecords(int records) {

    boolean moreRecords = false;
    boolean moreFiles = false;

    // Creates the cache if it is not created
    if (mCache == null) {
      mCache = new ArrayList<ActivityRecord>(CACHE_PAGE_SIZE);
    }

    // Calculates the target maximum size after loading required pages
    int targetCacheSize = mCache.size() + records;

    // Gets the file names to iterate, starting in lowest file with records remaining to be loaded
    Iterator<String> filesIterator = getLogFileNames(mLowestFile, (mLowestRecord != 0)).iterator();

    // Reads records until all required pages have been loaded or there are no more files
    while ((moreFiles = filesIterator.hasNext()) && mCache.size() < targetCacheSize) {

      // Open next file
      String fileName;
      BufferedReader reader = getReader(fileName = filesIterator.next());
      if (reader != null) {

        try {
          // Read an parse all the records in the current file skipping unformatted lines
          ArrayList<ActivityRecord> fileBlock = new ArrayList<ActivityRecord>(CACHE_PAGE_SIZE);
          String line;
          do {
            line = reader.readLine();
            ActivityRecord record = ActivityRecord.parseActivityRecord(line);
            if (record != null) {
              fileBlock.add(record);
            }
          } while (line != null);

          // Initializes record pointers to latest of this file +1
          if (mLowestRecord == 0) {
            mLowestRecord = fileBlock.size();
          }

          // Adds date separator record
          if (!fileName.equals(mLowestFile)) {
            mCache.add(new ActivityRecord(getLogFileDate(fileName)));
            mLowestFile = fileName;
          }

          // Calculates the number of records that still have to be added to cache
          int remSpace = targetCacheSize - mCache.size();

          // Extracts the number of records to fill the remaining space
          moreRecords = mLowestRecord > remSpace;
          int start = moreRecords ? mLowestRecord - remSpace : 0;
          int end = mLowestRecord;
          List<ActivityRecord> subList = fileBlock.subList(start, end);

          // Adds the records in reverse order at the end of the cache
          Collections.reverse(subList);
          mCache.addAll(subList);

          // Update record pointer
          mLowestRecord = start;
        } catch (IOException e) {
          Log.e(LOGTAG, Log.getStackTraceString(e));
        } finally {
          closeReader(reader);
        }
      }
    }
    return (mOlderRecords = (moreRecords || moreFiles));
  }
Ejemplo n.º 11
0
  @Override
  public String execute() throws Exception {
    Connection conn = null;
    PreparedStatement cStmt = null;
    String query;
    try {
      conn = Constants.DATASOURCE.getConnection();
      Long step = (super.cF.getTimeInMillis() - super.cI.getTimeInMillis()) / 1000;
      step = step / super.spansNumber + (step % super.spansNumber == 0L ? 0 : 1); // round up

      cI.add(Calendar.SECOND, (int) (start * step));
      Calendar c = null;
      if (limit != null && limit <= super.spansNumber)
        (c = (Calendar) cI.clone()).add(Calendar.SECOND, (int) (limit * step));
      else c = (Calendar) cF.clone();
      if (c.before(cF)) cF = c;

      // CallableStatement cStmt = conn.prepareCall(SqlQuery.SP_RTT_CHART.getSql());
      // cStmt.setInt(1, super.idServiceInstance);
      // cStmt.setTimestamp(2, new Timestamp(super.cI.getTimeInMillis()));
      // cStmt.setTimestamp(3, new Timestamp(super.cF.getTimeInMillis()));
      // cStmt.setLong(4, step);

      table = new ActivityTable();
      List<ActivityRecord> records = new LinkedList<ActivityRecord>();
      DateFormat formatter = new DateFormat(getLocale().getLanguage());
      c = (Calendar) cI.clone();
      // boolean hadResults = cStmt.execute();
      boolean fullTime = step < 60;

      if (step > 0) {
        while (c.getTimeInMillis() < cF.getTimeInMillis()) {

          query =
              "SELECT AVG(elapsedTime) as avgRtt FROM  esgf_dashboard.service_status WHERE idServiceInstance=";
          query = query + super.idServiceInstance;
          query = query + " AND timestamp between '";
          query = query + new Timestamp(c.getTimeInMillis()) + "' AND '";

          // while(hadResults) {
          // ResultSet rs = cStmt.getResultSet();
          ActivityRecord record = new ActivityRecord();
          record.setStartDate(formatter.formatDate(c));
          record.setStartTime(formatter.formatTime(c, fullTime));
          c.add(Calendar.SECOND, step.intValue());

          query = query + new Timestamp(c.getTimeInMillis()) + "'";
          // System.out.println("|||->>> RTTTableAction Query = "+query);

          cStmt = conn.prepareStatement(query);
          ResultSet rs = cStmt.executeQuery();

          record.setEndDate(formatter.formatDate(c));
          record.setEndTime(formatter.formatTime(c, fullTime));
          record.setValues(new LinkedList<Number>());
          if (rs.next() && rs.getBigDecimal("avgRtt") != null)
            record
                .getValues()
                .add(Math.round(rs.getBigDecimal("avgRtt").doubleValue() / 10.) / 100.);
          else record.getValues().add(null);
          records.add(record);
          // hadResults = cStmt.getMoreResults();
        } // endwhile
      } // endif
      cStmt.close();
      table.setActivityRecords(records);
      table.setTotalCount(super.spansNumber);
    } catch (SQLException e) {
      return ERROR;
    } finally {
      if (conn != null) conn.close();
    }
    return SUCCESS;
  }
Ejemplo n.º 12
0
 /**
  * Appends a record to the compound record. The record must have been executed already. The
  * application should not call this method directly. Instead, the record should be executed via
  * the usual call to {@link
  * org.eclipse.birt.report.model.activity.ActivityStack#execute(org.eclipse.birt.report.model.api.activity.IActivityRecord)
  * ActivityStack.execute( )}.
  *
  * @param record the record to be added.
  * @see
  *     org.eclipse.birt.report.model.activity.ActivityStack#execute(org.eclipse.birt.report.model.api.activity.IActivityRecord)
  */
 public void append(ActivityRecord record) {
   assert record != null;
   assert record.getState() == ActivityRecord.DONE_STATE;
   recordList.add(record);
 }