Ejemplo n.º 1
0
 /// <summary>
 /// Add a context to the stack.
 /// </summary>
 /// <param name="addContextProto"></param>
 private void AddContext(AddContextProto addContextProto)
 {
     lock (_contextStack)
     {
         ContextRuntime currentTopContext = _contextStack.Peek();
         if (!currentTopContext.Id.Equals(addContextProto.parent_context_id, StringComparison.OrdinalIgnoreCase))
         {
             var e = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Trying to instantiate a child context on context with id '{0}' while the current top context id is {1}",
                                                                 addContextProto.parent_context_id,
                                                                 currentTopContext.Id));
             Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
         }
         string contextConfigString = addContextProto.context_configuration;
         ContextConfiguration contextConfiguration = new ContextConfiguration(contextConfigString);
         ContextRuntime       newTopContext;
         if (addContextProto.service_configuration != null)
         {
             ServiceConfiguration serviceConfiguration = new ServiceConfiguration(addContextProto.service_configuration);
             newTopContext = currentTopContext.SpawnChildContext(contextConfiguration, serviceConfiguration.TangConfig);
         }
         else
         {
             newTopContext = currentTopContext.SpawnChildContext(contextConfiguration);
         }
         _contextStack.Push(newTopContext);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a context to the stack.
        /// </summary>
        /// <param name="addContextProto"></param>
        private void AddContext(AddContextProto addContextProto)
        {
            lock (_contextLock)
            {
                var currentTopContext = _topContext;
                if (!currentTopContext.Id.Equals(addContextProto.parent_context_id, StringComparison.OrdinalIgnoreCase))
                {
                    var e = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Trying to instantiate a child context on context with id '{0}' while the current top context id is {1}",
                                                                        addContextProto.parent_context_id,
                                                                        currentTopContext.Id));
                    Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
                }

                var contextConfiguration = _serializer.FromString(addContextProto.context_configuration);

                ContextRuntime newTopContext;
                if (!string.IsNullOrWhiteSpace(addContextProto.service_configuration))
                {
                    var serviceConfiguration = _serializer.FromString(addContextProto.service_configuration);
                    newTopContext = currentTopContext.SpawnChildContext(contextConfiguration, serviceConfiguration);
                }
                else
                {
                    newTopContext = currentTopContext.SpawnChildContext(contextConfiguration);
                }
                _topContext = newTopContext;
            }
        }