예제 #1
0
 public virtual T setLast <T>(T instance) where T : Lifecycle
 {
     lock (this)
     {
         if (_last != null)
         {
             throw new System.InvalidOperationException(format("Lifecycle supports only one last component. Already defined component: %s, new component: %s", _last, instance));
         }
         _last = AddNewComponent(instance);
         return(instance);
     }
 }
예제 #2
0
        private LifecycleInstance AddNewComponent <T>(T instance) where T : Lifecycle
        {
            Objects.requireNonNull(instance);
            ValidateNotAlreadyPartOfLifecycle(instance);
            LifecycleInstance         newInstance = new LifecycleInstance(this, instance);
            IList <LifecycleInstance> tmp         = new List <LifecycleInstance>(_instances);
            int position = _last != null ? tmp.Count - 1 : tmp.Count;

            tmp.Insert(position, newInstance);
            _instances = tmp;
            BringToState(newInstance);
            return(newInstance);
        }
예제 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void bringToState(LifecycleInstance instance) throws LifecycleException
        private void BringToState(LifecycleInstance instance)
        {
            switch (_status)
            {
            case Org.Neo4j.Kernel.Lifecycle.LifecycleStatus.Started:
                instance.Start();
                break;

            case Org.Neo4j.Kernel.Lifecycle.LifecycleStatus.Stopped:
                instance.Init();
                break;

            default:
                break;
            }
        }
예제 #4
0
 public virtual bool Remove(Lifecycle instance)
 {
     lock (this)
     {
         for (int i = 0; i < _instances.Count; i++)
         {
             if (_instances[i].isInstance(instance))
             {
                 IList <LifecycleInstance> tmp = new List <LifecycleInstance>(_instances);
                 LifecycleInstance         lifecycleInstance = tmp.RemoveAt(i);
                 lifecycleInstance.Shutdown();
                 _instances = tmp;
                 return(true);
             }
         }
         return(false);
     }
 }
예제 #5
0
        private LifecycleException StopInstances(IList <LifecycleInstance> instances)
        {
            LifecycleException ex = null;

            for (int i = instances.Count - 1; i >= 0; i--)
            {
                LifecycleInstance lifecycleInstance = instances[i];
                try
                {
                    lifecycleInstance.Stop();
                }
                catch (LifecycleException e)
                {
                    ex = Exceptions.chain(ex, e);
                }
            }
            return(ex);
        }
예제 #6
0
        /// <summary>
        /// Shutdown all registered instances, transitioning from either STARTED or STOPPED to SHUTDOWN.
        /// <para>
        /// If any instance fails to shutdown, the rest of the instances will still be shut down,
        /// so that the overall status is SHUTDOWN.
        /// </para>
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public synchronized void shutdown() throws LifecycleException
        public override void Shutdown()
        {
            lock (this)
            {
                LifecycleException ex = null;
                try
                {
                    Stop();
                }
                catch (LifecycleException e)
                {
                    ex = e;
                }

                if (_status == LifecycleStatus.Stopped)
                {
                    _status = ChangedStatus(this, _status, LifecycleStatus.ShuttingDown);
                    for (int i = _instances.Count - 1; i >= 0; i--)
                    {
                        LifecycleInstance lifecycleInstance = _instances[i];
                        try
                        {
                            lifecycleInstance.Shutdown();
                        }
                        catch (LifecycleException e)
                        {
                            ex = Exceptions.chain(ex, e);
                        }
                    }

                    _status = ChangedStatus(this, _status, LifecycleStatus.Shutdown);

                    if (ex != null)
                    {
                        throw ex;
                    }
                }
            }
        }