Yichun Zhang (章亦春)


SM::Server - Server entity in the supermarket


    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) { ... }


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.


$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.


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.


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


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.


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


Agent Zhang <agentzh@gmail.com>


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.


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