Class Service
Represents a lightweight service that can be controlled by Start/SignalStop-like commands. This class serves a a base for various implementations (i.e. LogService) including their composites. This class is thread-safe
Inheritance
Implements
Inherited Members
Namespace: NFX.ServiceModel
Assembly: NFX.dll
Syntax
public abstract class Service : ApplicationComponent, IApplicationComponent, IDisposable, IService, INamed, IConfigurable, ILocalizedTimeProvider
Constructors
Service()
Declaration
protected Service()
Service(Object)
Declaration
protected Service(object director)
Parameters
Type | Name | Description |
---|---|---|
System.Object | director |
Fields
CONFIG_NAME_ATTR
Declaration
public const string CONFIG_NAME_ATTR = "name"
Field Value
Type | Description |
---|---|
System.String |
Properties
ApplicationDontAutoStartService
Checks whether the class is decorated with ApplicationDontAutoStartServiceAttribute
Declaration
public bool ApplicationDontAutoStartService { 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 service
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 ControlStatus Status { get; }
Property Value
Type | Description |
---|---|
ControlStatus |
TimeLocation
Returns time location of this LocalizedTimeProvider implementation
Declaration
public TimeLocation TimeLocation { get; set; }
Property Value
Type | Description |
---|---|
TimeLocation |
Methods
____ObtainPrivateServiceStatusLockObject()
WARNING: Developers never call this method!!! It is used by advanced derived implementations that need to synchronize status updates. We do not want to make statuslock protected as it is almost never needed, hence this accessor
Declaration
protected object ____ObtainPrivateServiceStatusLockObject()
Returns
Type | Description |
---|---|
System.Object |
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 |
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 |
CheckServiceActive()
Checks for service activity and throws exception if service is not in ControlStatus.Active state
Declaration
protected void CheckServiceActive()
CheckServiceActiveOrStarting()
Checks for service activity and throws exception if service is not in ControlStatus.Active state
Declaration
protected void CheckServiceActiveOrStarting()
CheckServiceInactive()
Checks for service inactivity and throws exception if service is running (started, starting or stopping)
Declaration
protected void CheckServiceInactive()
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 |
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()
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()