Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use new CouchPersistentReplication.

  • Loading branch information...
commit 17411445001363a71891dc5a4a8b93f3d6db0013 1 parent e2c3969
@snej snej authored
View
18 Source/DemoAppDelegate.m
@@ -71,7 +71,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// Start the Couchbase Server
#ifdef USE_REMOTE_SERVER
- [self performSelector: @selector(couchbaseDidStart:)
+ [self performSelector: @selector(connectToServer:)
withObject: [NSURL URLWithString: USE_REMOTE_SERVER]
afterDelay: 0.0];
#else
@@ -93,9 +93,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
--(void)couchbaseMobile:(CouchbaseMobile*)couchbase didStart:(NSURL*)serverURL {
+- (void)connectToServer:(NSURL*)serverURL {
NSLog(@"GrocerySync: couchbaseMobile:didStart: <%@>", serverURL);
- gCouchLogLevel = 1;
+ gCouchLogLevel = 2;
RootViewController* root = (RootViewController*)navigationController.topViewController;
@@ -116,9 +116,6 @@ -(void)couchbaseMobile:(CouchbaseMobile*)couchbase didStart:(NSURL*)serverURL {
// Take down the splash screen:
[self removeSplash];
- } else {
- // When the server restarts, just tell the root controller to start syncing again:
- [root startSync];
}
database.tracksChanges = YES;
@@ -126,6 +123,11 @@ -(void)couchbaseMobile:(CouchbaseMobile*)couchbase didStart:(NSURL*)serverURL {
}
+-(void)couchbaseMobile:(CouchbaseMobile*)couchbase didStart:(NSURL*)serverURL {
+ [self connectToServer:serverURL];
+}
+
+
-(void)couchbaseMobile:(CouchbaseMobile*)couchbase failedToStart:(NSError*)error {
NSLog(@"GrocerySync: couchbaseMobile:failedToStart: %@", error);
[self showAlert: @"Couldn't start Couchbase."
@@ -143,10 +145,6 @@ - (void)applicationDidEnterBackground:(UIApplication *)application {
// Turn off the _changes watcher:
database.tracksChanges = NO;
- // Turn off syncing:
- RootViewController* root = (RootViewController*)navigationController.topViewController;
- [root stopSync];
-
// Make sure all transactions complete, because going into the background will
// close down the CouchDB server:
[RESTOperation wait: self.database.server.activeOperations];
View
9 Source/RootViewController.h
@@ -20,15 +20,15 @@
#import <UIKit/UIKit.h>
#import <CouchCocoa/CouchUITableSource.h>
-@class CouchDatabase, CouchReplication;
+@class CouchDatabase, CouchPersistentReplication;
@interface RootViewController : UIViewController <CouchUITableDelegate, UITextFieldDelegate>
{
CouchDatabase *database;
NSURL* remoteSyncURL;
- CouchReplication* _pull;
- CouchReplication* _push;
+ CouchPersistentReplication* _pull;
+ CouchPersistentReplication* _push;
UITableView *tableView;
IBOutlet UIProgressView *progress;
@@ -45,7 +45,4 @@
- (IBAction)configureSync:(id)sender;
- (IBAction) deleteCheckedItems:(id)sender;
-- (void) startSync;
-- (void) stopSync;
-
@end
View
45 Source/RootViewController.m
@@ -34,7 +34,7 @@ - (void)updateSyncURL;
- (void)showSyncButton;
- (void)showSyncStatus;
- (IBAction)configureSync:(id)sender;
-- (void)stopSync;
+- (void)forgetSync;
@end
@@ -74,7 +74,7 @@ - (void)viewDidLoad {
- (void)dealloc {
- [self stopSync];
+ [self forgetSync];
[database release];
[super dealloc];
}
@@ -82,7 +82,7 @@ - (void)dealloc {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear: animated];
- // Check for changes after returning from the sync confic view:
+ // Check for changes after returning from the sync config view:
[self updateSyncURL];
}
@@ -290,44 +290,23 @@ - (void)updateSyncURL {
if (syncpoint.length > 0)
newRemoteURL = [NSURL URLWithString:syncpoint];
- if (newRemoteURL != remoteSyncURL && ![newRemoteURL isEqual: remoteSyncURL]) {
- // Set up synchronization to/from a remote database:
- NSLog(@"Changing sync to <%@>", newRemoteURL.absoluteString);
- self.remoteSyncURL = newRemoteURL;
- [self stopSync];
- [self startSync];
- }
-
-}
+ [self forgetSync];
-
-- (void) startSync {
- if (remoteSyncURL && !_pull) {
- NSLog(@"Starting sync with %@", remoteSyncURL);
- _pull = [[database pullFromDatabaseAtURL: remoteSyncURL
- options: kCouchReplicationContinuous] retain];
- [_pull addObserver: self forKeyPath: @"status" options: 0 context: NULL];
-
- _push = [[database pushToDatabaseAtURL: remoteSyncURL
- options: kCouchReplicationContinuous] retain];
- [_push addObserver: self forKeyPath: @"status" options: 0 context: NULL];
- database.server.activityPollInterval = 1.0;
- }
+ NSArray* repls = [self.database replicateWithURL: newRemoteURL exclusively: YES];
+ _pull = [[repls objectAtIndex: 0] retain];
+ _push = [[repls objectAtIndex: 1] retain];
+ [_pull addObserver: self forKeyPath: @"completed" options: 0 context: NULL];
+ [_push addObserver: self forKeyPath: @"completed" options: 0 context: NULL];
}
-- (void) stopSync {
- if (_pull || _push)
- NSLog(@"Stopping sync");
- [_pull removeObserver: self forKeyPath: @"status"];
- [_pull stop];
+- (void) forgetSync {
+ [_pull removeObserver: self forKeyPath: @"completed"];
[_pull release];
_pull = nil;
- [_push removeObserver: self forKeyPath: @"status"];
- [_push stop];
+ [_push removeObserver: self forKeyPath: @"completed"];
[_push release];
_push = nil;
- database.server.activityPollInterval = 0.0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.