CouchbaseLite 等待拉取复制完成
CouchbaseLite wait for pull replication to finish
我有一个通过 CouchBaseLite 1.4 连接的 CouchDB。在继续申请之前,我无法等待提取所有文件。
目前我正在以一种非常 hacky 的方式实现这一点,我想修复它以更好地符合适当的编码标准。
当前:
pull.setContinuous(false);
pull.start();
//Waits for pull replication to start pulling in data
while(!pull.isRunning());
//Waits for pull replication to finish.
while(!pull.getStatus().equals(Replication.ReplicationStatus.REPLICATION_STOPPED));
//Set continuous to true
pull.setContinuous(true);
//Start it again.
pull.start();
我这样做的原因是数据库中可能有 2 个文档需要等待,如果它们不存在,桌面应用程序将进入设置模式。
- 有没有办法等待所有文件拉取完成
没有 hacky double
while
?
- 更好的是,假设我知道文档的
_id
。有没有办法等到两个都拉完再继续?
使用更改侦听器。要监视复制,您需要类似
// Replication.ChangeListener
@Override
public void changed(Replication.ChangeEvent changeEvent) {
if (changeEvent.getError() != null) {
Throwable lastError = changeEvent.getError();
// React to the error
return;
}
if (changeEvent.getTransition() == null) return;
ReplicationState dest = changeEvent.getTransition().getDestination();
replicationActive = ((dest == ReplicationState.STOPPING || dest == ReplicationState.STOPPED) ? false : true);
// Do something here if true
}
您可以对数据库对象的更改侦听器执行类似的操作,以在复制两个特定文档时进行捕获。
由于听起来您希望这些文档在其他地方的初始设置后位于数据库中,另一种方法是进行一次复制以获取那些第一个文档,然后在它之后开始连续复制已完成。
我有一个通过 CouchBaseLite 1.4 连接的 CouchDB。在继续申请之前,我无法等待提取所有文件。
目前我正在以一种非常 hacky 的方式实现这一点,我想修复它以更好地符合适当的编码标准。
当前:
pull.setContinuous(false);
pull.start();
//Waits for pull replication to start pulling in data
while(!pull.isRunning());
//Waits for pull replication to finish.
while(!pull.getStatus().equals(Replication.ReplicationStatus.REPLICATION_STOPPED));
//Set continuous to true
pull.setContinuous(true);
//Start it again.
pull.start();
我这样做的原因是数据库中可能有 2 个文档需要等待,如果它们不存在,桌面应用程序将进入设置模式。
- 有没有办法等待所有文件拉取完成
没有 hacky double
while
? - 更好的是,假设我知道文档的
_id
。有没有办法等到两个都拉完再继续?
使用更改侦听器。要监视复制,您需要类似
// Replication.ChangeListener
@Override
public void changed(Replication.ChangeEvent changeEvent) {
if (changeEvent.getError() != null) {
Throwable lastError = changeEvent.getError();
// React to the error
return;
}
if (changeEvent.getTransition() == null) return;
ReplicationState dest = changeEvent.getTransition().getDestination();
replicationActive = ((dest == ReplicationState.STOPPING || dest == ReplicationState.STOPPED) ? false : true);
// Do something here if true
}
您可以对数据库对象的更改侦听器执行类似的操作,以在复制两个特定文档时进行捕获。
由于听起来您希望这些文档在其他地方的初始设置后位于数据库中,另一种方法是进行一次复制以获取那些第一个文档,然后在它之后开始连续复制已完成。