3131/**
3232 * Configuration options for {@link AWSDataStorePlugin}.
3333 */
34- @ SuppressWarnings ("WeakerAccess" ) // This is a public API. Public methods available to user's package(s).
3534public final class DataStoreConfiguration {
3635 static final String PLUGIN_CONFIG_KEY = "awsDataStorePlugin" ;
3736 @ VisibleForTesting
@@ -41,26 +40,24 @@ public final class DataStoreConfiguration {
4140 @ VisibleForTesting
4241 static final int DEFAULT_SYNC_PAGE_SIZE = 1_000 ;
4342
44- private final DataStoreErrorHandler dataStoreErrorHandler ;
45- private final DataStoreConflictHandler dataStoreConflictHandler ;
43+ private final DataStoreErrorHandler errorHandler ;
44+ private final DataStoreConflictHandler conflictHandler ;
4645 private final Integer syncMaxRecords ;
4746 private final Integer syncPageSize ;
4847 private Long syncIntervalInMinutes ;
49- private Long syncIntervalMs ;
5048
5149 private DataStoreConfiguration (
52- DataStoreErrorHandler dataStoreErrorHandler ,
53- DataStoreConflictHandler dataStoreConflictHandler ,
50+ DataStoreErrorHandler errorHandler ,
51+ DataStoreConflictHandler conflictHandler ,
5452 Long syncIntervalInMinutes ,
5553 Integer syncMaxRecords ,
5654 Integer syncPageSize ) {
57- this .dataStoreErrorHandler = dataStoreErrorHandler ;
58- this .dataStoreConflictHandler = dataStoreConflictHandler ;
55+ this .errorHandler = errorHandler ;
56+ this .conflictHandler = conflictHandler ;
5957 this .syncMaxRecords = syncMaxRecords ;
6058 this .syncPageSize = syncPageSize ;
6159 if (syncIntervalInMinutes != null ) {
6260 this .syncIntervalInMinutes = syncIntervalInMinutes ;
63- this .syncIntervalMs = TimeUnit .MINUTES .toMillis (syncIntervalInMinutes );
6461 }
6562 }
6663
@@ -108,11 +105,11 @@ static Builder builder(@NonNull JSONObject pluginJson) {
108105 */
109106 @ NonNull
110107 public static DataStoreConfiguration defaults () throws DataStoreException {
111- DataStoreErrorHandler dataStoreErrorHandler = DefaultDataStoreErrorHandler .instance ();
108+ DataStoreErrorHandler errorHandler = DefaultDataStoreErrorHandler .instance ();
112109 return builder ()
113- .dataStoreErrorHandler ( dataStoreErrorHandler )
114- .dataStoreConflictHandler (ApplyRemoteConflictHandler .instance (dataStoreErrorHandler ))
115- .syncIntervalInMinutes (DEFAULT_SYNC_INTERVAL_MINUTES )
110+ .errorHandler ( errorHandler )
111+ .conflictHandler (ApplyRemoteConflictHandler .instance (errorHandler ))
112+ .syncInterval (DEFAULT_SYNC_INTERVAL_MINUTES , TimeUnit . MINUTES )
116113 .syncPageSize (DEFAULT_SYNC_PAGE_SIZE )
117114 .syncMaxRecords (DEFAULT_SYNC_MAX_RECORDS )
118115 .build ();
@@ -123,17 +120,17 @@ public static DataStoreConfiguration defaults() throws DataStoreException {
123120 * @return Data store error handler.
124121 */
125122 @ NonNull
126- public DataStoreErrorHandler getDataStoreErrorHandler () {
127- return this .dataStoreErrorHandler ;
123+ public DataStoreErrorHandler getErrorHandler () {
124+ return this .errorHandler ;
128125 }
129126
130127 /**
131128 * Gets the data store conflict handler.
132129 * @return Data store conflict handler
133130 */
134131 @ NonNull
135- public DataStoreConflictHandler getDataStoreConflictHandler () {
136- return this .dataStoreConflictHandler ;
132+ public DataStoreConflictHandler getConflictHandler () {
133+ return this .conflictHandler ;
137134 }
138135
139136 /**
@@ -144,7 +141,7 @@ public DataStoreConflictHandler getDataStoreConflictHandler() {
144141 */
145142 @ IntRange (from = 0 )
146143 public Long getSyncIntervalMs () {
147- return this . syncIntervalMs ;
144+ return TimeUnit . MINUTES . toMillis ( syncIntervalInMinutes ) ;
148145 }
149146
150147 /**
@@ -187,10 +184,10 @@ public boolean equals(@Nullable Object thatObject) {
187184 return false ;
188185 }
189186 DataStoreConfiguration that = (DataStoreConfiguration ) thatObject ;
190- if (!ObjectsCompat .equals (getDataStoreErrorHandler (), that .getDataStoreConflictHandler ())) {
187+ if (!ObjectsCompat .equals (getErrorHandler (), that .getConflictHandler ())) {
191188 return false ;
192189 }
193- if (!ObjectsCompat .equals (getDataStoreConflictHandler (), that .getDataStoreConflictHandler ())) {
190+ if (!ObjectsCompat .equals (getConflictHandler (), that .getConflictHandler ())) {
194191 return false ;
195192 }
196193 if (!ObjectsCompat .equals (getSyncMaxRecords (), that .getSyncMaxRecords ())) {
@@ -199,33 +196,27 @@ public boolean equals(@Nullable Object thatObject) {
199196 if (!ObjectsCompat .equals (getSyncPageSize (), that .getSyncPageSize ())) {
200197 return false ;
201198 }
202- if (!ObjectsCompat .equals (getSyncIntervalInMinutes (), that .getSyncIntervalInMinutes ())) {
203- return false ;
204- }
205- return ObjectsCompat .equals (getSyncIntervalMs (), that .getSyncIntervalMs ());
199+ return ObjectsCompat .equals (getSyncIntervalInMinutes (), that .getSyncIntervalInMinutes ());
206200 }
207201
208- @ SuppressWarnings ("ConstantConditions" )
209202 @ Override
210203 public int hashCode () {
211- int result = getDataStoreErrorHandler () != null ? getDataStoreErrorHandler ().hashCode () : 0 ;
212- result = 31 * result + (getDataStoreConflictHandler () != null ? getDataStoreConflictHandler ().hashCode () : 0 );
204+ int result = getErrorHandler () != null ? getErrorHandler ().hashCode () : 0 ;
205+ result = 31 * result + (getConflictHandler () != null ? getConflictHandler ().hashCode () : 0 );
213206 result = 31 * result + (getSyncMaxRecords () != null ? getSyncMaxRecords ().hashCode () : 0 );
214207 result = 31 * result + (getSyncPageSize () != null ? getSyncPageSize ().hashCode () : 0 );
215208 result = 31 * result + (getSyncIntervalInMinutes () != null ? getSyncIntervalInMinutes ().hashCode () : 0 );
216- result = 31 * result + (getSyncIntervalMs () != null ? getSyncIntervalMs ().hashCode () : 0 );
217209 return result ;
218210 }
219211
220212 @ Override
221213 public String toString () {
222214 return "DataStoreConfiguration{" +
223- "dataStoreErrorHandler =" + dataStoreErrorHandler +
224- ", dataStoreConflictHandler =" + dataStoreConflictHandler +
215+ "errorHandler =" + errorHandler +
216+ ", conflictHandler =" + conflictHandler +
225217 ", syncMaxRecords=" + syncMaxRecords +
226218 ", syncPageSize=" + syncPageSize +
227219 ", syncIntervalInMinutes=" + syncIntervalInMinutes +
228- ", syncIntervalMs=" + syncIntervalMs +
229220 '}' ;
230221 }
231222
@@ -234,8 +225,8 @@ public String toString() {
234225 * configuration methods.
235226 */
236227 public static final class Builder {
237- private DataStoreErrorHandler dataStoreErrorHandler ;
238- private DataStoreConflictHandler dataStoreConflictHandler ;
228+ private DataStoreErrorHandler errorHandler ;
229+ private DataStoreConflictHandler conflictHandler ;
239230 private Long syncIntervalInMinutes ;
240231 private Integer syncMaxRecords ;
241232 private Integer syncPageSize ;
@@ -244,8 +235,8 @@ public static final class Builder {
244235 private DataStoreConfiguration userProvidedConfiguration ;
245236
246237 private Builder () {
247- this .dataStoreErrorHandler = DefaultDataStoreErrorHandler .instance ();
248- this .dataStoreConflictHandler = ApplyRemoteConflictHandler .instance (dataStoreErrorHandler );
238+ this .errorHandler = DefaultDataStoreErrorHandler .instance ();
239+ this .conflictHandler = ApplyRemoteConflictHandler .instance (errorHandler );
249240 this .ensureDefaults = false ;
250241 }
251242
@@ -259,35 +250,36 @@ private Builder(JSONObject pluginJson, DataStoreConfiguration userProvidedConfig
259250 /**
260251 * A handler that will be invoked whenever there is a conflict between two model instances,
261252 * one in the local store, and one from the remote server, as received from a sync operation.
262- * @param dataStoreConflictHandler A handler to invoke upon sync conflicts
253+ * @param conflictHandler A handler to invoke upon sync conflicts
263254 * @return Current builder
264255 */
265256 @ NonNull
266- public Builder dataStoreConflictHandler (@ NonNull DataStoreConflictHandler dataStoreConflictHandler ) {
267- this .dataStoreConflictHandler = Objects .requireNonNull (dataStoreConflictHandler );
257+ public Builder conflictHandler (@ NonNull DataStoreConflictHandler conflictHandler ) {
258+ this .conflictHandler = Objects .requireNonNull (conflictHandler );
268259 return Builder .this ;
269260 }
270261
271262 /**
272263 * Sets a handler function to be applied when the DataStore encounters an unrecoverable error
273264 * in one of its ongoing background operations (model synchronization).
274- * @param dataStoreErrorHandler A handler for unrecoverable background errors
265+ * @param errorHandler A handler for unrecoverable background errors
275266 * @return Current builder instance
276267 */
277268 @ NonNull
278- public Builder dataStoreErrorHandler (@ NonNull DataStoreErrorHandler dataStoreErrorHandler ) {
279- this .dataStoreErrorHandler = Objects .requireNonNull (dataStoreErrorHandler );
269+ public Builder errorHandler (@ NonNull DataStoreErrorHandler errorHandler ) {
270+ this .errorHandler = Objects .requireNonNull (errorHandler );
280271 return Builder .this ;
281272 }
282273
283274 /**
284275 * Sets the duration of time after which delta syncs will not be preferred over base syncs.
285- * @param syncIntervalInMinutes The amount of time that must elapse for delta syncs to not be considered
276+ * @param duration The amount of time that must elapse for delta syncs to not be considered
277+ * @param timeUnit The time unit of the duration field
286278 * @return Current builder instance
287279 */
288280 @ NonNull
289- public Builder syncIntervalInMinutes (@ IntRange (from = 0 ) Long syncIntervalInMinutes ) {
290- this .syncIntervalInMinutes = syncIntervalInMinutes ;
281+ public Builder syncInterval (@ IntRange (from = 0 ) long duration , TimeUnit timeUnit ) {
282+ this .syncIntervalInMinutes = timeUnit . toMinutes ( duration ) ;
291283 return Builder .this ;
292284 }
293285
@@ -332,8 +324,8 @@ private void populateSettingsFromJson() throws DataStoreException {
332324 try {
333325 switch (configKey ) {
334326 case SYNC_INTERVAL_IN_MINUTES :
335- this . syncIntervalInMinutes ( pluginJson
336- . getLong ( ConfigKey . SYNC_INTERVAL_IN_MINUTES . toString ()) );
327+ long duration = pluginJson . getLong ( ConfigKey . SYNC_INTERVAL_IN_MINUTES . toString ());
328+ this . syncInterval ( duration , TimeUnit . MINUTES );
337329 break ;
338330 case SYNC_MAX_RECORDS :
339331 this .syncMaxRecords (pluginJson .getInt (ConfigKey .SYNC_MAX_RECORDS .toString ()));
@@ -357,8 +349,8 @@ private void applyUserProvidedConfiguration() {
357349 if (userProvidedConfiguration == null ) {
358350 return ;
359351 }
360- dataStoreErrorHandler = userProvidedConfiguration .getDataStoreErrorHandler ();
361- dataStoreConflictHandler = userProvidedConfiguration .getDataStoreConflictHandler ();
352+ errorHandler = userProvidedConfiguration .getErrorHandler ();
353+ conflictHandler = userProvidedConfiguration .getConflictHandler ();
362354 syncIntervalInMinutes = getValueOrDefault (
363355 userProvidedConfiguration .getSyncIntervalInMinutes (),
364356 syncIntervalInMinutes );
@@ -381,19 +373,19 @@ public DataStoreConfiguration build() throws DataStoreException {
381373 populateSettingsFromJson ();
382374 applyUserProvidedConfiguration ();
383375 if (ensureDefaults ) {
384- dataStoreErrorHandler = getValueOrDefault (
385- dataStoreErrorHandler ,
376+ errorHandler = getValueOrDefault (
377+ errorHandler ,
386378 DefaultDataStoreErrorHandler .instance ());
387- dataStoreConflictHandler = getValueOrDefault (
388- dataStoreConflictHandler ,
389- ApplyRemoteConflictHandler .instance (dataStoreErrorHandler ));
379+ conflictHandler = getValueOrDefault (
380+ conflictHandler ,
381+ ApplyRemoteConflictHandler .instance (errorHandler ));
390382 syncIntervalInMinutes = getValueOrDefault (syncIntervalInMinutes , DEFAULT_SYNC_INTERVAL_MINUTES );
391383 syncMaxRecords = getValueOrDefault (syncMaxRecords , DEFAULT_SYNC_MAX_RECORDS );
392384 syncPageSize = getValueOrDefault (syncPageSize , DEFAULT_SYNC_PAGE_SIZE );
393385 }
394386 return new DataStoreConfiguration (
395- dataStoreErrorHandler ,
396- dataStoreConflictHandler ,
387+ errorHandler ,
388+ conflictHandler ,
397389 syncIntervalInMinutes ,
398390 syncMaxRecords ,
399391 syncPageSize
0 commit comments