Example #1
0
  /** Move to the next stage in the syncing process. */
  public void advance() {
    // If we have a backoff, request a backoff and don't advance to next stage.
    long existingBackoff = largestBackoffObserved.get();
    if (existingBackoff > 0) {
      this.abort(null, "Aborting sync because of backoff of " + existingBackoff + " milliseconds.");
      return;
    }

    this.callback.handleStageCompleted(this.currentState, this);
    Stage next = nextStage(this.currentState);
    GlobalSyncStage nextStage;
    try {
      nextStage = this.getSyncStageByName(next);
    } catch (NoSuchStageException e) {
      this.abort(e, "No such stage " + next);
      return;
    }
    this.currentState = next;
    Logger.info(LOG_TAG, "Running next stage " + next + " (" + nextStage + ")...");
    try {
      nextStage.execute(this);
    } catch (Exception ex) {
      Logger.warn(LOG_TAG, "Caught exception " + ex + " running stage " + next);
      this.abort(ex, "Uncaught exception in stage.");
      return;
    }
  }
Example #2
0
  /**
   * Generate a fresh meta/global record.
   *
   * @return meta/global record.
   */
  public MetaGlobal generateNewMetaGlobal() {
    final String newSyncID = Utils.generateGuid();
    final String metaURL = this.config.metaURL();

    ExtendedJSONObject engines = new ExtendedJSONObject();
    for (String engineName : enabledEngineNames()) {
      EngineSettings engineSettings = null;
      try {
        GlobalSyncStage globalStage = this.getSyncStageByName(engineName);
        Integer version = globalStage.getStorageVersion();
        if (version == null) {
          continue; // Don't want this stage to be included in meta/global.
        }
        engineSettings = new EngineSettings(Utils.generateGuid(), version.intValue());
      } catch (NoSuchStageException e) {
        // No trouble; Android Sync might not recognize this engine yet.
        // By default, version 0.  Other clients will see the 0 version and reset/wipe accordingly.
        engineSettings = new EngineSettings(Utils.generateGuid(), 0);
      }
      engines.put(engineName, engineSettings.toJSONObject());
    }

    MetaGlobal metaGlobal = new MetaGlobal(metaURL, this.getAuthHeaderProvider());
    metaGlobal.setSyncID(newSyncID);
    metaGlobal.setStorageVersion(STORAGE_VERSION);
    metaGlobal.setEngines(engines);

    return metaGlobal;
  }
Example #3
0
 public void resetStages(Collection<GlobalSyncStage> stages) {
   for (GlobalSyncStage stage : stages) {
     try {
       Logger.info(LOG_TAG, "Resetting " + stage);
       stage.resetLocal(this);
     } catch (Exception e) {
       Logger.error(LOG_TAG, "Ignoring reset failure for stage " + stage, e);
     }
   }
 }
Example #4
0
 public void wipeStages(Collection<GlobalSyncStage> stages) {
   for (GlobalSyncStage stage : stages) {
     try {
       Logger.info(LOG_TAG, "Wiping " + stage);
       stage.wipeLocal(this);
     } catch (Exception e) {
       Logger.error(LOG_TAG, "Ignoring wipe failure for stage " + stage, e);
     }
   }
 }