-
public interface WorkManagerReplicatorFactory
To create a WorkManager Replicator, subclass this interface. The subclass must:
have a no-args constructor
not depend on any application state it does not construct
The second of these two constraints is pretty serious hindrance. Nearly every use of this class will be a distinct instance: the values set in one will not be visible from any other. Beyond that, a given use may be part of a completely different instance of the application than the any previous use: your application may have been stopped and restarted again, just to run the replication. You cannot even depend on static/class/companion variables!
The main job of your subclass is to create a
WorkManagerReplicatorConfiguration
and a unique tag that will identify the replicator it starts. The tag is a string that identifies the replication process: many instances of replicators, possibly across many instance of the application. To start a replication worker, ask your factory subclass for the appropriate work manager request (one-shot, or periodic) and enqueue the request as you would any other. Cancel a replication process using its tag:WorkManager.getInstance(context).cancelAllWorkByTag(factory.tag)
This system depends on there being exactly one process, the replicator process, with the given tag.
-
-
Method Summary
Modifier and Type Method Description abstract WorkManagerReplicatorConfiguration
getConfig()
OneTimeWorkRequest.Builder
oneTimeWorkRequestBuilder()
PeriodicWorkRequest.Builder
periodicWorkRequestBuilder(Duration repeatInterval, Duration flexInterval)
PeriodicWorkRequest.Builder
periodicWorkRequestBuilder(Long repeatInterval, TimeUnit repeatIntervalTimeUnit, Long flexInterval, TimeUnit flexIntervalTimeUnit)
abstract String
getTag()
-
-
Method Detail
-
getConfig
abstract WorkManagerReplicatorConfiguration getConfig()
-
oneTimeWorkRequestBuilder
OneTimeWorkRequest.Builder oneTimeWorkRequestBuilder()
-
periodicWorkRequestBuilder
PeriodicWorkRequest.Builder periodicWorkRequestBuilder(Duration repeatInterval, Duration flexInterval)
-
periodicWorkRequestBuilder
PeriodicWorkRequest.Builder periodicWorkRequestBuilder(Long repeatInterval, TimeUnit repeatIntervalTimeUnit, Long flexInterval, TimeUnit flexIntervalTimeUnit)
-
-
-
-