Пример #1
0
        public void OnCellDefinitionChanged(CellDefinition newCellDefinition, SolutionHead newDeployment)
        {
            var oldCellDefinition     = _cellDefinition;
            var newAssemblies         = newCellDefinition.Assemblies;
            var newEntryPointTypeName = newCellDefinition.EntryPointTypeName;

            _cellDefinition = newCellDefinition;
            _deployment     = newDeployment;

            var entryPoint = _entryPoint;

            if (entryPoint == null)
            {
                return;
            }

            if (!oldCellDefinition.Assemblies.Equals(newAssemblies) ||
                !StringComparer.Ordinal.Equals(oldCellDefinition.EntryPointTypeName, newEntryPointTypeName))
            {
                // cancel will stop the cell and unload the AppDomain, but then automatically
                // start again with the new assemblies and entry point
                entryPoint.Cancel();
                return;
            }

            entryPoint.AppplyChangedSettings(newCellDefinition.SettingsXml);
        }
Пример #2
0
        public void RunSync(CancellationToken cancellationToken)
        {
            _hostContext.Observer.TryNotify(() => new HostStartedEvent(_hostContext.Identity));

            try
            {
                _currentDeployment     = null;
                _currentSolution       = null;
                _currentDeploymentEtag = null;

                _autoLoadHeadDeploymentTimer.Change(0, _autoLoadHeadDeploymentIntervalMs);
                _watchdogTimer.Change(_watchdogIntervalMs, _watchdogIntervalMs);

                foreach (var command in _commandQueue.GetConsumingEnumerable(cancellationToken))
                {
                    Do((dynamic)command, cancellationToken);
                }
            }
            finally
            {
                _autoLoadHeadDeploymentTimer.Change(Timeout.Infinite, _autoLoadHeadDeploymentIntervalMs);
                _watchdogTimer.Change(Timeout.Infinite, _watchdogIntervalMs);
                _hostContext.Observer.TryNotify(() => new HostStoppedEvent(_hostContext.Identity));
            }
        }
 internal ApplicationEnvironment(IHostContext hostContext, CellLifeIdentity cellIdentity, SolutionHead solution, AssembliesHead assemblies, Action <IHostCommand> sendCommand)
 {
     _hostContext  = hostContext;
     _cellIdentity = cellIdentity;
     _solution     = solution;
     _assemblies   = assemblies;
     _sendCommand  = sendCommand;
 }
 internal ApplicationEnvironment(IHostContext hostContext, CellLifeIdentity cellIdentity, SolutionHead solution, AssembliesHead assemblies, Action<IHostCommand> sendCommand)
 {
     _hostContext = hostContext;
     _cellIdentity = cellIdentity;
     _solution = solution;
     _assemblies = assemblies;
     _sendCommand = sendCommand;
 }
Пример #5
0
 private Cell(IHostContext hostContext, Action <IHostCommand> sendCommand, CellDefinition cellDefinition, SolutionHead deployment, string solutionName, CancellationToken cancellationToken)
 {
     _hostContext             = hostContext;
     _sendCommand             = sendCommand;
     _solutionName            = solutionName;
     _cellName                = cellDefinition.CellName;
     _cellDefinition          = cellDefinition;
     _deployment              = deployment;
     _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
 }
Пример #6
0
 private Cell(IHostContext hostContext, Action<IHostCommand> sendCommand, CellDefinition cellDefinition, SolutionHead deployment, string solutionName, CancellationToken cancellationToken)
 {
     _hostContext = hostContext;
     _sendCommand = sendCommand;
     _solutionName = solutionName;
     _cellName = cellDefinition.CellName;
     _cellDefinition = cellDefinition;
     _deployment = deployment;
     _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
 }
Пример #7
0
 public static Cell Run(
     IHostContext hostContext,
     Action<IHostCommand> sendCommand,
     CellDefinition cellDefinition,
     SolutionHead deployment,
     string solutionName,
     CancellationToken cancellationToken)
 {
     var process = new Cell(hostContext, sendCommand, cellDefinition, deployment, solutionName, cancellationToken);
     process.Run();
     return process;
 }
Пример #8
0
        public static Cell Run(
            IHostContext hostContext,
            Action <IHostCommand> sendCommand,
            CellDefinition cellDefinition,
            SolutionHead deployment,
            string solutionName,
            CancellationToken cancellationToken)
        {
            var process = new Cell(hostContext, sendCommand, cellDefinition, deployment, solutionName, cancellationToken);

            process.Run();
            return(process);
        }
 public CellLifeIdentity GetNewCellLifeIdentity(string solutionName, string cellName, SolutionHead deployment)
 {
     return new CellLifeIdentity(_identity, solutionName, cellName, Guid.NewGuid().ToString("N"));
 }
 public NewUnrelatedSolutionDetectedEvent(HostLifeIdentity host, SolutionHead deployment, SolutionDefinition solution)
 {
     Host       = host;
     Deployment = deployment;
     Solution   = solution;
 }
Пример #11
0
        void OnDeploymentChanged(SolutionHead newDeployment, SolutionDefinition newSolution, CancellationToken cancellationToken)
        {
            // 0. ANALYZE CELL LAYOUT CHANGES

            var removed   = new Dictionary <string, Cell>(_cells);
            var added     = new List <CellDefinition>();
            var remaining = new List <CellDefinition>();

            Dictionary <string, CellDefinition> old;

            if (_currentSolution == null || _currentSolution.SolutionName != newSolution.SolutionName)
            {
                // we do not reuse cells in completely unrelated solutions (i.e. solution name changed)
                _hostContext.Observer.TryNotify(() => new NewUnrelatedSolutionDetectedEvent(_hostContext.Identity, newDeployment, newSolution));
                old = new Dictionary <string, CellDefinition>();
                added.AddRange(newSolution.Cells);
            }
            else
            {
                // keep remaining cells (only touch cells that actually change in some way)
                _hostContext.Observer.TryNotify(() => new NewDeploymentOfSolutionDetectedEvent(_hostContext.Identity, newDeployment, newSolution));
                old = _currentSolution.Cells.ToDictionary(cellDefinition => cellDefinition.CellName);
                foreach (var newCellDefinition in newSolution.Cells)
                {
                    if (old.ContainsKey(newCellDefinition.CellName))
                    {
                        removed.Remove(newCellDefinition.CellName);
                        remaining.Add(newCellDefinition);
                    }
                    else
                    {
                        added.Add(newCellDefinition);
                    }
                }
            }

            // 1. UPDATE

            _currentSolution   = newSolution;
            _currentDeployment = newDeployment;

            // 2. REMOVE CELLS NO LONGER PRESENT

            foreach (var cell in removed)
            {
                _cells.Remove(cell.Key);
                cell.Value.Cancel();
            }

            // 3. UPDATE CELLS STILL PRESENT

            foreach (var newCellDefinition in remaining)
            {
                var oldCellDefinition = old[newCellDefinition.CellName];
                if (!newCellDefinition.Equals(oldCellDefinition))
                {
                    _cells[newCellDefinition.CellName].OnCellDefinitionChanged(newCellDefinition, newDeployment);
                }
            }

            // 4. ADD NEW CELLS

            foreach (var cellDefinition in added)
            {
                var cellName = cellDefinition.CellName;
                _cells.Add(cellName, Cell.Run(_hostContext, _commandQueue.Add, cellDefinition, newDeployment, newSolution.SolutionName, cancellationToken));
            }
        }
Пример #12
0
        public void RunSync(CancellationToken cancellationToken)
        {
            _hostContext.Observer.TryNotify(() => new HostStartedEvent(_hostContext.Identity));

            try
            {
                _currentDeployment = null;
                _currentSolution = null;
                _currentDeploymentEtag = null;

                _autoLoadHeadDeploymentTimer.Change(0, _autoLoadHeadDeploymentIntervalMs);
                _watchdogTimer.Change(_watchdogIntervalMs, _watchdogIntervalMs);

                foreach (var command in _commandQueue.GetConsumingEnumerable(cancellationToken))
                {
                    Do((dynamic)command, cancellationToken);
                }
            }
            finally
            {
                _autoLoadHeadDeploymentTimer.Change(Timeout.Infinite, _autoLoadHeadDeploymentIntervalMs);
                _watchdogTimer.Change(Timeout.Infinite, _watchdogIntervalMs);
                _hostContext.Observer.TryNotify(() => new HostStoppedEvent(_hostContext.Identity));
            }
        }
 public void LoadDeployment(SolutionHead deployment)
 {
     _sendCommand(new LoadDeploymentCommand(deployment));
 }
Пример #14
0
        public void OnCellDefinitionChanged(CellDefinition newCellDefinition, SolutionHead newDeployment)
        {
            var oldCellDefinition = _cellDefinition;
            var newAssemblies = newCellDefinition.Assemblies;
            var newEntryPointTypeName = newCellDefinition.EntryPointTypeName;

            _cellDefinition = newCellDefinition;
            _deployment = newDeployment;

            var entryPoint = _entryPoint;
            if (entryPoint == null)
            {
                return;
            }

            if (!oldCellDefinition.Assemblies.Equals(newAssemblies)
                || !StringComparer.Ordinal.Equals(oldCellDefinition.EntryPointTypeName, newEntryPointTypeName))
            {
                // cancel will stop the cell and unload the AppDomain, but then automatically
                // start again with the new assemblies and entry point
                entryPoint.Cancel();
                return;
            }

            entryPoint.AppplyChangedSettings(newCellDefinition.SettingsXml);
        }
Пример #15
0
 public LoadDeploymentCommand(SolutionHead deployment)
 {
     Deployment = deployment;
 }
 public void LoadDeployment(SolutionHead deployment)
 {
     _sendCommand(new LoadDeploymentCommand(deployment));
 }
 public CellLifeIdentity GetNewCellLifeIdentity(string solutionName, string cellName, SolutionHead deployment)
 {
     // TODO: Replace GUID with global blob counter
     return new CellLifeIdentity(_identity, solutionName, cellName, Guid.NewGuid().ToString("N"));
 }
 public NewDeploymentOfSolutionDetectedEvent(HostLifeIdentity host, SolutionHead deployment, SolutionDefinition solution)
 {
     Host = host;
     Deployment = deployment;
     Solution = solution;
 }
Пример #19
0
        void OnDeploymentChanged(SolutionHead newDeployment, SolutionDefinition newSolution, CancellationToken cancellationToken)
        {
            // 0. ANALYZE CELL LAYOUT CHANGES

            var removed = new Dictionary<string, Cell>(_cells);
            var added = new List<CellDefinition>();
            var remaining = new List<CellDefinition>();

            Dictionary<string, CellDefinition> old;
            if (_currentSolution == null || _currentSolution.SolutionName != newSolution.SolutionName)
            {
                // we do not reuse cells in completely unrelated solutions (i.e. solution name changed)
                _hostContext.Observer.TryNotify(() => new NewUnrelatedSolutionDetectedEvent(_hostContext.Identity, newDeployment, newSolution));
                old = new Dictionary<string, CellDefinition>();
                added.AddRange(newSolution.Cells);
            }
            else
            {
                // keep remaining cells (only touch cells that actually change in some way)
                _hostContext.Observer.TryNotify(() => new NewDeploymentOfSolutionDetectedEvent(_hostContext.Identity, newDeployment, newSolution));
                old = _currentSolution.Cells.ToDictionary(cellDefinition => cellDefinition.CellName);
                foreach (var newCellDefinition in newSolution.Cells)
                {
                    if (old.ContainsKey(newCellDefinition.CellName))
                    {
                        removed.Remove(newCellDefinition.CellName);
                        remaining.Add(newCellDefinition);
                    }
                    else
                    {
                        added.Add(newCellDefinition);
                    }
                }
            }

            // 1. UPDATE

            _currentSolution = newSolution;
            _currentDeployment = newDeployment;

            // 2. REMOVE CELLS NO LONGER PRESENT

            foreach (var cell in removed)
            {
                _cells.Remove(cell.Key);
                cell.Value.Cancel();
            }

            // 3. UPDATE CELLS STILL PRESENT

            foreach (var newCellDefinition in remaining)
            {
                var oldCellDefinition = old[newCellDefinition.CellName];
                if (!newCellDefinition.Equals(oldCellDefinition))
                {
                    _cells[newCellDefinition.CellName].OnCellDefinitionChanged(newCellDefinition, newDeployment);
                }
            }

            // 4. ADD NEW CELLS

            foreach (var cellDefinition in added)
            {
                var cellName = cellDefinition.CellName;
                _cells.Add(cellName, Cell.Run(_hostContext, _commandQueue.Add, cellDefinition, newDeployment, newSolution.SolutionName, cancellationToken));
            }
        }
 public LoadDeploymentCommand(SolutionHead deployment)
 {
     Deployment = deployment;
 }