/// <summary> /// Opens the component. /// </summary> /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param> /// <returns></returns> public async Task OpenAsync(string correlationId) { if (_references != null) { throw new InvalidStateException(correlationId, "ALREADY_OPENED", "Container was already opened"); } //if (_config == null) // throw new InvalidStateException(correlationId, "NO_CONFIG", "Container was not configured"); try { _logger.Trace(correlationId, "Starting container."); // Create references with configured components _references = new ContainerReferences(); InitReferences(_references); _references.PutFromConfig(_config); SetReferences(_references); // Get custom description if available var infoDescriptor = new Descriptor("*", "context-info", "*", "*", "*"); _info = _references.GetOneRequired <ContextInfo>(infoDescriptor); await _references.OpenAsync(correlationId); // Get reference to logger _logger = new CompositeLogger(_references); _logger.Info(correlationId, "Container {0} started.", _info.Name); } catch (Exception ex) { _logger.Error(correlationId, ex, "Failed to start container"); await CloseAsync(correlationId); throw; } }
public async Task StartAsync(string correlationId, CancellationToken token) { if (Config == null) { throw new InvalidStateException(correlationId, "NO_CONFIG", "Container was not configured"); } try { Logger.Trace(correlationId, "Starting container."); // Create references with configured components InitReferences(References); References.PutFromConfig(Config); // Reference and open components var components = References.GetAll(); Referencer.SetReferences(References, components); await Opener.OpenAsync(correlationId, References.GetAll()); // Get reference to logger Logger = new CompositeLogger(References); // Get reference to container info var infoDescriptor = new Descriptor("*", "container-info", "*", "*", "*"); Info = (ContainerInfo)References.GetOneRequired(infoDescriptor); Logger.Info(correlationId, "Container {0} started.", Info.Name); } catch (Exception ex) { References = null; Logger.Error(correlationId, ex, "Failed to start container"); throw; } }
/// <summary> /// Closes component and frees used resources. /// </summary> /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param> /// <returns></returns> public async Task CloseAsync(string correlationId) { if (_references == null) { return; } try { _logger.Trace(correlationId, "Stopping {0} container", _info.Name); // Close and dereference components await _references.CloseAsync(correlationId); _references = null; _logger.Info(correlationId, "Container {0} stopped", _info.Name); } catch (Exception ex) { _logger.Error(correlationId, ex, "Failed to stop container"); throw; } }
/// <summary> /// Initializes a new instance of the <see cref="MicroserviceProcessContainer"/> class. /// </summary> public MicroserviceProcessContainer() { _references = new ContainerReferences(); }
/// <summary> /// Awake this instance. /// </summary> protected virtual void Awake() { m_containerReferences = this.GetComponent <ContainerReferences>(); }