text
stringlengths
0
234
end Find_Queue;
Name : constant Name_Access := Get_Event_Type_Name (Event.Kind);
begin
if Name = null then
Log.Error ("Cannot dispatch event type {0}", Event_Index'Image (Event.Kind));
raise Not_Found;
end if;
declare
Pos : Queue_Dispatcher_Lists.Cursor := Manager.Actions (Event.Kind).Queues.First;
begin
if not Queue_Dispatcher_Lists.Has_Element (Pos) then
Log.Debug ("Dispatching event {0} but there is no listener", Name.all);
else
Log.Debug ("Dispatching event {0}", Name.all);
loop
Queue_Dispatcher_Lists.Query_Element (Pos, Find_Queue'Access);
exit when Found;
Queue_Dispatcher_Lists.Next (Pos);
if not Queue_Dispatcher_Lists.Has_Element (Pos) then
Log.Debug ("Dispatched event {0} but there was no listener", Name.all);
exit;
end if;
end loop;
end if;
Function Definition: procedure Add_Dispatcher (Manager : in out Event_Manager;
Function Body: Match : in String;
Count : in Positive;
Priority : in Positive) is
use type AWA.Events.Dispatchers.Dispatcher_Access;
begin
Log.Info ("Adding event dispatcher with {0} tasks prio {1} and dispatching queues '{2}'",
Positive'Image (Count), Positive'Image (Priority), Match);
for I in Manager.Dispatchers'Range loop
if Manager.Dispatchers (I) = null then
Manager.Dispatchers (I) :=
AWA.Events.Dispatchers.Tasks.Create_Dispatcher (Manager'Unchecked_Access,
Match, Count, Priority);
return;
end if;
end loop;
Log.Error ("Implementation limit is reached. Too many dispatcher.");
end Add_Dispatcher;
-- ------------------------------
-- Initialize the event manager.
-- ------------------------------
procedure Initialize (Manager : in out Event_Manager;
App : in Application_Access) is
procedure Set_Events (Msg : in AWA.Events.Models.Message_Type_Ref);
Msg_Types : AWA.Events.Models.Message_Type_Vector;
Query : ADO.SQL.Query;
procedure Set_Events (Msg : in AWA.Events.Models.Message_Type_Ref) is
Name : constant String := Msg.Get_Name;
begin
declare
Index : constant Event_Index := Find_Event_Index (Name);
begin
Manager.Actions (Index).Event := Msg;
Function Definition: procedure Associate_Dispatcher (Key : in String;
Function Body: Queue : in out AWA.Events.Queues.Queue_Ref);
-- ------------------------------
-- Dispatch the event queues to the dispatcher according to the dispatcher configuration.
-- ------------------------------
procedure Associate_Dispatcher (Key : in String;
Queue : in out AWA.Events.Queues.Queue_Ref) is
pragma Unreferenced (Key);
Added : Boolean := False;
begin
for I in reverse Manager.Dispatchers'Range loop
if Manager.Dispatchers (I) /= null then
Manager.Dispatchers (I).Add_Queue (Queue, Added);
exit when Added;
end if;
end loop;
end Associate_Dispatcher;
Iter : AWA.Events.Queues.Maps.Cursor := Manager.Queues.First;
begin
Log.Info ("Starting the event manager");
while AWA.Events.Queues.Maps.Has_Element (Iter) loop
Manager.Queues.Update_Element (Iter, Associate_Dispatcher'Access);
AWA.Events.Queues.Maps.Next (Iter);
end loop;
-- Start the dispatchers.
for I in Manager.Dispatchers'Range loop
exit when Manager.Dispatchers (I) = null;
Manager.Dispatchers (I).Start;
end loop;