public void Setup(ReplicationOptions options) { _remoteRequestCancellationSource?.Cancel(); _remoteRequestCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(_cancellationTokenSource.Token); ClientFactory.SocketTimeout = options.SocketTimeout; var clientObj = ClientFactory.GetHttpClient(CookieStore, options.RetryStrategy); clientObj.Timeout = options.RequestTimeout; clientObj.SetConcurrencyLimit(options.MaxOpenHttpConnections); _client = clientObj; }
/// <summary> /// Triggers one way replication from the source to target. If bidirection is needed call this method twice with the source and target args reversed. /// </summary> /// <param name="source">Uri or database name of database to replicate from</param> /// <param name="target">Uri or database name of database to replicate to</param> /// <param name="continuous">Whether or not CouchDB should continue to replicate going forward on it's own</param> /// <returns></returns> public CouchResponse TriggerReplication(string source, string target, bool continuous) { var request = GetRequest(baseUri + "_replicate"); var options = new ReplicationOptions(source, target, continuous); var response = request.Post() .Data(options.ToString()) .GetResponse(); return(response.GetJObject()); }
public void Setup(ReplicationOptions options) { _remoteRequestCancellationSource?.Cancel(); _remoteRequestCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(_cancellationTokenSource.Token); ClientFactory.SocketTimeout = options.SocketTimeout; #if __ANDROID__ var clientObj = ClientFactory.GetHttpClient(CookieStore, options.RetryStrategy, options.TrustedServerCert); #else var clientObj = ClientFactory.GetHttpClient(CookieStore, options.RetryStrategy); #endif clientObj.Timeout = options.RequestTimeout; clientObj.SetConcurrencyLimit(options.MaxOpenHttpConnections); clientObj.Authenticator = Authenticator; _client = clientObj; }
public void Setup(ReplicationOptions options) { _remoteRequestCancellationSource?.Cancel(); _remoteRequestCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(_cancellationTokenSource.Token); ClientFactory.SocketTimeout = options.SocketTimeout; var clientObj = ClientFactory.GetHttpClient(CookieStore, options.RetryStrategy); clientObj.Timeout = options.RequestTimeout; clientObj.SetConcurrencyLimit(options.MaxOpenHttpConnections); clientObj.Authenticator = Authenticator; _client = clientObj; }
/// <summary> /// Default constructor /// </summary> /// <param name="db">The local database to replicate to/from</param> /// <param name="remote">The remote Uri to sync with</param> /// <param name="continuous">If set to <c>true</c> continuous.</param> /// <param name="clientFactory">The client factory for instantiating the HttpClient used to create web requests</param> /// <param name="workExecutor">The TaskFactory to execute work on</param> internal Replication(Database db, Uri remote, bool continuous, IHttpClientFactory clientFactory, TaskFactory workExecutor) { sessionID = $"repl{ Interlocked.Increment(ref _lastSessionID):000}"; var opts = new RemoteSessionContructorOptions { BaseUrl = remote, WorkExecutor = workExecutor, Id = _replicatorID, CancellationTokenSource = CancellationTokenSource }; _remoteSession = new RemoteSession(opts); Username = remote.UserInfo; LocalDatabase = db; _eventContext = LocalDatabase.Manager.CapturedContext; Continuous = continuous; // NOTE: Consider running a separate scheduler for all http requests. WorkExecutor = workExecutor; RemoteUrl = remote; #pragma warning disable 618 Options = new ReplicationOptionsDictionary(); #pragma warning restore 618 ReplicationOptions = new ReplicationOptions(); if (RemoteUrl.Query != null && !StringEx.IsNullOrWhiteSpace(RemoteUrl.Query)) { Authenticator = AuthenticatorFactory.CreateFromUri(remote); // we need to remove the query from the URL, since it will cause problems when // communicating with sync gw / couchdb try { RemoteUrl = new UriBuilder(remote.Scheme, remote.Host, remote.Port, remote.AbsolutePath).Uri; } catch (UriFormatException e) { throw Misc.CreateExceptionAndLog(Log.To.Sync, e, Tag, "Invalid URI format for remote endpoint"); } } Batcher = new Batcher<RevisionInternal>(workExecutor, INBOX_CAPACITY, ProcessorDelay, inbox => { try { Log.To.Sync.V(Tag, "*** {0} BEGIN ProcessInbox ({1} sequences)", this, inbox.Count); if(Continuous) { FireTrigger(ReplicationTrigger.Resume); } ProcessInbox (new RevisionList(inbox)); Log.To.Sync.V(Tag, "*** {0} END ProcessInbox (lastSequence={1})", this, LastSequence); } catch(Exception e) { throw Misc.CreateExceptionAndLog(Log.To.Sync, e, Tag, "{0} ProcessInbox failed", this); } }); ClientFactory = clientFactory; _stateMachine = new StateMachine<ReplicationState, ReplicationTrigger>(ReplicationState.Initial); InitializeStateMachine(); }