Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void start() throws LifecycleException
            public override void Start()
            {
                if (CurrentStatus == LifecycleStatus.None)
                {
                    Init();
                }
                if (CurrentStatus == LifecycleStatus.Stopped)
                {
                    CurrentStatus = outerInstance.changedStatus(Instance, CurrentStatus, LifecycleStatus.Starting);
                    try
                    {
                        Instance.start();
                        CurrentStatus = outerInstance.changedStatus(Instance, CurrentStatus, LifecycleStatus.Started);
                    }
                    catch (Exception e)
                    {
                        CurrentStatus = outerInstance.changedStatus(Instance, CurrentStatus, LifecycleStatus.Stopped);
                        try
                        {
                            Instance.stop();
                        }
                        catch (Exception se)
                        {
                            LifecycleException lifecycleException = new LifecycleException("Exception during graceful " + "attempt to stop partially started component. Please use non suppressed" + " exception to see original component failure.", se);
                            e.addSuppressed(lifecycleException);
                        }
                        if (e is LifecycleException)
                        {
                            throw ( LifecycleException )e;
                        }
                        throw new LifecycleException(Instance, LifecycleStatus.Stopped, LifecycleStatus.Started, e);
                    }
                }
            }
Esempio n. 2
0
        /// <summary>
        /// Stop all registered instances, transitioning from STARTED to STOPPED.
        /// <para>
        /// If any instance fails to stop, the rest of the instances will still be stopped,
        /// so that the overall status is STOPPED.
        /// </para>
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public synchronized void stop() throws LifecycleException
        public override void Stop()
        {
            lock (this)
            {
                if (_status == LifecycleStatus.Started)
                {
                    _status = ChangedStatus(this, _status, LifecycleStatus.Stopping);
                    LifecycleException ex = StopInstances(_instances);
                    _status = ChangedStatus(this, _status, LifecycleStatus.Stopped);

                    if (ex != null)
                    {
                        throw ex;
                    }
                }
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
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;
                    }
                }
            }
        }