static List <ActiveRunner> InitializeRunners(RunDescriptor runDescriptor, IList <EndpointBehaviour> behaviorDescriptors)
        {
            var runners      = new List <ActiveRunner>();
            var routingTable = CreateRoutingTable(runDescriptor, behaviorDescriptors);

            foreach (var behaviorDescriptor in behaviorDescriptors)
            {
                var endpointName = GetEndpointNameForRun(runDescriptor, behaviorDescriptor);
                var runner       = PrepareRunner(endpointName, behaviorDescriptor);
                var result       = runner.Instance.Initialize(runDescriptor, behaviorDescriptor, routingTable, endpointName);

                // Extend the lease to the timeout value specified.
                ILease serverLease = (ILease)RemotingServices.GetLifetimeService(runner.Instance);

                // Add the execution time + additional time for the endpoints to be able to stop gracefully
                var totalLifeTime = runDescriptor.TestExecutionTimeout.Add(TimeSpan.FromMinutes(2));
                serverLease.Renew(totalLifeTime);

                if (result.Failed)
                {
                    throw new ScenarioException(string.Format("Endpoint {0} failed to initialize - {1}", runner.Instance.Name(), result.ExceptionMessage));
                }

                runners.Add(runner);
            }

            return(runners);
        }
Exemple #2
0
            public static Action Prepare <T>(ILogger logger, IServiceProvider provider, ILease lease, T message)
            {
                var publisher = provider.GetRequiredService <IPublisher <T> >();

                logger.LogTrace($"Publisher used {publisher}");
                var publishing = publisher.PreparePublish(message);

                return(() =>
                {
                    var tokenSource = new CancellationTokenSource();
                    var publish = publishing(tokenSource.Token).ToObservable();
                    var releaser = Observable.Interval(lease.LeaseInterval).Select(_ => Unit.Default);
                    releaser.TakeUntil(publish).Subscribe(_ =>
                    {
                        if (!lease.Renew())
                        {
                            tokenSource.Cancel();
                            tokenSource.Dispose();
                            lease.Dispose();
                        }
                    });
                    publish.Subscribe(_ =>
                    {
                        lease.Dispose();
                        logger.LogTrace("Published {message}", message);
                    }, ex => logger.LogError(0, ex, "Publishing {message}", message));
                });
            }
Exemple #3
0
        public TimeSpan Renewal(ILease lease)
        {
            TimeSpan tsLease = TimeSpan.FromMinutes(5);

            lease.Renew(tsLease);
            return(tsLease);
        }
Exemple #4
0
        public void RenewLease()
        {
            ILease lease = (ILease)RemotingServices.GetLifetimeService(this);

            Debug.Assert(lease.CurrentState == LeaseState.Active);
            lease.Renew(TimeSpan.FromMinutes(30));
        }
Exemple #5
0
        public void UpdateLease(TimeSpan time)
        {
            ILease lease = (ILease)RemotingServices.GetLifetimeService(this as MarshalByRefObject);

            if (lease != null)
            {
                lease.Renew(time);
            }
        }
        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);
            }
        }
Exemple #7
0
        void RenewLease(IMessage msg)
        {
                        #if !DISABLE_REMOTING
            ServerIdentity identity = (ServerIdentity)RemotingServices.GetMessageTargetIdentity(msg);

            ILease lease = identity.Lease;
            if (lease != null && lease.CurrentLeaseTime < lease.RenewOnCallTime)
            {
                lease.Renew(lease.RenewOnCallTime);
            }
                        #endif
        }
Exemple #8
0
        public void DoLengthyOperation()
        {
            ILease itfLeaseInfo = (ILease)this.GetLifetimeService();

            if (itfLeaseInfo.CurrentLeaseTime.TotalMinutes < 1.0)
            {
                itfLeaseInfo.Renew(TimeSpan.FromMinutes(10));
            }

            // Do long running task...
            System.Threading.Thread.Sleep(10000);
        }
Exemple #9
0
        private void btnRenew_Click(object sender, System.EventArgs e)
        {
            mLease = (ILease)RemotingServices.GetLifetimeService(objCount);

            try
            {
                mLease.Renew(System.TimeSpan.FromSeconds(10));
                MessageBox.Show(this, "Lease renewed for 10 seconds");
            }
            catch
            {
                MessageBox.Show(this, "Lease has expired");
            }
        }
Exemple #10
0
        static void Main(string[] args)
        {
            // Use *.config file...
            RemotingConfiguration.Configure("CAOCarProviderClientLease.exe.config");

            // ... or use hard coded values.
            //RemotingConfiguration.RegisterActivatedClientType(typeof(CAOCarGeneralAsmLease.CarProvider),
            //	"http://localhost:032469");

            // Make the car provider.
            JamesBondCar[] cars =
            {
                new JamesBondCar("One",   100, false, false),
                new JamesBondCar("Two",   100, false, false),
                new JamesBondCar("Three", 100, false, false)
            };

            // Now trigger the custom ctor.
            CarProvider cp = new CarProvider(cars);

            // Adjust the lease of this type!
            ILease itfLeaseInfo = (ILease)RemotingServices.GetLifetimeService(cp);

            if (itfLeaseInfo.CurrentLeaseTime.TotalMinutes < 10.0)
            {
                itfLeaseInfo.Renew(TimeSpan.FromMinutes(1000));
            }

            // Get first JBC.
            JamesBondCar qCar = cp.GetJBCByIndex(0);

            // Get all JBCs.
            List <JamesBondCar> allJBCs = cp.GetAllAutos();

            // Use first car.
            UseCar(qCar);

            // Use all cars in ArrayList
            foreach (JamesBondCar j in allJBCs)
            {
                UseCar(j);
            }

            Console.WriteLine("Client started!  Hit enter to end");
            Console.ReadLine();
        }
Exemple #11
0
        /// <summary>
        /// 采用延迟租约(Lease)的方式来延长远程对象生命周期
        /// </summary>
        /// <param name="counter"></param>
        static void ExtendLifetimeViaLease(object counter)
        {
            CounterService counterService = counter as CounterService;

            ILease lease = RemotingServices.GetLifetimeService(counterService) as ILease;

            while (true)
            {
                if (lease == null)
                {
                    Console.WriteLine("Can not retrieve the lease!");
                    break;
                }

                lease.Renew(TimeSpan.FromSeconds(_leaseRenewalFrequency));
                Thread.Sleep(_leaseRenewalFrequency * 950);
            }
        }
 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;
 }
Exemple #13
0
 public TimeSpan Renew(TimeSpan renewalTime)
 {
     Console.WriteLine("The lease has been renewed for {0} milliseconds...", renewalTime.Milliseconds);
     return(baseLease.Renew(renewalTime));
 }
        /// <summary>
        /// Method to extend the lifetime of a DistributedSearchable object.
        /// </summary>
        public void Renew()
        {
            ILease oLease = (ILease)this.GetLifetimeService();

            oLease.Renew(DistributedSearchable.GetLeaseTimeSpan());
        }
Exemple #15
0
 public TimeSpan Renewal(ILease lease)
 {
     TimeSpan tsLease = TimeSpan.FromMinutes(5);
     lease.Renew(tsLease);
     return tsLease;
 }
Exemple #16
0
        public static void FonctionSecuriteParTimer(object state)
        {
            if (m_bDejaEnSecurite)
            {
                return;
            }
            try
            {
                m_bDejaEnSecurite = true;
                foreach (C2iSponsor sponsor in m_gl_listeSponsors.ToArray())
                {
                    string strLibelle = sponsor.Label; // Pour debuguer uniquement
                    try
                    {
                        sponsor.m_suspectGarbage.CreateGeneration();
                        if (sponsor.m_listeObjetsSponsorises != null)
                        {
                            List <object> lstObjets = new List <object>(sponsor.m_listeObjetsSponsorises.ToArray());
                            foreach (object obj in sponsor.m_dicObjetsSponsor.Values)
                            {
                                lstObjets.Add(obj);
                            }
                            int nIndex = 0;
                            sponsor.m_suspectGarbage.RenouvelleBailParAppel();
                            foreach (object obj in lstObjets)
                            {
                                I2iMarshalObject obj2i = obj as I2iMarshalObject;
                                CProxy2iMarshal  proxy = null;
                                if (obj2i == null)
                                {
                                    proxy = obj as CProxy2iMarshal;
                                    if (proxy != null)
                                    {
                                        obj2i = proxy.Objet;
                                    }
                                }
                                if (proxy == null)
                                {
                                    nIndex++;
                                }
                                if (obj2i != null)
                                {
                                    try
                                    {
                                        Type tp = obj2i.GetType();

                                        ILease lease = (ILease)RemotingServices.GetLifetimeService((MarshalByRefObject)obj2i);
                                        if (lease != null)
                                        {
                                            lease.Renew(TimeSpan.FromMinutes(2));
                                        }

                                        obj2i.RenouvelleBailParAppel();
                                        nIndex++;
                                    }
                                    catch
                                    {
                                        sponsor.m_suspectGarbage.RegisterSuspect(obj2i);

                                        if (proxy != null)
                                        {
                                            sponsor.m_dicObjetsSponsor.Remove(proxy.UniqueId);
                                        }
                                        else
                                        {
                                            sponsor.m_listeObjetsSponsorises.RemoveAt(nIndex);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch {}
                }
            }
            catch
            {}
            finally
            {
                m_bDejaEnSecurite = false;
            }
        }