Пример #1
0
        /// <summary>
        /// Create a new ContextRuntime.
        /// </summary>
        /// <param name="serviceInjector"></param>
        /// <param name="contextConfiguration">the Configuration for this context.</param>
        /// <param name="parentContext"></param>
        public ContextRuntime(
                IInjector serviceInjector,
                IConfiguration contextConfiguration,
                Optional<ContextRuntime> parentContext)
        {
            ContextConfiguration config = contextConfiguration as ContextConfiguration;
            if (config == null)
            {
                var e = new ArgumentException("contextConfiguration is not of type ContextConfiguration");
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
            }
            _contextLifeCycle = new ContextLifeCycle(config.Id);
            _serviceInjector = serviceInjector;
            _parentContext = parentContext;
            try
            {
                _contextInjector = serviceInjector.ForkInjector();
            }
            catch (Exception e)
            {
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);

                Optional<string> parentId = ParentContext.IsPresent() ?
                    Optional<string>.Of(ParentContext.Value.Id) :
                    Optional<string>.Empty();
                ContextClientCodeException ex = new ContextClientCodeException(ContextClientCodeException.GetId(contextConfiguration), parentId, "Unable to spawn context", e);
                
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
            }
            // Trigger the context start events on contextInjector.
            _contextLifeCycle.Start();
        }
Пример #2
0
        /// <summary>
        /// Create a new ContextRuntime.
        /// </summary>
        /// <param name="serviceInjector"></param>
        /// <param name="contextConfiguration">the Configuration for this context.</param>
        /// <param name="parentContext"></param>
        public ContextRuntime(
            IInjector serviceInjector,
            IConfiguration contextConfiguration,
            Optional <ContextRuntime> parentContext)
        {
            ContextConfiguration config = contextConfiguration as ContextConfiguration;

            if (config == null)
            {
                var e = new ArgumentException("contextConfiguration is not of type ContextConfiguration");
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
            }
            _contextLifeCycle = new ContextLifeCycle(config.Id);
            _serviceInjector  = serviceInjector;
            _parentContext    = parentContext;
            try
            {
                _contextInjector = serviceInjector.ForkInjector();
            }
            catch (Exception e)
            {
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);

                Optional <string> parentId = ParentContext.IsPresent() ?
                                             Optional <string> .Of(ParentContext.Value.Id) :
                                             Optional <string> .Empty();

                ContextClientCodeException ex = new ContextClientCodeException(ContextClientCodeException.GetId(contextConfiguration), parentId, "Unable to spawn context", e);

                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
            }
            // Trigger the context start events on contextInjector.
            _contextLifeCycle.Start();
        }
Пример #3
0
        /// <summary>
        /// Create a new ContextRuntime.
        /// </summary>
        /// <param name="serviceInjector"></param>
        /// <param name="contextConfiguration">the Configuration for this context.</param>
        /// <param name="parentContext"></param>
        public ContextRuntime(
            IInjector serviceInjector,
            IConfiguration contextConfiguration,
            Optional <ContextRuntime> parentContext)
        {
            _serviceInjector = serviceInjector;

            // Note that for Service objects and handlers, we are not merging them into a separate
            // class (e.g. ServiceContainer) due to the inability to allow service stacking if an instance
            // of such a class were to be materialized. i.e. if a ServiceContainer object were initialized
            // and a child ServiceConfiguration is submitted, when the child service injector tries to
            // get the relevant handlers and services set, it will get the same set of handlers as
            // previously instantiated by the parent injector, and thus will not allow the stacking
            // of ServiceConfigurations.
            _injectedServices = serviceInjector.GetNamedInstance <ServicesSet, ISet <object> >();

            _serviceContextStartHandlers =
                serviceInjector.GetNamedInstance <ContextConfigurationOptions.StartHandlers, ISet <IObserver <IContextStart> > >();

            _serviceContextStopHandlers =
                serviceInjector.GetNamedInstance <ContextConfigurationOptions.StopHandlers, ISet <IObserver <IContextStop> > >();

            _serviceTaskStartHandlers =
                serviceInjector.GetNamedInstance <TaskConfigurationOptions.StartHandlers, ISet <IObserver <ITaskStart> > >();

            _serviceTaskStopHandlers =
                serviceInjector.GetNamedInstance <TaskConfigurationOptions.StopHandlers, ISet <IObserver <ITaskStop> > >();

            _contextInjector  = serviceInjector.ForkInjector(contextConfiguration);
            _contextLifeCycle = _contextInjector.GetInstance <ContextLifeCycle>();
            _parentContext    = parentContext;
            _contextLifeCycle.Start();
        }
Пример #4
0
 /// <summary>
 /// Create a new ContextRuntime.
 /// </summary>
 /// <param name="serviceInjector"></param>
 /// <param name="contextConfiguration">the Configuration for this context.</param>
 /// <param name="parentContext"></param>
 public ContextRuntime(
         IInjector serviceInjector,
         IConfiguration contextConfiguration,
         Optional<ContextRuntime> parentContext)
 {
     _serviceInjector = serviceInjector;
     _contextInjector = serviceInjector.ForkInjector(contextConfiguration);
     _contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
     _parentContext = parentContext;
     _contextLifeCycle.Start();
 }
Пример #5
0
 /// <summary>
 /// Create a new ContextRuntime.
 /// </summary>
 /// <param name="serviceInjector"></param>
 /// <param name="contextConfiguration">the Configuration for this context.</param>
 /// <param name="parentContext"></param>
 public ContextRuntime(
         IInjector serviceInjector,
         IConfiguration contextConfiguration,
         Optional<ContextRuntime> parentContext)
 {
     _serviceInjector = serviceInjector;
     _injectedServices = Optional<ISet<object>>.Of(serviceInjector.GetNamedInstance<ServicesSet, ISet<object>>());
     _contextInjector = serviceInjector.ForkInjector(contextConfiguration);
     _contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
     _parentContext = parentContext;
     _contextLifeCycle.Start();
 }
Пример #6
0
        /// <summary>
        /// Create a new ContextRuntime.
        /// </summary>
        /// <param name="serviceInjector"></param>
        /// <param name="contextConfiguration">the Configuration for this context.</param>
        /// <param name="parentContext"></param>
        public ContextRuntime(
            IInjector serviceInjector,
            IConfiguration contextConfiguration,
            Optional <ContextRuntime> parentContext)
        {
            _serviceInjector  = serviceInjector;
            _injectedServices = Optional <ISet <object> > .Of(serviceInjector.GetNamedInstance <ServicesSet, ISet <object> >());

            _contextInjector  = serviceInjector.ForkInjector(contextConfiguration);
            _contextLifeCycle = _contextInjector.GetInstance <ContextLifeCycle>();
            _parentContext    = parentContext;
            _contextLifeCycle.Start();
        }
Пример #7
0
        /// <summary>
        /// Create a new ContextRuntime.
        /// </summary>
        /// <param name="serviceInjector"></param>
        /// <param name="contextConfiguration">the Configuration for this context.</param>
        /// <param name="parentContext"></param>
        public ContextRuntime(
                IInjector serviceInjector,
                IConfiguration contextConfiguration,
                Optional<ContextRuntime> parentContext)
        {
            _serviceInjector = serviceInjector;

            // Note that for Service objects and handlers, we are not merging them into a separate
            // class (e.g. ServiceContainer) due to the inability to allow service stacking if an instance 
            // of such a class were to be materialized. i.e. if a ServiceContainer object were initialized
            // and a child ServiceConfiguration is submitted, when the child service injector tries to
            // get the relevant handlers and services set, it will get the same set of handlers as
            // previously instantiated by the parent injector, and thus will not allow the stacking
            // of ServiceConfigurations.
            _injectedServices = serviceInjector.GetNamedInstance<ServicesSet, ISet<object>>();

            _serviceContextStartHandlers = 
                serviceInjector.GetNamedInstance<ContextConfigurationOptions.StartHandlers, ISet<IObserver<IContextStart>>>();

            _serviceContextStopHandlers = 
                serviceInjector.GetNamedInstance<ContextConfigurationOptions.StopHandlers, ISet<IObserver<IContextStop>>>();

            _serviceTaskStartHandlers = 
                serviceInjector.GetNamedInstance<TaskConfigurationOptions.StartHandlers, ISet<IObserver<ITaskStart>>>();

            _serviceTaskStopHandlers = 
                serviceInjector.GetNamedInstance<TaskConfigurationOptions.StopHandlers, ISet<IObserver<ITaskStop>>>();

            _contextInjector = serviceInjector.ForkInjector(contextConfiguration);
            _contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
            _parentContext = parentContext;

            try
            {
                _contextLifeCycle.Start();
            }
            catch (Exception e)
            {
                const string message = "Encountered Exception in ContextStartHandler.";
                if (ParentContext.IsPresent())
                {
                    throw new ContextStartHandlerException(
                        Id, Optional<string>.Of(ParentContext.Value.Id), message, e);
                }
                
                throw new ContextStartHandlerException(Id, Optional<string>.Empty(), message, e);
            }
        }
Пример #8
0
        public ContextRuntime(
            string id,
            IInjector serviceInjector,
            IConfiguration contextConfiguration)
        {
            // This should only be used at the root context to support backward compatibility.
            LOGGER.Log(Level.Info, "Instantiating root context");
            _contextLifeCycle = new ContextLifeCycle(id);
            _serviceInjector = serviceInjector;
            _parentContext = Optional<ContextRuntime>.Empty();
            try
            {
                _contextInjector = serviceInjector.ForkInjector();
            }
            catch (Exception e)
            {
                Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);

                Optional<string> parentId = ParentContext.IsPresent() ?
                    Optional<string>.Of(ParentContext.Value.Id) :
                    Optional<string>.Empty();
                ContextClientCodeException ex = new ContextClientCodeException(ContextClientCodeException.GetId(contextConfiguration), parentId, "Unable to spawn context", e);

                Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
            }

            // Trigger the context start events on contextInjector.
            _contextLifeCycle.Start();
        }