コード例 #1
0
        protected override IDistributor<int> CreateDistributor(
            Func<Lease<int>, Task> onReceive = null,
            Leasable<int>[] leasables = null,
            int maxDegreesOfParallelism = 1,
            string name = null,
            TimeSpan? waitInterval = null,
            string pool = null)
        {
            leasables = leasables ?? DefaultLeasable;

            pool = pool ?? DateTimeOffset.UtcNow.Ticks.ToString();
            distributor = new SqlBrokeredDistributor<int>(
                leasables,
                Database,
                pool,
                maxDegreesOfParallelism,
                waitInterval,
                DefaultLeaseDuration);

            if (onReceive != null)
            {
                distributor.OnReceive(onReceive);
            }

            Database.RegisterLeasableResources(leasables, pool).Wait();

            return distributor;
        }
コード例 #2
0
 protected abstract IDistributor<int> CreateDistributor(
     Func<Lease<int>, Task> onReceive = null,
     Leasable<int>[] leasables = null,
     int maxDegreesOfParallelism = 5,
     [CallerMemberName] string name = null,
     TimeSpan? waitInterval = null,
     string pool = null);
コード例 #3
0
ファイル: Actor.cs プロジェクト: matijagrcic/Endjin.Leasing
        /// <summary>
        /// This will try and fail if it cannot get the lease first time.
        /// </summary>
        /// <returns></returns>
        public Task RunMutexWithOptionsAsync()
        {
            var leasable = new Leasable(new AzureLeaseProviderFactory(new ConnectionStringProvider()), new AzureLeasePolicyValidator())
            {
                LeasePolicy = new LeasePolicy { Duration = TimeSpan.FromSeconds(15), Name = "LeasingTestHarness", ActorName = this.Name },
                RetryStrategy = new DoNotRetry(),
                RetryPolicy = new DoNotRetryPolicy()
            };

            return leasable.MutexWithOptionsAsync(this.DoSomethingAsync);
        }
コード例 #4
0
ファイル: Actor.cs プロジェクト: endjin/Endjin.Leasing
        /// <summary>
        /// This will try and fail if it cannot get the lease first time.
        /// </summary>
        /// <returns></returns>
        public Task RunMutexWithOptionsAsync()
        {
            var leasable = new Leasable(new AzureLeaseProviderFactory(new ConnectionStringProvider()), new AzureLeasePolicyValidator())
            {
                LeasePolicy = new LeasePolicy {
                    Duration = TimeSpan.FromSeconds(15), Name = "LeasingTestHarness", ActorName = this.Name
                },
                RetryStrategy = new DoNotRetry(),
                RetryPolicy   = new DoNotRetryPolicy()
            };

            return(leasable.MutexWithOptionsAsync(this.DoSomethingAsync));
        }
コード例 #5
0
        public async Task Leases_record_the_time_when_they_were_last_released()
        {
            Leasable <int> leasable    = null;
            var            received    = default(DateTimeOffset);
            var            distributor = CreateDistributor(async l =>
            {
                received = DateTimeOffset.UtcNow;
                leasable = l.Leasable;
            });

            await distributor.Distribute(1);

            leasable.LeaseLastReleased
            .ToUniversalTime()
            .Should()
            .BeCloseTo(received,
                       precision: (int)ClockDriftTolerance.TotalMilliseconds);
        }
コード例 #6
0
 protected override IDistributor<int> CreateDistributor(
     Func<Lease<int>, Task> onReceive = null,
     Leasable<int>[] leasables = null,
     int maxDegreesOfParallelism = 5,
     string name = null,
     TimeSpan? waitInterval = null,
     string pool = null)
 {
     distributor = new InMemoryDistributor<int>(
         leasables ?? DefaultLeasable,
         pool ?? DateTimeOffset.UtcNow.Ticks.ToString(),
         maxDegreesOfParallelism,
         waitInterval,
         DefaultLeaseDuration);
     if (onReceive != null)
     {
         distributor.OnReceive(onReceive);
     }
     return distributor;
 }
コード例 #7
0
 public CouchbaseLiteHttpClient(HttpClient client, DefaultAuthHandler authHandler)
 {
     _httpClient = client;
     _authHandler = authHandler;
     SetConcurrencyLimit(ReplicationOptions.DefaultMaxOpenHttpConnections);
 }
コード例 #8
0
ファイル: Actor.cs プロジェクト: endjin/Endjin.Leasing
        /// <summary>
        /// This will retry until it sucessfully executes.
        /// </summary>
        /// <returns></returns>new
        public Task RunSimpleMutexAsync()
        {
            var leasable = new Leasable(new AzureLeaseProviderFactory(new ConnectionStringProvider()), new AzureLeasePolicyValidator());

            return(leasable.MutexAsync(this.DoSomethingAsync, "LeasingTestHarness", this.Name));
        }
コード例 #9
0
 public CouchbaseLiteHttpClient(HttpClient client, DefaultAuthHandler authHandler)
 {
     _httpClient = client;
     _authHandler = authHandler;
     SetConcurrencyLimit(ReplicationOptions.DefaultMaxOpenHttpConnections);
 }
コード例 #10
0
 public void SetUp()
 {
     DefaultLeasable = Enumerable.Range(1, 10)
                                 .Select(i => new Leasable<int>(i, i.ToString()))
                                 .ToArray();
 }
コード例 #11
0
 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;
 }
コード例 #12
0
ファイル: Actor.cs プロジェクト: matijagrcic/Endjin.Leasing
        /// <summary>
        /// This will retry until it sucessfully executes.
        /// </summary>
        /// <returns></returns>new 
        public Task RunSimpleMutexAsync()
        {
            var leasable = new Leasable(new AzureLeaseProviderFactory(new ConnectionStringProvider()), new AzureLeasePolicyValidator());

            return leasable.MutexAsync(this.DoSomethingAsync, "LeasingTestHarness", this.Name);
        }