Esempio n. 1
0
        /// <summary>
        /// Close this context. If there is a child context, this recursively closes it before closing this context. If
        /// there is an Task currently running, that will be closed.
        /// </summary>
        public void Dispose()
        {
            lock (_contextLifeCycle)
            {
                _contextState = ContextStatusProto.State.DONE;
                if (_task.IsPresent())
                {
                    LOGGER.Log(Level.Warning, "Shutting down an task because the underlying context is being closed.");
                    _task.Value.Close(null);
                }
                if (_childContext.IsPresent())
                {
                    LOGGER.Log(Level.Warning, "Closing a context because its parent context is being closed.");
                    _childContext.Value.Dispose();
                }
                _contextLifeCycle.Close();
                if (_parentContext.IsPresent())
                {
                    ParentContext.Value.ResetChildContext();
                }

                foreach (var injectedService in _injectedServices.OfType <IDisposable>())
                {
                    injectedService.Dispose();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Close this context. If there is a child context, this recursively closes it before closing this context. If
        /// there is an Task currently running, that will be closed.
        /// </summary>
        public void Dispose()
        {
            lock (_contextLifeCycle)
            {
                _contextState = ContextStatusProto.State.DONE;
                if (_task.IsPresent())
                {
                    LOGGER.Log(Level.Warning, "Shutting down an task because the underlying context is being closed.");
                    _task.Value.Close(null);
                }
                if (_childContext.IsPresent())
                {
                    LOGGER.Log(Level.Warning, "Closing a context because its parent context is being closed.");
                    _childContext.Value.Dispose();
                }

                try
                {
                    _contextLifeCycle.Close();
                }
                catch (Exception e)
                {
                    const string message = "Encountered Exception in ContextStopHandler.";
                    if (ParentContext.IsPresent())
                    {
                        throw new ContextStopHandlerException(
                                  Id, Optional <string> .Of(ParentContext.Value.Id), message, e);
                    }

                    throw new ContextStopHandlerException(Id, Optional <string> .Empty(), message, e);
                }
                finally
                {
                    if (_parentContext.IsPresent())
                    {
                        ParentContext.Value.ResetChildContext();
                    }

                    foreach (var injectedService in _injectedServices.OfType <IDisposable>())
                    {
                        injectedService.Dispose();
                    }
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Close this context. If there is a child context, this recursively closes it before closing this context. If
 /// there is an Task currently running, that will be closed.
 /// </summary>
 public void Dispose()
 {
     lock (_contextLifeCycle)
     {
         _contextState = ContextStatusProto.State.DONE;
         if (_task.IsPresent())
         {
             LOGGER.Log(Level.Warning, "Shutting down an task because the underlying context is being closed.");
             _task.Value.Close(null);
         }
         if (_childContext.IsPresent())
         {
             LOGGER.Log(Level.Warning, "Closing a context because its parent context is being closed.");
             _childContext.Value.Dispose();
         }
         _contextLifeCycle.Close();
         if (_parentContext.IsPresent())
         {
             ParentContext.Value.ResetChildContext();
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Close this context. If there is a child context, this recursively closes it before closing this context. If
        /// there is an Task currently running, that will be closed.
        /// </summary>
        public void Dispose()
        {
            lock (_contextLifeCycle)
            {
                _contextState = ContextStatusProto.State.DONE;
                if (_task.IsPresent())
                {
                    LOGGER.Log(Level.Warning, "Shutting down an task because the underlying context is being closed.");
                    _task.Value.Close(null);
                }
                if (_childContext.IsPresent())
                {
                    LOGGER.Log(Level.Warning, "Closing a context because its parent context is being closed.");
                    _childContext.Value.Dispose();
                }

                try
                {
                    _contextLifeCycle.Close();
                }
                catch (Exception e)
                {
                    const string message = "Encountered Exception in ContextStopHandler.";
                    if (ParentContext.IsPresent())
                    {
                        throw new ContextStopHandlerException(
                            Id, Optional<string>.Of(ParentContext.Value.Id), message, e);
                    }

                    throw new ContextStopHandlerException(Id, Optional<string>.Empty(), message, e);
                }
                finally
                {
                    if (_parentContext.IsPresent())
                    {
                        ParentContext.Value.ResetChildContext();
                    }

                    foreach (var injectedService in _injectedServices.OfType<IDisposable>())
                    {
                        injectedService.Dispose();
                    }
                }
            }
        }