コード例 #1
0
  /**
   * Engines to include in a fresh meta/global record.
   *
   * <p>Returns either the persisted engine names (perhaps we have been node re-assigned and are
   * initializing a clean server: we want to upload the persisted engine names so that we don't
   * accidentally disable engines that Android Sync doesn't recognize), or the set of engines names
   * that Android Sync implements.
   *
   * @return set of engine names.
   */
  protected Set<String> enabledEngineNames() {
    if (config.enabledEngineNames != null) {
      return config.enabledEngineNames;
    }

    // These are the default set of engine names.
    Set<String> validEngineNames = SyncConfiguration.validEngineNames();

    // If the user hasn't set any selected engines, that's okay -- default to
    // everything.
    if (config.userSelectedEngines == null) {
      return validEngineNames;
    }

    // userSelectedEngines has keys that are engine names, and boolean values
    // corresponding to whether the user asked for the engine to sync or not. If
    // an engine is not present, that means the user didn't change its sync
    // setting. Since we default to everything on, that means the user didn't
    // turn it off; therefore, it's included in the set of engines to sync.
    Set<String> validAndSelectedEngineNames = new HashSet<String>();
    for (String engineName : validEngineNames) {
      if (config.userSelectedEngines.containsKey(engineName)
          && !config.userSelectedEngines.get(engineName)) {
        continue;
      }
      validAndSelectedEngineNames.add(engineName);
    }
    return validAndSelectedEngineNames;
  }
コード例 #2
0
  public GlobalSession(
      SyncConfiguration config,
      BaseGlobalSessionCallback callback,
      Context context,
      Bundle extras,
      ClientsDataDelegate clientsDelegate,
      NodeAssignmentCallback nodeAssignmentCallback)
      throws SyncConfigurationException, IllegalArgumentException, IOException, ParseException,
          NonObjectJSONException {

    if (callback == null) {
      throw new IllegalArgumentException("Must provide a callback to GlobalSession constructor.");
    }

    Logger.debug(LOG_TAG, "GlobalSession initialized with bundle " + extras);

    this.callback = callback;
    this.context = context;
    this.clientsDelegate = clientsDelegate;
    this.nodeAssignmentCallback = nodeAssignmentCallback;

    this.config = config;
    registerCommands();
    prepareStages();

    Collection<String> knownStageNames = SyncConfiguration.validEngineNames();
    config.stagesToSync = Utils.getStagesToSyncFromBundle(knownStageNames, extras);

    // TODO: data-driven plan for the sync, referring to prepareStages.
  }