The notifier is a task that waits on events.
It has two features
FOREVER {
AwaitEvent( eventId );
Send( server );
}
You could call a notifier a detective,
In an application there is likely to be lots of waiting on combinations of events.
We use the detective to discover that a complex event has occurred.
Code could be
FOREVER {
Send( part1 );
Send( part2 );
...
Send( master );
}
Code above doesn't work! Try instead
// InitializeDB;
// Create workers and synchronize;
// Synchronize with client;
FOREVER {
Receive( *requester, request );
if ( request.type == CLIENT ) {
parsedRequest = parse( request );
if ( happened( parsedRequest, DB ) ) Reply( requester );
else enqueue( parsedRequest );
}
else if (request.type == WORKER ) {
updateDB ( request );
Reply( requester );
foreach ( queuedRequest )
if ( happened( parsedRequest, DB ) ) {
dequeue( parsedRequest );
Reply( client );
}
}
}
FOREVER {
Receive
switch
case CLIENT: Reply c't or hold
case WORKER: Reply w'r, Reply held
}
This is the code of a detective.
We can say that an event has not happened yet.
Only at the end of the universe can we say that an event simply has not happened.
Time-outs are needed for NOT
FOREVER {
Send( detective, <timed-out>, <delay-request> )
Delay( delay-time );
}
FOREVER {
Receive
switch {
case CLIENT_TO:
if ( to-worker available && other-worker available ) {
Reply( to-worker );
Reply( other-worker );
enqueue( client );
}
else {
if ( !to-worker available ) Create( to-worker ) // and initialize
if // other-worker
case WORKER_TO:
if ( !first && client-waiting ) { Reply( client ); enqueue( to-client ) }
else Reply( to-worker( delay );
...
}
}
Who is the client of the detective
What you are expected to do
What you are expected to do
Give trains roles and objectives. For example,
Another example,
The track is a graph.
Many games are played on graphs
E.g. watchmen and bandit.
Return to: