-
-
Save cfloisand/e9dcfa54e4b7a50cd4b3e44a4e7477e5 to your computer and use it in GitHub Desktop.
sync config
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
// One-shot download configuration | |
try { | |
gatewayUrl = "wss://..." | |
Endpoint gatewayEndpoint = new URLEndpoint(new URI(gatewayUrl)); | |
pullConfig = new ReplicatorConfiguration(db, gatewayEndpoint); | |
} catch (Exception e) { | |
//... | |
} | |
String cookie = ...; | |
String channel = ...; | |
String cookieName = ...; | |
String cookieValue = ...; | |
pullConfig.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PULL); | |
pullConfig.setContinuous(false); | |
pullConfig.setChannels(Arrays.asList(channel)); | |
SessionAuthenticator authenticator = new SessionAuthenticator(cookieValue, cookieName); | |
pullConfig.setAuthenticator(authenticator); | |
replicator = new Replicator(pullConfig); | |
replicatorListener = new ReplicatorListener(); | |
replicatorListener.addDownloadListener(() -> { | |
startSync(); //<< One-shot download is done, so start sync mode | |
}); | |
replicatorToken = replicator.addChangeListener(replicatorListener); | |
replicator.start(); | |
// Starting sync mode | |
private void startSync() { | |
replicator.stop(); | |
replicator.removeChangeListener(replicatorToken); | |
ReplicatorConfiguration syncConfig = new ReplicatorConfiguration(replicator.getConfig()); | |
syncConfig.setContinuous(true); | |
syncConfig.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PUSH_AND_PULL); | |
replicator = new Replicator(syncConfig); | |
replicatorToken = replicator.addChangeListener(replicatorListener); | |
replicator.start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment