Skip to content

Warden Manager

Piotr Gankiewicz edited this page Sep 18, 2016 · 3 revisions

WardenManager is an extension that allows controlling the instance of IWarden using the available commands and events. It is defined via the following interface:

public interface IWardenManager
{
    Task StartAsync();
    Task StopAsync();
}
  • StartAsync() - start the Manager using the underlying IWarden instance.
  • PauseAsync() - stop the Manager including the underlying IWarden instance.

The WardenManager can be used for example for the remote controlling of the Warden by using the service bus or any other mechanism for sending the commands.

public interface IWardenCommand
{
}

public interface IWardenEvent
{
}

The following commands are available:

  • PauseWarden - pauses the instance of IWarden.
  • StopWarden - stops the instance of IWarden.
  • StartWarden - starts/resumes the instance of IWarden.
  • KillWarden - kills the process where the instance IWarden is running.
  • PingWarden - pings the process where the instance IWarden is running.

And the events:

  • WardenCommandExecuted - returned whenever any command is executed, includes the name of the command.
  • WardenPingResponded - returned after sending the PingWarden command.

Configuration:

WardenManager can be configured to accept the command source and event handler.

public interface IWardenCommandSource
{
    Func<IWardenCommand, Task> CommandReceivedAsync { get; set; }
}

The command source is just a callback that needs to be invoked whenever there's a new command available so that WardenManager can execute it correctly.

public interface IWardenEventHandler
{
    Task HandleAsync<T>(T @event) where T : IWardenEvent;
}

The event handler is responsible for pushing out the events from the WardenManager so they could be processed e.g. by the external application that controls the Warden remotely.

The example configuration that makes use of the already configured IWarden instance and both CommandSource and EventHandler is presented below. It also uses the Logger for the informational purposes.

var wardenManager = WardenManager.Create(warden, cfg =>
{
    cfg.SetCommandSource(() => CommandSource)
       .SetEventHandler(() => EventHandler)
       .WithConsoleLogger(minLevel: WardenLoggerLevel.All, useColors: true);
});

The complete examples using the MSMQ service bus and the Rebus library can be found in the solution under the examples directory. In order to run them, make sure you've enabled the MSMQ and run the Warden.Examples.CommandsAndEvents.Manager application first in order to create a queue that will be used by the Warden.Examples.CommandsAndEvents.App.

Clone this wiki locally