Created
January 30, 2014 15:39
-
-
Save harrybiscuit/8711258 to your computer and use it in GitHub Desktop.
A simple workflow application monitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Concurrent; | |
public interface IWorkflowApplicationMonitor | |
{ | |
bool IsRunning(Guid workflowDefinitionId); | |
void SetStatusToRunning(Guid workflowDefinitionId); | |
void SetStatusToNotRunning(Guid workflowDefinitionId); | |
} | |
public class WorkflowApplicationMonitor : IWorkflowApplicationMonitor | |
{ | |
public const bool IS_RUNNING_FLAG = true; | |
public const bool IS_NOT_RUNNING_FLAG = false; | |
private static readonly ConcurrentDictionary<Guid, bool> _runningWorkflowDefinitions = | |
new ConcurrentDictionary<Guid, bool>(); | |
public bool IsRunning(Guid workflowDefinitionId) | |
{ | |
bool isRunning; | |
var keyFound = _runningWorkflowDefinitions.TryGetValue(workflowDefinitionId, out isRunning); | |
return keyFound ? isRunning : IS_NOT_RUNNING_FLAG; | |
} | |
public void SetStatusToRunning(Guid workflowDefinitionId) | |
{ | |
_runningWorkflowDefinitions.AddOrUpdate(workflowDefinitionId, IS_RUNNING_FLAG, | |
(definitionId, isRunning) => IS_RUNNING_FLAG); | |
} | |
public void SetStatusToNotRunning(Guid workflowDefinitionId) | |
{ | |
_runningWorkflowDefinitions.AddOrUpdate(workflowDefinitionId.Value, IS_NOT_RUNNING_FLAG, | |
(definitionId, isRunning) => IS_NOT_RUNNING_FLAG); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment