34 lines
1.4 KiB
C#
34 lines
1.4 KiB
C#
using Akka.Actor;
|
|
using Akka.Event;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Messages.RemoteQuery;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.SiteEventLogging;
|
|
|
|
/// <summary>
|
|
/// Akka actor bridge for <see cref="IEventLogQueryService"/>.
|
|
/// Receives <see cref="EventLogQueryRequest"/> from the SiteCommunicationActor
|
|
/// and returns <see cref="EventLogQueryResponse"/>.
|
|
/// </summary>
|
|
public class EventLogHandlerActor : ReceiveActor
|
|
{
|
|
private readonly ILoggingAdapter _log = Context.GetLogger();
|
|
private readonly IEventLogQueryService _queryService;
|
|
|
|
/// <summary>Initializes the actor and registers the <see cref="EventLogQueryRequest"/> handler.</summary>
|
|
/// <param name="queryService">The query service that executes event log queries.</param>
|
|
public EventLogHandlerActor(IEventLogQueryService queryService)
|
|
{
|
|
_queryService = queryService;
|
|
|
|
// The query is synchronous SQLite I/O (a keyword search can scan millions of
|
|
// rows), so run it on the thread pool and pipe the reply back rather than pinning
|
|
// an Akka dispatcher thread (review 2026-10-21 02/P1). ExecuteQuery never throws —
|
|
// it returns Success:false — so no failure mapper is needed beyond the safety net.
|
|
Receive<EventLogQueryRequest>(msg =>
|
|
{
|
|
var service = _queryService;
|
|
Task.Run(() => service.ExecuteQuery(msg)).PipeTo(Sender);
|
|
});
|
|
}
|
|
}
|