本文整理汇总了Java中com.couchbase.lite.replicator.Replication类的典型用法代码示例。如果您正苦于以下问题:Java Replication类的具体用法?Java Replication怎么用?Java Replication使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Replication类属于com.couchbase.lite.replicator包,在下文中一共展示了Replication类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changed
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
@Override
public void changed(Replication.ChangeEvent event) {
Throwable error = null;
if (mPull != null) {
if (error == null)
error = mPull.getLastError();
}
if (error == null || error == mReplError)
error = mPush.getLastError();
if (error != mReplError) {
mReplError = error;
if (mReplError != null)
showErrorMessage(mReplError.getMessage(), null);
}
}
示例2: startSync
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
private void startSync() {
URL url;
try {
url = new URL(syncUrl);
} catch (MalformedURLException e) {
Log.e(TAG, e.getMessage());
return;
}
Replication replication = mDatabase.createPullReplication(url);
replication.setChannels(Arrays.asList(channels));
replication.setContinuous(true);
replication.addChangeListener(changeListener);
replication.start();
}
示例3: startSync
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
private void startSync() {
URL syncUrl;
try {
syncUrl = new URL(SYNC_URL);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
Replication pullReplication = database.createPullReplication(syncUrl);
pullReplication.setContinuous(true);
Replication pushReplication = database.createPushReplication(syncUrl);
pushReplication.setContinuous(true);
pullReplication.start();
pushReplication.start();
pullReplication.addChangeListener(this);
pushReplication.addChangeListener(this);
}
示例4: startSync
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
private void startSync() {
URL url = null;
try {
url = new URL(SYNC_URL);
} catch (MalformedURLException e) {
e.printStackTrace();
}
Authenticator authenticator = new BasicAuthenticator("james", "letmein");
Replication push = database.createPushReplication(url);
push.setContinuous(true);
push.setAuthenticator(authenticator);
push.start();
Replication pull = database.createPullReplication(url);
pull.setContinuous(true);
pull.setAuthenticator(authenticator);
pull.start();
}
示例5: forgetDatabase
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
/**
* @exclude
*/
@InterfaceAudience.Private
protected void forgetDatabase(Database db) {
synchronized (lockDatabases) {
Log.v(Log.TAG_DATABASE, "Fogetting forgetDatabase() %s %s", this, db);
// remove from cached list of dbs
databases.remove(db.getName());
// remove from list of replications
// TODO: should there be something that actually stops the replication(s) first?
Iterator<Replication> replicationIterator = this.replications.iterator();
while (replicationIterator.hasNext()) {
Replication replication = replicationIterator.next();
if (replication.getLocalDatabase().getName().equals(db.getName())) {
replicationIterator.remove();
}
}
// Remove registered encryption key if available:
encryptionKeys.remove(db.getName());
Log.v(Log.TAG_DATABASE, "Forgot forgetDatabase() %s %s", this, db);
}
}
示例6: addActiveReplication
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
@InterfaceAudience.Private
public void addActiveReplication(Replication replication) {
replication.addChangeListener(new Replication.ChangeListener() {
@Override
public void changed(Replication.ChangeEvent event) {
ReplicationStateTransition transition = event.getTransition();
if (transition != null && transition.getDestination() == ReplicationState.STOPPED) {
synchronized (activeReplicators) {
activeReplicators.remove(event.getSource());
activeReplicators.notifyAll();
}
}
}
});
activeReplicators.add(replication);
}
示例7: changed
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
@Override
public void changed(Replication.ChangeEvent event) {
final int changeCount = event.getChangeCount();
if (changeCount > 0) {
((Activity) mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, String.format("%d document(s) changed", changeCount), Toast.LENGTH_SHORT).show();
}
});
}
}
示例8: Manager
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
/**
* Constructor
*
* @throws java.lang.SecurityException - Runtime exception that can be thrown by File.mkdirs()
*/
@InterfaceAudience.Public
public Manager(Context context, ManagerOptions options) throws IOException {
Log.i(Database.TAG, "### %s ###", getFullVersionInfo());
this.context = context;
this.directoryFile = context.getFilesDir();
this.options = (options != null) ? options : DEFAULT_OPTIONS;
this.databases = new HashMap<String, Database>();
this.encryptionKeys = new HashMap<String, Object>();
this.replications = new ArrayList<Replication>();
if (!directoryFile.exists()) {
directoryFile.mkdirs();
}
if (!directoryFile.isDirectory()) {
throw new IOException(String.format(Locale.ENGLISH, "Unable to create directory for: %s", directoryFile));
}
upgradeOldDatabaseFiles(directoryFile);
// this must be a single threaded executor due to contract w/ Replication object
// which must run on either:
// - a shared single threaded executor
// - its own single threaded executor
workExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "CBLManagerWorkExecutor");
}
});
}
示例9: isValidDatabaseName
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
/**
* Returns YES if the given name is a valid database name.
* (Only the characters in "abcdefghijklmnopqrstuvwxyz0123456789_$()+-/" are allowed.)
*/
@InterfaceAudience.Public
public static boolean isValidDatabaseName(String databaseName) {
if (databaseName.length() > 0 && databaseName.length() < 240 &&
containsOnlyLegalCharacters(databaseName) &&
Character.isLowerCase(databaseName.charAt(0))) {
return true;
}
return databaseName.equals(Replication.REPLICATOR_DATABASE_NAME);
}
示例10: getAllReplications
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
/**
* Get all the replicators associated with this database.
*/
@InterfaceAudience.Public
public List<Replication> getAllReplications() {
if (!isOpen()) throw new CouchbaseLiteRuntimeException("Database is closed.");
storeRef.retain();
try {
List<Replication> allReplicatorsList = new ArrayList<Replication>();
synchronized (activeReplicators) {
allReplicatorsList.addAll(activeReplicators);
}
return allReplicatorsList;
} finally {
storeRef.release();
}
}
示例11: createPullReplication
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
/**
* Creates a new Replication that will pull from the source Database at the given url.
*
* @param remote the remote URL to pull from
* @return A new Replication that will pull from the source Database at the given url.
*/
@InterfaceAudience.Public
public Replication createPullReplication(URL remote) {
if (remote == null) throw new IllegalArgumentException("remote is null");
if (!isOpen()) throw new CouchbaseLiteRuntimeException("Database is closed.");
storeRef.retain();
try {
return new Replication(this, remote, Replication.Direction.PULL, getHttpClientFactory());
} finally {
storeRef.release();
}
}
示例12: createPushReplication
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
/**
* Creates a new Replication that will push to the target Database at the given url.
*
* @param remote the remote URL to push to
* @return A new Replication that will push to the target Database at the given url.
*/
@InterfaceAudience.Public
public Replication createPushReplication(URL remote) {
if (remote == null) throw new IllegalArgumentException("remote is null");
if (!isOpen()) throw new CouchbaseLiteRuntimeException("Database is closed.");
storeRef.retain();
try {
return new Replication(this, remote, Replication.Direction.PUSH, getHttpClientFactory());
} finally {
storeRef.release();
}
}
示例13: findActiveReplicator
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
protected Replication findActiveReplicator(Replication replicator) {
synchronized (activeReplicators) {
String remoteCheckpointDocID = replicator.remoteCheckpointDocID();
if (remoteCheckpointDocID == null)
return null;
for (Replication r : activeReplicators) {
if (remoteCheckpointDocID.equals(r.remoteCheckpointDocID()) && r.isRunning())
return r;
}
}
return null;
}
示例14: testPull
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
public void testPull() throws IOException {
CountDownLatch doneSignal = new CountDownLatch(1);
HttpClient httpClient = new CBLiteHttpClient(manager);
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
// create a local database
CouchDbConnector dbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);
// push this database to the test replication server
ReplicationCommand pushCommand = new ReplicationCommand.Builder()
.source(getReplicationURL().toExternalForm())
.target(DEFAULT_TEST_DB)
.continuous(false)
.build();
ReplicationStatus status = dbInstance.replicate(pushCommand);
Replication repl = database.getReplicator(status.getSessionId());
ReplicationChangeListener replicationObserver = new ReplicationChangeListener(doneSignal);
repl.addChangeListener(replicationObserver);
try {
boolean success = doneSignal.await(30, TimeUnit.SECONDS);
assertTrue(success);
} catch (InterruptedException e) {
e.printStackTrace();
}
Assert.assertNotNull(status.getSessionId());
}
示例15: testPullWithObserver
import com.couchbase.lite.replicator.Replication; //导入依赖的package包/类
public void testPullWithObserver() throws IOException {
CountDownLatch doneSignal = new CountDownLatch(1);
HttpClient httpClient = new CBLiteHttpClient(manager);
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
// push this database to the test replication server
ReplicationCommand pushCommand = new ReplicationCommand.Builder()
.source(getReplicationURL().toExternalForm())
.target(DEFAULT_TEST_DB)
.continuous(false)
.build();
ReplicationStatus status = dbInstance.replicate(pushCommand);
Replication repl = database.getReplicator(status.getSessionId());
ReplicationChangeListener replicationObserver = new ReplicationChangeListener(doneSignal);
repl.addChangeListener(replicationObserver);
Assert.assertNotNull(status.getSessionId());
Assert.assertEquals(repl.getSessionID(), status.getSessionId());
try {
boolean success = doneSignal.await(30, TimeUnit.SECONDS);
assertTrue(success);
} catch (InterruptedException e) {
e.printStackTrace();
}
Assert.assertTrue(replicationObserver.isReplicationFinished());
}