本文整理汇总了Java中com.firebase.jobdispatcher.RetryStrategy类的典型用法代码示例。如果您正苦于以下问题:Java RetryStrategy类的具体用法?Java RetryStrategy怎么用?Java RetryStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RetryStrategy类属于com.firebase.jobdispatcher包,在下文中一共展示了RetryStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: syncImmediately
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
synchronized public static void syncImmediately(Context context, String tag) {
Timber.d("Scheduling a immediate sync");
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver
(context));
Bundle bundle = new Bundle();
Job myJob = dispatcher.newJobBuilder()
.setService(QuoteJobService.class)
.setTag(tag)
.setExtras(bundle)
.setRecurring(false)
.setTrigger(Trigger.executionWindow(0, 0))
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setReplaceCurrent(true)
.build();
dispatcher.mustSchedule(myJob);
}
示例2: onSetupComplete
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
@SuppressLint("ApplySharedPref")
private void onSetupComplete() {
//download whole leaderboards data asynchronously
new FetchLeaderBoardDataAsync(this).execute();
//schedule daily sync at 3:00 am local time
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
DateTime now = new DateTime();
DateTime tomorrow = now.plusDays(1).withTimeAtStartOfDay().plusHours(3);
int windowStart = Hours.hoursBetween(now, tomorrow).getHours() * 60 * 60;
Job synJob = dispatcher.newJobBuilder()
.setService(SyncScheduler.class)
.setTag(Constants.PERIODIC_SYNC_SCHEDULE_KEY)
.setReplaceCurrent(true)
.setTrigger(Trigger.executionWindow(windowStart, windowStart + 10))
.setConstraints(Constraint.ON_ANY_NETWORK)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.build();
dispatcher.mustSchedule(synJob);
sharedPreferences.edit().putBoolean(Constants.PREF_FIREBASE_SETUP, true).commit();
startActivity(new Intent(this, PreChecksActivity.class));
finish();
}
示例3: scheduleJob
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
public static void scheduleJob(Context context, Message message) {
try {
Bundle bundle = new Bundle();
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
bundle.putString(MobiComKitConstants.AL_MESSAGE_KEY, message.getKeyString());
Class pushNotificationJobServiceClass = Class.forName("com.applozic.mobicomkit.uiwidgets.notification.PushNotificationJobService");
Job myJob = dispatcher.newJobBuilder()
.setService(pushNotificationJobServiceClass) // the JobService that will be called
.setTag(MobiComKitConstants.PUSH_NOTIFICATION_DISPATCHER) // uniquely identifies the job
.setRecurring(false)
.setTrigger(Trigger.executionWindow(0, 0))
.setReplaceCurrent(true)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setExtras(bundle)
.build();
dispatcher.mustSchedule(myJob);
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: scheduleImageService
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
@Override
public void scheduleImageService(FirebaseJobDispatcher dispatcher) {
dispatcher
.newJobBuilder()
.setService(DownloadImageService.class)
.setTag(Configuration.JOB_ID_DOWNLOAD_IMAGE_SERVICE)
.setRecurring(false)
.setLifetime(Lifetime.FOREVER)
.setTrigger(Trigger.executionWindow(0, 3600))
.setReplaceCurrent(true)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.setConstraints(
Constraint.ON_UNMETERED_NETWORK,
Constraint.DEVICE_CHARGING
)
.build();
}
示例5: setup
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
private static void setup(@NonNull final Context context, final int timeInSeconds) {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job myJob = dispatcher.newJobBuilder()
// the JobService that will be called
.setService(DailyReminderService.class)
// uniquely identifies the job
.setTag(DailyReminderService.TAG)
// one-off job
.setRecurring(false)
// persist past a device reboot (requires boot receiver permission)
.setLifetime(Lifetime.FOREVER)
// start between 0 and 60 seconds from now
.setTrigger(Trigger.executionWindow(timeInSeconds, timeInSeconds + 30))
// overwrite an existing job with the same tag
.setReplaceCurrent(true)
// retry with exponential backoff
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
//.setExtras(myExtrasBundle)
.build();
dispatcher.mustSchedule(myJob);
}
示例6: queuePostCore
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
public void queuePostCore(@NonNull FirebaseJobDispatcher dispatcher, @NonNull PostRequest postRequest) {
Bundle extras = new Bundle(2);
extras.putString(GenericJobService.JOB_TYPE, GenericJobService.POST);
extras.putParcelable(GenericJobService.PAYLOAD, postRequest);
dispatcher.mustSchedule(dispatcher.newJobBuilder()
.setService(GenericJobService.class)
.setTag(GenericJobService.POST)
.setRecurring(false)
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
.setTrigger(Trigger.executionWindow(0, 60))
.setReplaceCurrent(false)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setConstraints(Constraint.ON_ANY_NETWORK, Constraint.DEVICE_CHARGING)
.setExtras(extras)
.build());
Log.d("FBJD", postRequest.getMethod() + " request is queued successfully!");
}
示例7: queueFileIOCore
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
public void queueFileIOCore(@NonNull FirebaseJobDispatcher dispatcher, boolean isDownload,
@NonNull FileIORequest fileIORequest) {
Bundle extras = new Bundle(2);
extras.putString(GenericJobService.JOB_TYPE, isDownload ?
GenericJobService.DOWNLOAD_FILE : GenericJobService.UPLOAD_FILE);
extras.putParcelable(GenericJobService.PAYLOAD, fileIORequest);
dispatcher.mustSchedule(dispatcher.newJobBuilder()
.setService(GenericJobService.class)
.setTag(isDownload ? GenericJobService.DOWNLOAD_FILE : GenericJobService.UPLOAD_FILE)
.setRecurring(false)
.setLifetime(Lifetime.FOREVER)
.setReplaceCurrent(false)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setConstraints(fileIORequest.onWifi() ? Constraint.ON_UNMETERED_NETWORK : Constraint.ON_ANY_NETWORK,
fileIORequest.isWhileCharging() ? Constraint.DEVICE_CHARGING : 0)
.setExtras(extras)
.build());
Log.d("FBJD", String.format("%s file request is queued successfully!", isDownload ?
"Download" : "Upload"));
}
示例8: schedulePeriodic
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
public static void schedulePeriodic(Context context, String tag, int period) {
Timber.d("Scheduling a periodic sync every " + period + " seconds");
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job myJob = dispatcher.newJobBuilder()
.setService(QuoteJobService.class)
.setTag(tag)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(period, period))
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
.setConstraints(Constraint.ON_ANY_NETWORK)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.setReplaceCurrent(true)
.build();
dispatcher.mustSchedule(myJob);
}
示例9: onStartJob
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
@Override
public boolean onStartJob(JobParameters job) {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
/* Schedule the job once now*/
Job oneTimeJob = dispatcher.newJobBuilder()
.setService(WakatimeDataSyncJob.class)
.setTag("OneTimeJob")
.setTrigger(Trigger.executionWindow(0, 60))
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.build();
dispatcher.mustSchedule(oneTimeJob);
/* Schedule a recurring job everyday */
Job synJob = dispatcher.newJobBuilder()
.setService(WakatimeDataSyncJob.class)
.setTag(Constants.WAKATIME_DATA_SYNC_JOB_TAG)
.setReplaceCurrent(true)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(Constants.SYNC_PERIOD, Constants.SYNC_TOLERANCE))
.setConstraints(Constraint.ON_ANY_NETWORK)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.build();
dispatcher.mustSchedule(synJob);
return false;
}
示例10: createJob
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
@Override
protected Job createJob(FirebaseJobDispatcher dispatcher) {
return dispatcher.newJobBuilder()
.setLifetime(Lifetime.FOREVER)
.setService(SyncService.class)
.setTag(UNIQUE_TAG)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(DEFAULT_INTERVAL_START, DEFAULT_INTERVAL_END))
.setConstraints(Constraint.ON_ANY_NETWORK)
.setReplaceCurrent(false)
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
.build();
}
示例11: ServiceScheduler
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
/**
* Only call the constructor at the point of changes to avoid omitted changes
* <br />
*
* @param context Current activity context or application context
*/
public ServiceScheduler(@NonNull Context context) {
prefs = new ApplicationPrefs(context);
defaultPrefs = new DefaultPreferences(context);
dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
syncJob = dispatcher.newJobBuilder()
.setRecurring(true)
.setReplaceCurrent(true)
// the JobService that will be called
.setService(JobDispatcherService.class)
// uniquely identifies the job
.setTag(JobDispatcherService.SERVICE_TAG)
// recurring job
.setRecurring(true)
// persist past a device reboot
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
// start between 5 and e.g. 15 minutes (900 seconds)
.setTrigger(Trigger.executionWindow(DefaultPreferences.MINIMUM_SYNC_TIME, defaultPrefs.getSyncTime()))
// overwrite an existing job with the same tag
.setReplaceCurrent(true)
// retry with exponential backoff
.setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)
// constraints that need to be satisfied for the job to run
.setConstraints( // only run on any network
Constraint.ON_ANY_NETWORK)
.build();
}
示例12: scheduleBackgroundJob
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
/**
* Schedule a new background job that will be triggered via {@link FirebaseJobDispatcher}.
*/
private boolean scheduleBackgroundJob(String jobKey, int period, boolean persist,
boolean override, int networkType, boolean requiresCharging, Bundle jobBundle) {
int periodInSeconds = (int) TimeUnit.MILLISECONDS.toSeconds(period);
Job.Builder jobBuilder = mJobDispatcher.newJobBuilder()
.setService(BackgroundJob.class)
.setExtras(jobBundle)
.setTag(jobKey)
.setTrigger(Trigger.executionWindow(periodInSeconds, periodInSeconds))
.setLifetime(persist ? Lifetime.FOREVER : Lifetime.UNTIL_NEXT_BOOT)
.setRecurring(true)
.setReplaceCurrent(override)
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR);
if (requiresCharging) {
jobBuilder.addConstraint(Constraint.DEVICE_CHARGING);
}
if (networkType == Constraint.ON_ANY_NETWORK || networkType == Constraint.ON_UNMETERED_NETWORK) {
jobBuilder.addConstraint(networkType);
}
if (mJobDispatcher.schedule(jobBuilder.build()) == SCHEDULE_RESULT_SUCCESS) {
Log.d(LOG_TAG, "Successfully scheduled: " + jobKey);
return true;
} else {
Log.w(LOG_TAG, "Failed to schedule: " + jobKey);
return false;
}
}
示例13: startService
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
public static void startService (Context context)
{
FirebaseJobDispatcher dispatcher =
new FirebaseJobDispatcher( new GooglePlayDriver( context ) );
Job myJob = dispatcher.newJobBuilder( )
// the JobService that will be called
.setService( SyncService.class )
// uniquely identifies the job
.setTag( "sync-service-tag" )
// one-off job
.setRecurring( false )
// persist past a device reboot
.setLifetime( Lifetime.FOREVER )
// don't overwrite an existing job with the same tag
.setReplaceCurrent( true )
// retry with exponential backoff
.setRetryStrategy( RetryStrategy.DEFAULT_EXPONENTIAL )
// constraints that need to be satisfied for the job to run
.setConstraints(
Constraint.ON_ANY_NETWORK
)
//start job immediately
.setTrigger( Trigger.executionWindow( 0, 0 ) )
.build( );
dispatcher.mustSchedule( myJob );
}
示例14: setup
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
private static boolean setup(@NonNull final Context context, final int timeInSeconds, final boolean waitUnmeteredNetwork) {
if (!isBackupActive(context)) {
return false;
}
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
Job.Builder obBuilder = dispatcher.newJobBuilder()
// the JobService that will be called
.setService(DriveBackupService.class)
// uniquely identifies the job
.setTag(DriveBackupService.TAG)
// one-off job
.setRecurring(false)
// persist past a device reboot (requires boot receiver permission)
.setLifetime(Lifetime.FOREVER)
// overwrite an existing job with the same tag
.setReplaceCurrent(true)
// retry with exponential backoff
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR);
if (waitUnmeteredNetwork) {
// only run on an unmetered network
obBuilder.addConstraint(Constraint.ON_UNMETERED_NETWORK);
}
if (timeInSeconds >= 0) {
// Run after selected time and any time in one hour
obBuilder.setTrigger(Trigger.executionWindow(timeInSeconds, timeInSeconds + 1800));
} else {
obBuilder.setTrigger(Trigger.NOW);
}
return dispatcher.schedule(obBuilder.build()) == FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS;
}
示例15: GeotargetJobManager
import com.firebase.jobdispatcher.RetryStrategy; //导入依赖的package包/类
public GeotargetJobManager(Context context) {
this.context = context;
dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));
currentJob = dispatcher.newJobBuilder()
.setService(GeotargetJobService.class)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(START_WINDOW, STOP_WINDOW))
.setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
.setTag("location-update-job")
.setLifetime(Lifetime.FOREVER)
.setConstraints(Constraint.ON_ANY_NETWORK)
.build();
}