On this page:
2.1 Initialization and Connecting Clients
2.2 Adoption Protocol
2.3 Testing Task
2.4 Delivery
8.9

E2 — Adoptions, Take 2

Due Friday, 29 March 2024, 11:59:59pm.

Purpose The purpose of this milestone is to implement (most of) the shelter side of the STBU center in Elixir.

Programming Task

This milestone calls for implementing three major pieces of the animal shelter functionality:

  1. Providing clients the means to view and adopt pets;

  2. Enforcing play timeouts; and

  3. Taking in new animals.

2.1 Initialization and Connecting Clients

Implement the module STBU.Interface.Entry with (at least) the following public functions:

A client may use the returned "shelter" PID to either initiate the adoption protocol or bring additional animals to the shelter. For this purpose, implement the module STBU.Interface.Shelter with (at least) the following public functions:

Note. The intention of these module interfaces is to abstract the particular details of message formats and protocols away from clients. That is, you must design the particular data representation of messages, sequence of message sends and receives, and number of collaborating processes to implement the required behavior.

2.2 Adoption Protocol

The logical structure of the adoption protocol mirrors that of milestone 3 (Adoption Protocol), with some minor alterations to the data to accomodate the new setting. The client-facing interface will be provided by the module STBU.Interface.PetViewer, in which you will implement (at least) the following public functions:

Data.

  A PetView is a map with (at least) the following keys associated

  to values of the corresponding type:

   %{ :name => String,

      :age  => NaturalNumber,

      :type =>  PetTypeEx,

      :beenVaccinated => Bool,

      :picture => URI }

  

  A PetTypeEx is either :dog or :cat.

  

  A URI is an instance of the %URI{} struct.

  

  An Optional<T> is either nil or T.

Timeouts. In the event of a play timeout, the pet should return to its pen and the client should receive a PlayTimeout message:

Data.

  A PlayTimeout is a tuple

    {:play_timeout, PetView}

  describing the pet in question.

2.3 Testing Task

Implement the module STBU.Test.EagerClient with (at least) the following public functions:

Data.

  An EagerClientResult is a tuple

    {:eager_client_result, Optional<PetView>}

  describing the client's result.

2.4 Delivery

Your project should include the designated modules under the lib directory (see Elixir, Mix) with the behavior described above, and succesfully build (i.e. with mix compile).