ePages 6.11.0 - DE_EPAGES/Core/API/Object/MonitorThread.pm

Package DE_EPAGES::Core::API::Object::MonitorThread

The monitor thread observes the worker (main) thread. If the main thread need longer then a specified timeout to finish, the monitor thread intercepts and sends the WebAdapter an intermediate result (hourglas page) by calling $Monitor->timeout. The main functionality of this modules is to synchronize the main and the monitor thread.

Example
$MonitorThread = DE_EPAGES::Core::API::Object::MonitorThread->new(
    'Monitor' => $MonitorShared,
    'Timeout' => 5,
);
foreach @Requests {
    $MonitorThread->run(
        Sub => sub { return 'do anything for request, like handle()'; }
    );
}

Functions

close
monitor
new
run
startMonitor
thread

close

Shuts down the monitor thread. Signals the thread function, waits for the thread function to exit and joins the thread.

monitor

Returns the monitor object.

Syntax
$Monitor = $MonitorThread->monitor;
Return
$Monitor (object)
monitor

new

Creates a new monitor thread (used at application server start). The $Monitor object is used to send the hourglas page after a timeout. The result of this function is not the thread itself. It's wrapper that manages the thread and the synchronization between main and monitor thread. The thread will be joined automatically when this object is destroyed.

Syntax
$MonitorThread = DE_EPAGES::Core::API::Object::MonitorThread->new(%options);
Example
$MonitorThread = DE_EPAGES::Core::API::Object::MonitorThread->new(
    'Monitor' => $Monitor,
    'Timeout' => 15
);
Input
$options{Monitor} (object)
monitor object, e.g.
DE_EPAGES::WebInterface::API::Object::MonitorShared
$options{Timeout} (integer)
timeout for the hourglass page in seconds
Return
$MonitorThread (object)
object representing the monitor thread

run

Use this method to execute a possible long-running procedure. In the beginning it calls $Monitor->reset. When the specified timeout (see new) is reached before the procedure has finished, it calls $Monitor->timeout on a second thread.

Syntax
$MonitorThread->run( Sub => $Sub );
Example
$MonitorThread->run(
    Sub => sub { sleep(30); },
);
Input
%Options (hash)
  • Sub - possible long-running code block - code ref

startMonitor

Starts the monitor immediately even before timeout has been reached.

Syntax
$self->startMonitor;

thread

returns the real thread.

Syntax
$Thread = $MonitorThread->thread;
Return
$Thread (object)
thread