Beispiel #1
0
        public TimeSpan Renewal(ILease lease) {
#if DEBUG
            return TimeSpan.FromMinutes(10);
#else
            return TimeSpan.FromHours(1);
#endif
        }
 // In order to take advantage of the XamlBuildTaskRemotingLeaseLifetimeInMinutes environment variable from an MSBuild
 // project file (e.g. csproj file), the following needs to be added to that project file:
 //
 // After the initial "<Project ..." line:
 // <UsingTask TaskName="MySetEnv" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
 //   <ParameterGroup>
 //     <Name Required="true" />
 //     <Value Required="false" />
 //   </ParameterGroup>
 //   <Task>
 //     <Code Type="Fragment" Language="cs">System.Environment.SetEnvironmentVariable(Name, Value);</Code>
 //   </Task>
 // </UsingTask>
 //
 // And at the end of the project file, before the closing </Project> :
 //
 // <Target Name="BeforeBuild">
 //   <MySetEnv Name="XamlBuildTaskTimeoutInMinutes" Value="24" />
 // </Target>
 // <Target Name="AfterBuild">
 //   <MySetEnv Name="XamlBuildTaskRemotingLeaseLifetimeInMinutes" Value="" />
 // </Target>
 //
 // This example uses a task name of "MySetEnv", but it that name could be anything desired.
 // It also sets the timeout to 24 minutes, as defined as the Value specified to the MySetEnv task.
 // The AfterBuild target is not required, but is probably desired so that the environment variable setting
 // does not persist after the processing of this particular project file.
 // The valid values for the environment variable are numbers between 1 and 2147483647 inclusive
 // (positive 32-bit integers). Any other value will result in no change to the lease lifetime.
 internal static void SetLeaseLifetimeFromEnvironmentVariable(ILease lease)
 {
     // We can only change the lease lifetime if we have an ILease and it is still in the Initial state.
     if ((lease != null) && (lease.CurrentState == LeaseState.Initial))
     {
         try
         {
             string remotingLeaseLifetimeInMinutesStringValue = Environment.GetEnvironmentVariable(RemotingLeaseLifetimeInMinutesEnvironmentVariableName);
             if (!string.IsNullOrEmpty(remotingLeaseLifetimeInMinutesStringValue))
             {
                 int remotingLeaseLifetimeInMinutes = -1;
                 if (Int32.TryParse(remotingLeaseLifetimeInMinutesStringValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out remotingLeaseLifetimeInMinutes))
                 {
                     // revert to the defauilt if the number specified is less than or equal to 0.
                     if (remotingLeaseLifetimeInMinutes > 0)
                     {
                         lease.InitialLeaseTime = TimeSpan.FromMinutes(remotingLeaseLifetimeInMinutes);
                         lease.RenewOnCallTime = TimeSpan.FromMinutes(remotingLeaseLifetimeInMinutes);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             // simply ignore any exceptions that might have occurred and go with the default. We can't log it because
             // we aren't initialized enough at this point.
             if (Fx.IsFatal(ex))
             {
                 throw;
             }
         }
     }
 }
Beispiel #3
0
 public TimeSpan Renewal(ILease lease)
 {
     //If the kill delay has expired
     if (m_expireSet && m_expires.CompareTo(DateTime.Now) < 0)
         m_live = false;
     return m_live ? TimeSpan.FromMinutes(TIMEOUT_MIN) : TimeSpan.Zero;
 }
 public LeaseAcquireResponse TryRenewBrokerLease(String topic, int partition, ILease lease, String sessionId,
                                                 int brokerPort)
 {
     long expireTime = new DateTime().CurrentTimeMillis() + 10 * 1000L;
     long leaseId = m_leaseId.AtomicIncrementAndGet();
     return new LeaseAcquireResponse(true, new DefaultLease(leaseId, expireTime), expireTime);
 }
Beispiel #5
0
        TimeSpan ISponsor.Renewal(ILease lease)
        {
            if (lease == null)
            {
                throw new ArgumentNullException("lease");
            }

            return _timespan;
        }
        public CacheLifecycle(ILease lease)
        {
            if (lease == null)
            {
                throw new ArgumentNullException("lease");
            }

            this.cache = new LeasedObjectCache(lease);
        }
        public CacheLifetimeManager(ILease lease)
        {
            if (lease == null)
            {
                throw new ArgumentNullException("lease");
            }

            this.lease = lease;
        }
Beispiel #8
0
        private async Task <DocumentServiceLease> TryGetLeaseAsync(ILease lease)
        {
            Uri      documentUri = this.CreateDocumentUri(lease.Id);
            Document document    = await this.client.TryGetDocumentAsync(
                documentUri,
                this.requestOptionsFactory.CreateRequestOptions(lease))
                                   .ConfigureAwait(false);

            return(document != null?DocumentServiceLease.FromDocument(document) : null);
        }
Beispiel #9
0
        public override object InitializeLifetimeService()
        {
            ILease lease = (ILease)base.InitializeLifetimeService();

            if (lease.CurrentState == LeaseState.Initial)
            {
                lease.InitialLeaseTime = TimeSpan.FromSeconds(30.0);
            }
            return(lease);
        }
Beispiel #10
0
        /// <summary>
        /// Verifies that a lease is registered/unregistered for the lifetime service.
        /// </summary>
        /// <param name="lease">The lease that is checked.</param>
        /// <param name="checkRegistered">if set to <c>true</c> it is checked that it is registered otherwise
        /// it must be unregistered.</param>
        private void VerifyLifetimeServiceRegistered(ILease lease, bool checkRegistered)
        {
            Hashtable sponsorTable = (Hashtable)lease.GetType()
                                     .GetField("sponsorTable", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(lease);
            string message = checkRegistered
                                 ? "Expected lifetime service to be registered."
                                 : "Expected lifetime service to be unregistered.";

            Assert.AreEqual(checkRegistered, sponsorTable.Contains(this.asyncResult), message);
        }
 private void SetupReplaceConflict(IChangeFeedDocumentClient client, ILease updatedLease)
 {
     Mock.Get(client)
     .Setup(c => c.ReplaceDocumentAsync(
                documentUri,
                updatedLease,
                It.Is <RequestOptions>(options => options.AccessCondition.Type == AccessConditionType.IfMatch && options.AccessCondition.Condition == eTag1),
                default(CancellationToken)))
     .ThrowsAsync(DocumentExceptionHelpers.CreatePreconditionFailedException());
 }
Beispiel #12
0
        /// <summary>
        /// Obtains a lifetime service object to control the lifetime policy for this instance.
        /// </summary>
        /// <returns>An object of type ILease used to control the lifetime
        /// policy for this instance.</returns>
        public override object InitializeLifetimeService()
        {
            ILease lease = (ILease)base.InitializeLifetimeService();

            if (lease != null)
            {
                lease.Register(_sponsor);
            }
            return(lease);
        }
Beispiel #13
0
        private RequestOptions CreateIfMatchOptions(ILease lease)
        {
            var ifMatchCondition = new AccessCondition {
                Type = AccessConditionType.IfMatch, Condition = lease.ConcurrencyToken
            };

            return(new RequestOptions {
                AccessCondition = ifMatchCondition
            });
        }
        /// <summary>
        /// Prepare the lease sponsorship settings
        /// </summary>
        /// <returns></returns>
        public override object InitializeLifetimeService()
        {
            ILease LeaseInfo = (ILease)base.InitializeLifetimeService();

            LeaseInfo.InitialLeaseTime   = TimeSpan.FromMinutes(GPEnums.REMOTING_RENEWAL_MINUTES);
            LeaseInfo.RenewOnCallTime    = TimeSpan.FromMinutes(GPEnums.REMOTING_RENEWAL_MINUTES);
            LeaseInfo.SponsorshipTimeout = TimeSpan.FromMinutes(GPEnums.REMOTING_TIMEOUT_MINUTES);

            return(LeaseInfo);
        }
Beispiel #15
0
        override public object InitializeLifetimeService()
        {
            ILease iLease = (ILease)base.InitializeLifetimeService();

            iLease.InitialLeaseTime   = TimeSpan.FromSeconds(20);
            iLease.SponsorshipTimeout = TimeSpan.FromSeconds(20);
            iLease.RenewOnCallTime    = TimeSpan.FromSeconds(20);
            iLease.Register(this);
            return(iLease);
        }
Beispiel #16
0
        public override object InitializeLifetimeService()
        {
            ILease lease = (ILease)base.InitializeLifetimeService();

            lease.InitialLeaseTime   = DefaultLease.InitialLeaseTime;
            lease.RenewOnCallTime    = DefaultLease.RenewOnCallTime;
            lease.SponsorshipTimeout = DefaultLease.SponsorshipTimeout;
            return(lease);
            //return null;
        }
Beispiel #17
0
            /// <summary>
            /// Obtains a lifetime service object to control the lifetime policy for
            /// this instance.
            /// </summary>
            /// <returns>
            /// An object of type <see cref="ILease" /> used to control the lifetime
            /// policy for this instance. This is the current lifetime service object
            /// for this instance if one exists; otherwise, a new lifetime service
            /// object initialized with a lease that will never time out.
            /// </returns>
            public override Object InitializeLifetimeService()
            {
                ILease lease = (ILease)base.InitializeLifetimeService();

                if (lease.CurrentState == LeaseState.Initial)
                {
                    lease.InitialLeaseTime = TimeSpan.Zero;
                }
                return(lease);
            }
Beispiel #18
0
            public override object InitializeLifetimeService()
            {
                // We want an infinite lifetime as far as the
                // remoting infrastructure is concerned
                // (Thanks for Mike Woodring for pointing this out)
                ILease lease = (ILease)base.InitializeLifetimeService();

                lease.InitialLeaseTime = TimeSpan.Zero;
                return(lease);
            }
 /// <summary>Empties the list objects registered with the current <see cref="T:System.Runtime.Remoting.Lifetime.ClientSponsor" />.</summary>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" />
 /// </PermissionSet>
 public void Close()
 {
     foreach (object obj in this.registered_objects.Values)
     {
         MarshalByRefObject marshalByRefObject = (MarshalByRefObject)obj;
         ILease             lease = marshalByRefObject.GetLifetimeService() as ILease;
         lease.Unregister(this);
     }
     this.registered_objects.Clear();
 }
Beispiel #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoteClient"/> class.
 /// </summary>
 public RemoteClient()
 {
     clientchannel = new IpcChannel();
     ChannelServices.RegisterChannel(clientchannel, false);
     RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteObject), "ipc://localhost:15000/RemoteObject.rem");
     RemoteObj = new RemoteObject();
     sponser = new RemoteClientSponser("RemoteClient");
     lease = (ILease)RemoteObj.GetLifetimeService();
     lease.Register(sponser);
 }
        public Sponsor(T obj)
        {
            mObj = obj;

            // Get the lifetime service lease from the MarshalByRefObject,
            // and register ourselves as a sponsor.
            ILease lease = (ILease)obj.GetLifetimeService();

            lease.Register(this);
        }
Beispiel #22
0
        public LeasedObjectCache(ILease lease)
        {
            if (lease == null)
            {
                throw new ArgumentNullException("lease");
            }

            this.lease       = lease;
            this.objectCache = new LifecycleObjectCache();
        }
        public LeasedObjectCache(ILease lease)
        {
            if (lease == null)
            {
                throw new ArgumentNullException("lease");
            }

            this.lease = lease;
            this.objectCache = new MainObjectCache();
        }
        private void RenewLease(IMessage msg)
        {
            ServerIdentity serverIdentity = (ServerIdentity)RemotingServices.GetMessageTargetIdentity(msg);
            ILease         lease          = serverIdentity.Lease;

            if (lease != null && lease.CurrentLeaseTime < lease.RenewOnCallTime)
            {
                lease.Renew(lease.RenewOnCallTime);
            }
        }
Beispiel #25
0
        public Request(Host host, Connection connection)
            : base(string.Empty, string.Empty, null)
        {
            this._host       = host;
            this._connection = connection;
            ILease lease = (ILease)RemotingServices.GetLifetimeService(this._connection);

            this._connectionSponsor = new Sponsor();
            lease.Register(this._connectionSponsor);
        }
Beispiel #26
0
        public override object InitializeLifetimeService()
        {
            ILease lease = (ILease)base.InitializeLifetimeService();
             
            //Set lease properties
            lease.InitialLeaseTime = TimeSpan.FromSeconds(5);

            lease.RenewOnCallTime    = TimeSpan.FromSeconds(3);
            lease.SponsorshipTimeout = TimeSpan.FromSeconds(10);
            return(lease);
        }
Beispiel #27
0
 public TimeSpan Renewal(ILease lease)
 {
     Console.WriteLine("{0}: Sponsor chamado",DateTime.Now);
        if (IsForRenew) {
        Console.WriteLine("{0}: vai renovar 10 seg.",DateTime.Now);
        return TimeSpan.FromSeconds(10);
        } else {
       Console.WriteLine("{0}: Não renova mais.",DateTime.Now);
       return TimeSpan.Zero;
        }
 }
Beispiel #28
0
        public override object InitializeLifetimeService()
        {
            TianTiService.Instance = this;
            ILease lease = (ILease)base.InitializeLifetimeService();

            if (lease.CurrentState == LeaseState.Initial)
            {
                lease.InitialLeaseTime = TimeSpan.FromDays(2000.0);
            }
            return(lease);
        }
        // Note: requestOptions are only used for read and not for update.
        public async Task <ILease> UpdateLeaseAsync(
            ILease cachedLease,
            Uri documentUri,
            RequestOptions requestOptions,
            Func <ILease, ILease> updateLease,
            bool retryOnConflict)
        {
            ILease lease = cachedLease;

            for (int retryCount = retryOnConflict ? RetryCountOnConflict : 0; retryCount >= 0; retryCount--)
            {
                lease = updateLease(lease);
                if (lease == null)
                {
                    return(null);
                }

                lease.Timestamp = DateTime.UtcNow;
                Document leaseDocument = await this.TryReplaceLeaseAsync(lease, documentUri).ConfigureAwait(false);

                if (leaseDocument != null)
                {
                    return(DocumentServiceLease.FromDocument(leaseDocument));
                }

                Logger.InfoFormat("Partition {0} lease update conflict. Reading the current version of lease.", lease.PartitionId);
                Document document;
                try
                {
                    IResourceResponse <Document> response = await this.client.ReadDocumentAsync(
                        documentUri, requestOptions).ConfigureAwait(false);

                    document = response.Resource;
                }
                catch (DocumentClientException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
                {
                    Logger.InfoFormat("Partition {0} lease no longer exists", lease.PartitionId);
                    throw new LeaseLostException(lease);
                }

                DocumentServiceLease serverLease = DocumentServiceLease.FromDocument(document);
                Logger.InfoFormat(
                    "Partition {0} update failed because the lease with token '{1}' was updated by host '{2}' with token '{3}'. Will retry, {4} retry(s) left.",
                    lease.PartitionId,
                    lease.ConcurrencyToken,
                    serverLease.Owner,
                    serverLease.ConcurrencyToken,
                    retryCount);

                lease = serverLease;
            }

            throw new LeaseLostException(lease);
        }
Beispiel #30
0
        ///////////////////////////////////////////////////////////////////////

        public override Object InitializeLifetimeService()
        {
            // We don't ever want this to expire...
            ILease NewLease = ( ILease )base.InitializeLifetimeService();

            if (NewLease.CurrentState == LeaseState.Initial)
            {
                NewLease.InitialLeaseTime = TimeSpan.Zero;
            }
            return(NewLease);
        }
Beispiel #31
0
        public void Unregister(MarshalByRefObject obj)
        {
            if (!registered_objects.ContainsKey(obj))
            {
                return;
            }
            ILease lease = obj.GetLifetimeService() as ILease;

            lease.Unregister(this);
            registered_objects.Remove(obj);
        }
Beispiel #32
0
        public override object InitializeLifetimeService()
        {
            ILease tmp = (ILease)base.InitializeLifetimeService();

            if (tmp.CurrentState == LeaseState.Initial)
            {
                tmp.InitialLeaseTime = TimeSpan.FromSeconds(5);
                tmp.RenewOnCallTime  = TimeSpan.FromSeconds(1);
            }
            return(tmp);
        }
Beispiel #33
0
 /// <summary>
 /// Closes the connection.
 /// </summary>
 private void CloseConnectionInternal()
 {
     if (this._connection != null)
     {
         this._connection.Close();
         ILease lease = (ILease)RemotingServices.GetLifetimeService(this._connection);
         lease.Unregister(this._connectionSponsor);
         this._connection        = null;
         this._connectionSponsor = null;
     }
 }
Beispiel #34
0
        /// <inheritdoc />
        /// <summary>
        /// InitializeLifetimeService is called when the remote object is activated.
        /// This method will determine how long the lifetime for the object will be.
        /// </summary>
        /// <returns>The lease object to control this object's lifetime.</returns>
        public override object InitializeLifetimeService()
        {
            lock (_callbackMonitor)
            {
                VerifyActiveProxy();

                // Each MarshalByRef object has a reference to the service which
                // controls how long the remote object will stay around
                ILease lease = (ILease)base.InitializeLifetimeService();

                // Set how long a lease should be initially. Once a lease expires
                // the remote object will be disconnected and it will be marked as being availiable
                // for garbage collection
                int initialLeaseTime = 1;

                string initialLeaseTimeFromEnvironment = Environment.GetEnvironmentVariable("MSBUILDENGINEPROXYINITIALLEASETIME");

                if (!String.IsNullOrEmpty(initialLeaseTimeFromEnvironment))
                {
                    int leaseTimeFromEnvironment;
                    if (int.TryParse(initialLeaseTimeFromEnvironment, out leaseTimeFromEnvironment) && leaseTimeFromEnvironment > 0)
                    {
                        initialLeaseTime = leaseTimeFromEnvironment;
                    }
                }

                lease.InitialLeaseTime = TimeSpan.FromMinutes(initialLeaseTime);

                // Make a new client sponsor. A client sponsor is a class
                // which will respond to a lease renewal request and will
                // increase the lease time allowing the object to stay in memory
                _sponsor = new ClientSponsor();

                // When a new lease is requested lets make it last 1 minutes longer.
                int leaseExtensionTime = 1;

                string leaseExtensionTimeFromEnvironment = Environment.GetEnvironmentVariable("MSBUILDENGINEPROXYLEASEEXTENSIONTIME");
                if (!String.IsNullOrEmpty(leaseExtensionTimeFromEnvironment))
                {
                    int leaseExtensionFromEnvironment;
                    if (int.TryParse(leaseExtensionTimeFromEnvironment, out leaseExtensionFromEnvironment) && leaseExtensionFromEnvironment > 0)
                    {
                        leaseExtensionTime = leaseExtensionFromEnvironment;
                    }
                }

                _sponsor.RenewalTime = TimeSpan.FromMinutes(leaseExtensionTime);

                // Register the sponsor which will increase lease timeouts when the lease expires
                lease.Register(_sponsor);

                return(lease);
            }
        }
 /// <summary>
 /// Renews the lease on the instance as though it has been called normally.
 /// </summary>
 /// <param name="lease"></param>
 /// <returns></returns>
 TimeSpan ISponsor.Renewal(ILease lease)
 {
     if (IsDisposed)
     {
         return(TimeSpan.Zero);
     }
     else
     {
         return(LifetimeServices.RenewOnCallTime);
     }
 }
        internal static ILease GetLeaseInitial(MarshalByRefObject obj)
        {
            LeaseManager leaseManager = LeaseManager.GetLeaseManager(LifetimeServices.LeaseManagerPollTime);
            ILease       lease        = leaseManager.GetLease(obj);

            if (lease == null)
            {
                lease = LifetimeServices.CreateLease(obj);
            }
            return(lease);
        }
    public override object InitializeLifetimeService()
    {
        //Default lease associated with remote object is retrieved
        ILease objLease = (ILease)base.InitializeLifetimeService();

        //Initial Lease time is updated to 3 minute
        objLease.InitialLeaseTime = TimeSpan.FromMinutes(3);
        //Renewal time is updated to 1 minute
        objLease.RenewOnCallTime = TimeSpan.FromMinutes(1);
        return(objLease);
    }
Beispiel #38
0
        private IDocumentServiceLeaseUpdater CreateLeaseUpdater(ILease expectedCachedLease)
        {
            var       leaseUpdater = Mock.Of <IDocumentServiceLeaseUpdater>();
            MockLease storedLease  = CreateStoredLease(owner);

            Mock.Get(leaseUpdater)
            .Setup(u => u.UpdateLeaseAsync(expectedCachedLease, documentUri, It.IsAny <Func <ILease, ILease> >()))
            .Callback((ILease cachedLease, Uri uri, Func <ILease, ILease> callback) => callback(storedLease))
            .ReturnsAsync(storedLease);
            return(leaseUpdater);
        }
    public override object InitializeLifetimeService()
    {
        ILease lease = (ILease)base.InitializeLifetimeService();

        Debug.Assert(lease.CurrentState == LeaseState.Initial);
        //Set lease properties
        lease.InitialLeaseTime   = TimeSpan.FromMinutes(30);
        lease.RenewOnCallTime    = TimeSpan.FromMinutes(10);
        lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
        return(lease);
    }
Beispiel #40
0
 public TimeSpan Renewal(ILease lease)
 {
     if (!this.disposed)
     {
         return(TimeSpan.FromSeconds(30));
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Beispiel #41
0
 public TimeSpan Renewal(ILease lease)
 {
     if (discovery.GetPeers().Count != 0)
     {
         Debug.WriteLine("! PeerDiscoverySponsor.Renewal() Peers != 0");
         return TimeSpan.FromSeconds(2);
     }
     Debug.WriteLine("! PeerDiscoverySponsor.Renewal() Peers is 0");
     discovery.Dispose();
     discovery = null;
     return TimeSpan.Zero;
 }
        public virtual void Start(StartOptions options)
        {
            var context = new StartContext(options);

            IServiceProvider services = ServicesFactory.Create(context.Options.Settings);

            var engine = services.GetService<IHostingEngine>();

            _runningApp = engine.Start(context);

            _lease = (ILease)RemotingServices.GetLifetimeService(this);
            _lease.Register(this);
        }
Beispiel #43
0
		public void StartTrackingLifetime (ILease lease)
		{
			// Adds this identity to the LeaseManager. 
			// _serverObject must be set.

			if (lease != null && lease.CurrentState == LeaseState.Null) lease = null;

			if (lease != null) 
			{
				if (! (lease is Lease)) lease = new Lease();  // This seems to be MS behavior
				_lease = (Lease) lease;
				LifetimeServices.TrackLifetime (this);
			}
		}
 public LeaseAcquireResponse TryRenewConsumerLease(Tpg tpg, ILease lease, String sessionId)
 {
     Dictionary<string, string> p = new Dictionary<string, string>();
     p.Add(LEASE_ID, Convert.ToString(lease.ID));
     p.Add(SESSION_ID, sessionId);
     p.Add(HOST, Local.IPV4);
     String response = Post("/lease/consumer/renew", p, tpg);
     if (response != null)
     {
         return JSON.DeserializeObject<LeaseAcquireResponse>(response);
     }
     else
     {
         return null;
     }
 }
        public override ILeaseHandle[] Acquire(object[] keys, int millis, WaitCallback expiryCallback)
        {
            lock (_Sync)
            {
                int count = keys.Length;
                var leases = new ILease[count];
                var expired = new int[count];
                var create = new int[count];
                int e = 0; // index for expired[]
                int c = 0; // index for create[]

                ILease lease;
                int threadID = Thread.CurrentThread.ManagedThreadId;

                for (int i = 0; i < keys.Length; i++)
                {
                    object key = keys[i];
                    if (_Leases.TryGetValue(key, out lease))
                    {
                        leases[i] = lease;
                        if (lease.Expired) expired[e++] = i;
                        else if (lease.ThreadID != threadID) return null;
                    }
                    else
                    {
                        create[c++] = i;
                    }
                }

                for (int i = 0; i < e; i++)
                {
                    int k = expired[i];
                    lease = leases[k];
                    Free(lease);
                    if (lease.ExpiryCallback != null) ThreadPool.QueueUserWorkItem(lease.ExpiryCallback, lease);
                    leases[k] = Add(keys[k], millis, expiryCallback);
                }

                for (int i = 0; i < c; i++)
                {
                    int k = create[i];
                    leases[k] = Add(keys[k], millis, expiryCallback);
                }
                return leases;
            }
        }
Beispiel #46
0
        public TimeSpan Renewal(ILease lease)
        {
            do
            {
                try
                {
                    Console.WriteLine("{0}: MainSponsor.Renewal()", _myRegSponsor.GetId());
                    return _listSponsors[0].Renewal(lease);
                }
                catch (Exception)
                {
                    Console.WriteLine("##### {0}: Client Disconnected", _myRegSponsor.GetId());
                    _listSponsors.RemoveAt(0);

                    if (_listSponsors.Count == 0)
                        _myRegSponsor.Dispose();
                }

            } while (_listSponsors.Count > 0);

            return TimeSpan.FromSeconds(0);
        }
 public TimeSpan Renewal(ILease lease)
 {
     Predicate<KeyValuePair<ILease, WeakReference>> match = null;
     OneWayList<KeyValuePair<ILease, WeakReference>> list;
     WeakReference reference = null;
     lock ((list = this.LeaseObjectList))
     {
         foreach (KeyValuePair<ILease, WeakReference> pair in this.LeaseObjectList)
         {
             if (object.ReferenceEquals(pair.Key, lease))
             {
                 reference = pair.Value;
                 goto Label_0090;
             }
         }
     }
 Label_0090:
     if (reference != null)
     {
         if (reference.IsAlive && (reference.Target != null))
         {
             lease.Renew(this.RenewalTime);
             return this.RenewalTime;
         }
         lock ((list = this.LeaseObjectList))
         {
             if (match == null)
             {
                 match = delegate (KeyValuePair<ILease, WeakReference> x) {
                     return object.ReferenceEquals(x.Key, lease) || !x.Value.IsAlive;
                 };
             }
             this.LeaseObjectList.RemoveAll(match);
         }
     }
     return TimeSpan.Zero;
 }
	// Request renewal of a lease.
	public TimeSpan Renewal(ILease lease)
			{
				return renewalTime;
			}
Beispiel #49
0
 public TimeSpan Renewal(ILease lease)
 {
     Console.WriteLine("{0}: Renewing lease for more {1}", DateTime.Now, m_renewLeaseTime);
     return TimeSpan.FromSeconds(m_renewLeaseTime);
 }
Beispiel #50
0
 // In theory: I execute, therefore I am.
 // If GC collects this class then sponsorship will expire
 public TimeSpan Renewal(ILease lease)
 {
     return TimeSpan.FromMinutes(2);
 }
 public TimeSpan Renewal(ILease leaseInfo)
 {
     Console.WriteLine("{0}: SingletonClientSponsor.Renewal()", _name);
     return TimeSpan.FromSeconds(4);
 }
	public virtual System.TimeSpan Renewal(ILease lease) {}
Beispiel #53
0
 public TimeSpan Renewal(ILease lease)
 {
     if (!m_closed)
         return lease.InitialLeaseTime;
     return TimeSpan.FromTicks(0);
 }
Beispiel #54
0
 public TimeSpan Renewal(ILease lease)
 {
     TimeSpan tsLease = TimeSpan.FromMinutes(5);
     lease.Renew(tsLease);
     return tsLease;
 }
 public LeaseAcquireResponse TryRenewConsumerLease(Tpg tpg, ILease lease, String sessionId)
 {
     return new LeaseAcquireResponse(false, null, new DateTime().CurrentTimeMillis() + 10 * 1000L);
 }
 /// <summary>
 /// Verifies that a lease is registered/unregistered for the lifetime service.
 /// </summary>
 /// <param name="lease">The lease that is checked.</param>
 /// <param name="checkRegistered">if set to <c>true</c> it is checked that it is registered otherwise
 /// it must be unregistered.</param>
 private void VerifyLifetimeServiceRegistered(ILease lease, bool checkRegistered)
 {
     Hashtable sponsorTable = (Hashtable)lease.GetType()
         .GetField("sponsorTable", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(lease);
     string message = checkRegistered
                          ? "Expected lifetime service to be registered."
                          : "Expected lifetime service to be unregistered.";
     Assert.AreEqual(checkRegistered, sponsorTable.Contains(this.asyncResult), message);
 }
 public TimeSpan Renewal(ILease lease)
 {
     return new TimeSpan(0, 1, 0, 0);
 }
Beispiel #58
0
			//[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
			public TimeSpan Renewal(ILease lease)
			{
				(new Logger()).WriteDebug4("lease:renewal:" + (null == _cAtom ? "no" : "yes:" + _cAtom.GetHashCode()));
				if(null != _cAtom)
					return TimeSpan.FromSeconds(20);
				return TimeSpan.Zero;
			}
Beispiel #59
0
 public TimeSpan Renewal(ILease lease) 
 {
     BCLDebug.Trace("REMOTE", "ClientSponsor Renewal "+m_renewalTime); 
     return m_renewalTime; 
 }
	public TimeSpan Renewal (ILease lease)
	{
		return TimeSpan.FromSeconds (7);
	}