tgstation-server
The /tg/station 13 server suite
EventConsumer.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Threading;
4 using System.Threading.Tasks;
7 
8 namespace Tgstation.Server.Host.Components
9 {
12  {
17 
22 
27  public EventConsumer(IConfiguration configuration)
28  {
29  this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
30  }
31 
33  public async Task<bool> HandleEvent(EventType eventType, IEnumerable<string> parameters, CancellationToken cancellationToken)
34  {
35  if (watchdog == null)
36  throw new InvalidOperationException("EventConsumer used without watchdog set!");
37 
38  if (!await configuration.HandleEvent(eventType, parameters, cancellationToken).ConfigureAwait(false))
39  return false;
40  return await watchdog.HandleEvent(eventType, parameters, cancellationToken).ConfigureAwait(false);
41  }
42 
47  public void SetWatchdog(IWatchdog watchdog)
48  {
49  if (watchdog == null)
50  throw new ArgumentNullException(nameof(watchdog));
51  if (this.watchdog != null)
52  throw new InvalidOperationException("watchdog already set!");
53  this.watchdog = watchdog;
54  }
55  }
56 }
async Task< bool > HandleEvent(EventType eventType, IEnumerable< string > parameters, CancellationToken cancellationToken)
Handle a given eventType
Consumes EventTypes and takes the appropriate actions
IWatchdog watchdog
The IWatchdog for the
EventType
Types of events. Mirror in tgs.dm
Definition: EventType.cs:6
readonly IConfiguration configuration
The IConfiguration for the EventConsumer
EventConsumer(IConfiguration configuration)
Construct an IEventConsumer
For managing the Configuration directory
Task< bool > HandleEvent(EventType eventType, IEnumerable< string > parameters, CancellationToken cancellationToken)
Handle a given eventType
void SetWatchdog(IWatchdog watchdog)
Set the watchdog for the EventConsumer
Runs and monitors the twin server controllers
Definition: IWatchdog.cs:12