Class Daemon
Represents a lightweight daemon(background in-app process) which can be controlled by Start/SignalStop-like commands. This class serves a a base for various implementations (e.g. LogDaemon) including their composites. This class is thread-safe
Inheritance
Implements
Inherited Members
Namespace: Azos.Apps
Assembly: Azos.dll
Syntax
public abstract class Daemon : ApplicationComponent, IDisposable, IDaemon, IDaemonView, IApplicationComponent, INamed, IConfigurable, ILocalizedTimeProvider
Constructors
Daemon(IApplicationComponent)
Declaration
protected Daemon(IApplicationComponent director)
Parameters
Type | Name | Description |
---|---|---|
IApplicationComponent | director |
Daemon(IApplication)
Declaration
protected Daemon(IApplication application)
Parameters
Type | Name | Description |
---|---|---|
IApplication | application |
Fields
CONFIG_NAME_ATTR
Declaration
public const string CONFIG_NAME_ATTR = "name"
Field Value
Type | Description |
---|---|
System.String |
Properties
ApplicationDontAutoStartDaemon
Checks whether the class should not be auto-started by the application on boot. Default implementation checks whether it is decorated with ApplicationDontAutoStartDaemonAttribute
Declaration
public virtual bool ApplicationDontAutoStartDaemon { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
LocalizedTime
Returns current time localized per TimeLocation
Declaration
public DateTime LocalizedTime { get; }
Property Value
Type | Description |
---|---|
System.DateTime |
Name
Provides textual name for the daemon
Declaration
public string Name { get; protected set; }
Property Value
Type | Description |
---|---|
System.String |
Running
Returns true when service is active or about to become active. Check in service implementation loops/threads/tasks
Declaration
public bool Running { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Status
Current service status
Declaration
public DaemonStatus Status { get; }
Property Value
Type | Description |
---|---|
DaemonStatus |
TimeLocation
Returns time location of this LocalizedTimeProvider implementation
Declaration
public TimeLocation TimeLocation { get; set; }
Property Value
Type | Description |
---|---|
TimeLocation |
Methods
AbortStart()
Allows to abort unsuccessful DoStart() overridden implementation. This method must be called from within DoStart()
Declaration
protected void AbortStart()
AcceptManagerVisit(Object, DateTime)
Accepts a visit of a manager entity - this call is useful for periodic updates of service status, i.e. when service does not have a thread of its own it can be periodically managed by some other service through this method. The default implementation of DoAcceptManagerVisit(object, DateTime) does nothing
Declaration
public void AcceptManagerVisit(object manager, DateTime managerNow)
Parameters
Type | Name | Description |
---|---|---|
System.Object | manager | |
System.DateTime | managerNow |
CheckDaemonActive()
Checks for service activity and throws exception if service is not in ControlStatus.Active state
Declaration
protected void CheckDaemonActive()
CheckDaemonActiveOrStarting()
Checks for service activity and throws exception if service is not in ControlStatus.Active state
Declaration
protected void CheckDaemonActiveOrStarting()
CheckDaemonInactive()
Checks for service inactivity and throws exception if service is running (started, starting or stopping)
Declaration
protected void CheckDaemonInactive()
CheckForCompleteStop()
Non-blocking call that returns true when the service instance has completely stopped after SignalStop()
Declaration
public bool CheckForCompleteStop()
Returns
Type | Description |
---|---|
System.Boolean |
Configure(IConfigSectionNode)
Configures service from configuration node (and possibly it's sub-nodes)
Declaration
public void Configure(IConfigSectionNode fromNode)
Parameters
Type | Name | Description |
---|---|---|
IConfigSectionNode | fromNode |
Destructor()
Declaration
protected override void Destructor()
Overrides
DoAcceptManagerVisit(Object, DateTime)
Accepts a visit from external manager. Base implementation does nothing. Override in services that need external management calls to update their state periodically, i.e. when they don't have a thread on their own
Declaration
protected virtual void DoAcceptManagerVisit(object manager, DateTime managerNow)
Parameters
Type | Name | Description |
---|---|---|
System.Object | manager | |
System.DateTime | managerNow |
DoCheckForCompleteStop()
Provides implementation for checking whether the service has completely stopped
Declaration
protected virtual bool DoCheckForCompleteStop()
Returns
Type | Description |
---|---|
System.Boolean |
DoConfigure(IConfigSectionNode)
Provides implementation that configures service from configuration node (and possibly it's sub-nodes)
Declaration
protected virtual void DoConfigure(IConfigSectionNode node)
Parameters
Type | Name | Description |
---|---|---|
IConfigSectionNode | node |
DoSignalStop()
Provides implementation that signals service to stop. This is expected not to block
Declaration
protected virtual void DoSignalStop()
DoStart()
Provides implementation that starts the service
Declaration
protected virtual void DoStart()
DoWaitForCompleteStop()
Provides implementation for a blocking call that returns only after a complete service stop
Declaration
protected virtual void DoWaitForCompleteStop()
LocalizedTimeToUniversalTime(DateTime)
Converts localized time to UTC time as of TimeLocation property
Declaration
public DateTime LocalizedTimeToUniversalTime(DateTime local)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | local |
Returns
Type | Description |
---|---|
System.DateTime |
SetOnInactiveDaemon<T>(T)
Checks that daemon is not active and returns the passed variable throwing otherwise. Used for one line property setters
Declaration
protected T SetOnInactiveDaemon<T>(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
SignalStop()
Non-blocking call that initiates the stopping of the service
Declaration
public void SignalStop()
Start()
Blocking call that starts the service instance
Declaration
public void Start()
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |
Overrides
UniversalTimeToLocalizedTime(DateTime)
Converts universal time to local time as of TimeLocation property
Declaration
public DateTime UniversalTimeToLocalizedTime(DateTime utc)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | utc |
Returns
Type | Description |
---|---|
System.DateTime |
WaitForCompleteStop()
Blocks execution of current thread until this service has completely stopped. This call must be performed by only 1 thread otherwise exception is thrown
Declaration
public void WaitForCompleteStop()