text
stringlengths
0
234
Ctx : constant AWA.Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
begin
if Ctx /= null then
return Ctx.Get_Application;
end if;
-- If there is no service context, look in the servlet current context.
declare
use type ASF.Servlets.Servlet_Registry_Access;
Ctx : constant ASF.Servlets.Servlet_Registry_Access := ASF.Server.Current;
begin
if Ctx = null then
Log.Warn ("There is no service context");
return null;
end if;
if not (Ctx.all in AWA.Applications.Application'Class) then
Log.Warn ("The servlet context is not an application");
return null;
end if;
return AWA.Applications.Application'Class (Ctx.all)'Access;
Function Definition: procedure Free is
Function Body: new Ada.Unchecked_Deallocation (Object => Consumer_Array,
Name => Consumer_Array_Access);
begin
if Manager.Workers /= null then
Log.Info ("Stopping the event dispatcher tasks");
for I in Manager.Workers'Range loop
if Manager.Workers (I)'Callable then
Manager.Workers (I).Stop;
else
Log.Error ("Event consumer task terminated abnormally");
end if;
end loop;
Free (Manager.Workers);
end if;
end Stop;
procedure Add_Queue (Manager : in out Task_Dispatcher;
Queue : in AWA.Events.Queues.Queue_Ref;
Added : out Boolean) is
begin
Log.Info ("Adding queue {0} to the task dispatcher", Queue.Get_Name);
Manager.Queues.Enqueue (Queue);
Added := True;
end Add_Queue;
function Create_Dispatcher (Service : in AWA.Events.Services.Event_Manager_Access;
Match : in String;
Count : in Positive;
Priority : in Positive) return Dispatcher_Access is
Result : constant Task_Dispatcher_Access := new Task_Dispatcher;
begin
Result.Task_Count := Count;
Result.Priority := Priority;
Result.Match := To_Unbounded_String (Match);
Result.Manager := Service.all'Access;
return Result.all'Access;
end Create_Dispatcher;
task body Consumer is
Dispatcher : Task_Dispatcher_Access;
Time : Duration := 0.01;
Do_Work : Boolean := True;
Context : AWA.Services.Contexts.Service_Context;
begin
Log.Info ("Event consumer is ready");
select
accept Start (D : in Task_Dispatcher_Access) do
Dispatcher := D;
end Start;
Log.Info ("Event consumer is started");
-- Set the service context.
Context.Set_Context (Application => Dispatcher.Manager.Get_Application.all'Access,
Principal => null);
while Do_Work loop
declare
Nb_Queues : constant Natural := Dispatcher.Queues.Get_Count;
Queue : AWA.Events.Queues.Queue_Ref;
Nb_Events : Natural := 0;
begin
-- We can have several tasks that dispatch events from several queues.
-- Each queue in the list must be given the same polling quota.
-- Pick a queue and dispatch some pending events.
-- Put back the queue in the fifo.
for I in 1 .. Nb_Queues loop
Dispatcher.Queues.Dequeue (Queue);
begin
Dispatcher.Dispatch (Queue, Nb_Events);
exception
when E : others =>
Log.Error ("Exception when dispatching events", E, True);
Function Definition: procedure Register_User (Data : in out Authenticate_Bean;
Function Body: Outcome : in out Unbounded_String) is