Yichun Zhang (章亦春)

NAME

SM::Server - Server entity in the supermarket

SYNOPSIS

    use SM::Server;
    my $server = SM::Server->new( sub { rand(3) } );
    $server->join_queue($client_1, $client_2);

    print $server->id, " : ", $server->queue_len();

    # or equivalently:
    print "$server : ", $server->queue_len();

    if ($server->busy) { ... }

DESCRIPTION

This class implements the server entity in the supermarket problem space. Every server has an ID which is guaranteed to be unique in the whole application.

METHODS

$obj->new( sub {...} )

Server instance constructor. It takes an optional argument, which is an anonymous sub generating service time periods for each client.

The service_time argument defaults to sub { 1 }

$id = $obj->id()

Reads the server's ID, which is generated by Server class's internal counter.

$bool = $obj->busy()

Tests the status of the server, busy or not.

$obj->join_queue(@client)

Makes a client (or more) join the server's client queue (which could be empty).

$len = $obj->queue_len()

Returns the length of the server's client queue (in number of clients).

$time = $obj->gen_service_time()

Generate the next serving time period using the generator passed in via the constructor.

$obj->log("log message")

A message logger for the current server.

INTERNAL METHODS

The following methods are all started by a leading underscore (_), which are not meant to be used by the user directly.

$obj->_serve_next()

Informs the server that it should serve the next client. if the server is currently busy, then the client at service will be popped from the client queue.

$obj->_queue()

Returns the reference to the server's internal client queue.

AUTHOR

Agent Zhang <agentzh@gmail.com>

COPYRIGHT

Copyright 2006 by Agent Zhang. All rights reserved.

This library is free software; you can modify and/or modify it under the same terms as Perl itself.

SEE ALSO

SM, SM::Client, SM::Simulator.