Beispiel #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);
                    }
                }
            }
Beispiel #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void shutdown() throws LifecycleException
            public override void Shutdown()
            {
                if (CurrentStatus == LifecycleStatus.Started)
                {
                    Stop();
                }

                if (CurrentStatus == LifecycleStatus.Stopped)
                {
                    CurrentStatus = outerInstance.changedStatus(Instance, CurrentStatus, LifecycleStatus.ShuttingDown);
                    try
                    {
                        Instance.shutdown();
                    }
                    catch (LifecycleException e)
                    {
                        throw e;
                    }
                    catch (Exception e)
                    {
                        throw new LifecycleException(Instance, LifecycleStatus.Stopped, LifecycleStatus.ShuttingDown, e);
                    }
                    finally
                    {
                        CurrentStatus = outerInstance.changedStatus(Instance, CurrentStatus, LifecycleStatus.Shutdown);
                    }
                }
            }
Beispiel #3
0
        /// <summary>
        /// Initialize all registered instances, transitioning from status NONE to STOPPED.
        /// <para>
        /// If transition fails, then it goes to STOPPED and then SHUTDOWN, so it cannot be restarted again.
        /// </para>
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public synchronized void init() throws LifecycleException
        public override void Init()
        {
            lock (this)
            {
                if (_status == LifecycleStatus.None)
                {
                    _status = ChangedStatus(this, _status, LifecycleStatus.Initializing);
                    foreach (LifecycleInstance instance in _instances)
                    {
                        try
                        {
                            instance.Init();
                        }
                        catch (LifecycleException e)
                        {
                            _status = ChangedStatus(this, _status, LifecycleStatus.Stopped);

                            try
                            {
                                Shutdown();
                            }
                            catch (LifecycleException shutdownErr)
                            {
                                e.addSuppressed(shutdownErr);
                            }

                            throw e;
                        }
                    }
                    _status = ChangedStatus(this, _status, LifecycleStatus.Stopped);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Start all registered instances, transitioning from STOPPED to STARTED.
        /// <para>
        /// If it was previously not initialized, it will be initialized first.
        /// </para>
        /// <para>
        /// If any instance fails to start, the already started instances will be stopped, so
        /// that the overall status is STOPPED.
        ///
        /// </para>
        /// </summary>
        /// <exception cref="LifecycleException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public synchronized void start() throws LifecycleException
        public override void Start()
        {
            lock (this)
            {
                Init();

                if (_status == LifecycleStatus.Stopped)
                {
                    _status = ChangedStatus(this, _status, LifecycleStatus.Starting);
                    foreach (LifecycleInstance instance in _instances)
                    {
                        try
                        {
                            instance.Start();
                        }
                        catch (LifecycleException e)
                        {
                            // TODO perhaps reconsider chaining of exceptions coming from LifeSupports?
                            _status = ChangedStatus(this, _status, LifecycleStatus.Started);
                            try
                            {
                                Stop();
                            }
                            catch (LifecycleException stopErr)
                            {
                                e.addSuppressed(stopErr);
                            }

                            throw e;
                        }
                    }
                    _status = ChangedStatus(this, _status, LifecycleStatus.Started);
                }
            }
        }
Beispiel #5
0
        private LifecycleStatus ChangedStatus(Lifecycle instance, LifecycleStatus oldStatus, LifecycleStatus newStatus)
        {
            foreach (LifecycleListener listener in _listeners)
            {
                listener.NotifyStatusChanged(instance, oldStatus, newStatus);
            }

            return(newStatus);
        }
Beispiel #6
0
        private static string HumanReadableMessage(object instance, LifecycleStatus from, LifecycleStatus to, Exception cause)
        {
            string        instanceStr = instance.ToString();
            StringBuilder message     = new StringBuilder();

            switch (to)
            {
            case Org.Neo4j.Kernel.Lifecycle.LifecycleStatus.Stopped:
                if (from == LifecycleStatus.None)
                {
                    message.Append("Component '").Append(instanceStr).Append("' failed to initialize");
                }
                else if (from == LifecycleStatus.Started)
                {
                    message.Append("Component '").Append(instanceStr).Append("' failed to stop");
                }
                break;

            case Org.Neo4j.Kernel.Lifecycle.LifecycleStatus.Started:
                if (from == LifecycleStatus.Stopped)
                {
                    message.Append("Component '").Append(instanceStr).Append("' was successfully initialized, but failed to start");
                }
                break;

            case Org.Neo4j.Kernel.Lifecycle.LifecycleStatus.Shutdown:
                message.Append("Component '").Append(instanceStr).Append("' failed to shut down");
                break;

            default:
                break;
            }
            if (message.Length == 0)
            {
                message.Append("Component '").Append(instanceStr).Append("' failed to transition from ").Append(from.name().ToLower()).Append(" to ").Append(to.name().ToLower());
            }
            message.Append('.');
            if (cause != null)
            {
                Exception root = RootCause(cause);
                message.Append(" Please see the attached cause exception \"").Append(root.Message).Append('"');
                if (root.InnerException != null)
                {
                    message.Append(" (root cause cycle detected)");
                }
                message.Append('.');
            }

            return(message.ToString());
        }
Beispiel #7
0
        private Resource CreateResourceWithEndpointLifecycleStatus(LifecycleStatus endpointStatus)
        {
            var firstEndpoint = new DistributionEndpointBuilder()
                                .GenerateSampleData()
                                .WithDistributionEndpointLifecycleStatus(endpointStatus)
                                .Build();

            var resource = new ResourceBuilder()
                           .GenerateSampleData()
                           .WithMainDistributionEndpoint(firstEndpoint)
                           .Build();

            return(resource);
        }
Beispiel #8
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;
                    }
                }
            }
        }
Beispiel #9
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;
                    }
                }
            }
        }
 public static bool ContainsLifecycleStatus(this IDictionary <string, List <dynamic> > property, LifecycleStatus status)
 {
     return(ContainsSingleValue(property, Graph.Metadata.Constants.Resource.LifecycleStatus, status.GetDescription()));
 }
 private LifecycleException ExceptionFor(LifecycleStatus from, LifecycleStatus to, Exception cause)
 {
     return(new LifecycleException(new ObjectAnonymousInnerClass(this)
                                   , from, to, cause));
 }
 private LifecycleException ExceptionFor(LifecycleStatus from, LifecycleStatus to)
 {
     return(ExceptionFor(from, to, null));
 }
Beispiel #13
0
 public PidUriTemplateBuilder WithPidUriTemplateLifecycleStatus(LifecycleStatus status)
 {
     CreateOrOverwriteProperty(COLID.Graph.Metadata.Constants.PidUriTemplate.HasLifecycleStatus, status.GetDescription());
     return(this);
 }
Beispiel #14
0
 public LifecycleState()
 {
     status = LifecycleStatus.Offscreen;
 }
Beispiel #15
0
 public DistributionEndpointBuilder WithDistributionEndpointLifecycleStatus(LifecycleStatus status)
 {
     CreateOrOverwriteProperty(Resource.DistributionEndpoints.DistributionEndpointLifecycleStatus, EnumExtension.GetDescription(status));
     return(this);
 }
 public ResourceBuilder WithLifecycleStatus(LifecycleStatus status)
 {
     CreateOrOverwriteProperty(hasLifecycleStatus, status.GetDescription());
     return(this);
 }
Beispiel #17
0
 public LifecycleException(object instance, LifecycleStatus from, LifecycleStatus to, Exception cause) : base(HumanReadableMessage(instance, from, to, cause), cause)
 {
 }
 public PidUriTemplateBuilder WithPidUriTemplateLifecycleStatus(LifecycleStatus status)
 {
     CreateOrOverwriteProperty(RegistrationService.Common.Constants.PidUriTemplate.HasLifecycleStatus, status.GetDescription());
     return(this);
 }