-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
252 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/io/split/android/client/service/synchronizer/LastUpdateTimestampProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.split.android.client.service.synchronizer; | ||
|
||
public interface LastUpdateTimestampProvider { | ||
|
||
long getLastUpdateTimestamp(); | ||
|
||
void setLastUpdateTimestamp(long timestamp); | ||
} |
45 changes: 45 additions & 0 deletions
45
...in/java/io/split/android/client/service/synchronizer/LastUpdateTimestampProviderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.split.android.client.service.synchronizer; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import io.split.android.client.storage.db.GeneralInfoDao; | ||
import io.split.android.client.storage.db.GeneralInfoEntity; | ||
import io.split.android.client.utils.logger.Logger; | ||
|
||
public class LastUpdateTimestampProviderImpl implements LastUpdateTimestampProvider { | ||
|
||
private final ExecutorService mExecutor = Executors.newSingleThreadExecutor(); | ||
private final AtomicLong mTimestamp = new AtomicLong(-1); | ||
private final Object mLock = new Object(); | ||
private final GeneralInfoDao mGeneralInfoDao; | ||
|
||
public LastUpdateTimestampProviderImpl(GeneralInfoDao generalInfoDao) { | ||
mGeneralInfoDao = generalInfoDao; | ||
mExecutor.submit(() -> { | ||
synchronized (mLock) { | ||
Logger.e("Retrieving timestamp for initialization"); | ||
mTimestamp.set(mGeneralInfoDao.getByName(GeneralInfoEntity.SPLITS_UPDATE_TIMESTAMP).getLongValue()); | ||
Logger.e("Initialized timestamp to " + mTimestamp.get()); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public long getLastUpdateTimestamp() { | ||
synchronized (mLock) { | ||
return mTimestamp.get(); | ||
} | ||
} | ||
|
||
@Override | ||
public void setLastUpdateTimestamp(long timestamp) { | ||
mTimestamp.set(timestamp); | ||
mExecutor.submit(() -> { | ||
synchronized (mLock) { | ||
mGeneralInfoDao.update(new GeneralInfoEntity(GeneralInfoEntity.SPLITS_UPDATE_TIMESTAMP, timestamp)); | ||
} | ||
}); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/io/split/android/client/service/synchronizer/RolloutCacheManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.split.android.client.service.synchronizer; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import io.split.android.client.service.synchronizer.mysegments.MySegmentsSynchronizerRegistry; | ||
import io.split.android.client.utils.logger.Logger; | ||
|
||
class RolloutCacheManagerImpl implements RolloutCacheManager { | ||
|
||
private final LastUpdateTimestampProvider mTimestampProvider; | ||
private final FeatureFlagsSynchronizer mFeatureFlagsSynchronizer; | ||
private final MySegmentsSynchronizerRegistry.Tasks mMySegmentsSynchronizerRegistry; | ||
private final boolean mForceCacheExpiration; | ||
private final long mCacheExpirationPeriod; | ||
|
||
RolloutCacheManagerImpl(LastUpdateTimestampProvider timestampProvider, | ||
FeatureFlagsSynchronizer featureFlagsSynchronizer, | ||
MySegmentsSynchronizerRegistry.Tasks mySegmentsSynchronizerRegistry, | ||
boolean forceCacheExpiration, | ||
long cacheExpirationPeriod) { | ||
mTimestampProvider = timestampProvider; | ||
mFeatureFlagsSynchronizer = featureFlagsSynchronizer; | ||
mMySegmentsSynchronizerRegistry = mySegmentsSynchronizerRegistry; | ||
mForceCacheExpiration = forceCacheExpiration; | ||
mCacheExpirationPeriod = cacheExpirationPeriod; | ||
} | ||
|
||
@Override | ||
public void validateCache() { | ||
long lastUpdateTimestamp = mTimestampProvider.getLastUpdateTimestamp(); | ||
long currentTime = System.currentTimeMillis() / 1000; | ||
long elapsedTime = currentTime - lastUpdateTimestamp; | ||
|
||
if (mForceCacheExpiration || TimeUnit.MILLISECONDS.toSeconds(elapsedTime) > mCacheExpirationPeriod) { | ||
if (mForceCacheExpiration) { | ||
Logger.v("Forcing cache expiration"); | ||
} else { | ||
Logger.v("Cache expired due to time"); | ||
} | ||
clearCache(); | ||
} | ||
} | ||
|
||
private void clearCache() { | ||
mFeatureFlagsSynchronizer.expireCache(); | ||
mMySegmentsSynchronizerRegistry.expireCache(); | ||
} | ||
} | ||
|
||
interface RolloutCacheManager { | ||
|
||
void validateCache(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.