Exemplo n.º 1
0
        /// <summary>IoC constructor.</summary>
        public Runtime(RuntimeProviders runtimeProviders, ICloudConfigurationSettings settings, ICloudRuntimeObserver observer = null)
        {
            _runtimeProviders = runtimeProviders;
            _runtimeFinalizer = runtimeProviders.RuntimeFinalizer;
            _log = runtimeProviders.Log;
            _observer = observer;

            _settings = settings;
        }
Exemplo n.º 2
0
 /// <summary>IoC constructor.</summary>
 public RuntimeProviders(
     IBlobStorageProvider blobStorage,
     IQueueStorageProvider queueStorage,
     ITableStorageProvider tableStorage,
     IRuntimeFinalizer runtimeFinalizer,
     Storage.Shared.Logging.ILog log)
 {
     BlobStorage = blobStorage;
     QueueStorage = queueStorage;
     TableStorage = tableStorage;
     RuntimeFinalizer = runtimeFinalizer;
     Log = log;
 }
		/// <summary>IoC constructor.</summary>
		public CloudInfrastructureProviders(
			IBlobStorageProvider blobStorage, 
			IQueueStorageProvider queueStorage,
			ITableStorageProvider tableStorage,
			ILog log,
			IProvisioningProvider provisioning,
			IRuntimeFinalizer runtimeFinalizer)
		{
			BlobStorage = blobStorage;
			QueueStorage = queueStorage;
			TableStorage = tableStorage;
			Log = log;
			Provisioning = provisioning;
			RuntimeFinalizer = runtimeFinalizer;
		}
 /// <summary>IoC constructor.</summary>
 public CloudStorageProviders(
     IBlobStorageProvider blobStorage,
     IQueueStorageProvider queueStorage,
     ITableStorageProvider tableStorage,
     IBlobStorageProvider neutralBlobStorage,
     IQueueStorageProvider neutralQueueStorage,
     ITableStorageProvider neutralTableStorage,
     IBlobStorageProvider rawBlobStorage,
     IRuntimeFinalizer runtimeFinalizer = null)
 {
     BlobStorage = blobStorage;
     QueueStorage = queueStorage;
     TableStorage = tableStorage;
     NeutralBlobStorage = neutralBlobStorage;
     NeutralQueueStorage = neutralQueueStorage;
     NeutralTableStorage = neutralTableStorage;
     RawBlobStorage = rawBlobStorage;
     RuntimeFinalizer = runtimeFinalizer;
 }
Exemplo n.º 5
0
        /// <summary>Called once by the service fabric. Call is not supposed to return
        /// until stop is requested, or an uncaught exception is thrown.</summary>
        public void Execute()
        {
            _log.DebugFormat("Runtime: started on worker {0}.", CloudEnvironment.PartitionKey);

            // hook on the current thread to force shut down
            _executeThread = Thread.CurrentThread;

            IContainer applicationContainer = null;
            try
            {
                List<CloudService> services;

                // note: we need to keep the container alive until the finally block
                // because the finalizer (of the container) is called there.
                applicationContainer = LoadAndBuildApplication(out services);

                _applicationFinalizer = applicationContainer.ResolveOptional<IRuntimeFinalizer>();
                _scheduler = new Scheduler(services, service => service.Start(), _observer);

                foreach (var action in _scheduler.Schedule())
                {
                    if (_isStopRequested)
                    {
                        break;
                    }

                    action();
                }
            }
            catch (ThreadInterruptedException)
            {
                _log.WarnFormat("Runtime: execution was interrupted on worker {0} in service {1}. The Runtime will be restarted.",
                    CloudEnvironment.PartitionKey, GetNameOfServiceInExecution());
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();

                _log.DebugFormat("Runtime: execution was aborted on worker {0} in service {1}. The Runtime is stopping.",
                    CloudEnvironment.PartitionKey, GetNameOfServiceInExecution());
            }
            catch (TimeoutException)
            {
                _log.WarnFormat("Runtime: execution timed out on worker {0} in service {1}. The Runtime will be restarted.",
                    CloudEnvironment.PartitionKey, GetNameOfServiceInExecution());
            }
            catch (TriggerRestartException)
            {
                // Supposed to be handled by the runtime host (i.e. SingleRuntimeHost)
                throw;
            }
            catch (Exception ex)
            {
                _log.ErrorFormat(ex, "Runtime: An unhandled {0} exception occurred on worker {1} in service {2}. The Runtime will be restarted.",
                    ex.GetType().Name, CloudEnvironment.PartitionKey, GetNameOfServiceInExecution());
            }
            finally
            {
                _log.DebugFormat("Runtime: stopping on worker {0}.", CloudEnvironment.PartitionKey);

                if (_runtimeFinalizer != null)
                {
                    _runtimeFinalizer.FinalizeRuntime();
                }

                if (_applicationFinalizer != null)
                {
                    _applicationFinalizer.FinalizeRuntime();
                }

                if (applicationContainer != null)
                {
                    applicationContainer.Dispose();
                }

                _log.DebugFormat("Runtime: stopped on worker {0}.", CloudEnvironment.PartitionKey);
            }
        }
 /// <summary>
 /// Optionally provide a runtime finalizer.
 /// </summary>
 public CloudStorageBuilder WithRuntimeFinalizer(IRuntimeFinalizer runtimeFinalizer)
 {
     RuntimeFinalizer = runtimeFinalizer;
     return this;
 }