C Lab Exercise 3

The task in this exercise is to implement parts, i.e. a living room with a kitchen, of a home automation system. This home automation system contains several sensors measuring the environment and actuators for reacting accordingly. Figure C.1 illustrates the home automation system and its connected devices. Your implementation has to use an actor-based architecture and we propose using the Akka (https://akka.io/) framework for your implementation, as introduced in An Actor Implementation: Java Akka.

Illustration of a home automation system and its connected devices.

Figure C.1: Illustration of a home automation system and its connected devices.

While working on this exercise you will learn how to build applications using the Actor Model paradigm as introduced in Actors. In this paradigm actors are running concurrently and communicate via message-passing only as it uses a share nothing approach, making it very different from typical object-oriented applications. Another outcome of this excercise is to demonstrate how the interaction patterns presented in the lecture are applied in applications.

C.1 Environment

Functions of devices in the home automation system may depend on environmental conditions, which are not controlled by the system itself, e.g., a heating device regulating the temperature depending on the environmental temperature. In this exercise we don’t use any real-world values, but rather simulate the necessary environmental variables by the means of actors.

The simulation of the environment has to provide two values, temperature and weather condition, and slightly deviate them from their respective initial values over time. Considering the temperature the simulator should periodically increase or decrease the temperature by a random value, e.g., start with 23°C increase by 0.5, increase by 0.7, decrease by 0.2 and so on. For the weather condition it is sufficient to consider a couple of classes like sunny or cloudy.

In essence the environment simulator should provide:

  • An Actor that simulates environmental temperature, changing over time.
  • An Actor that simulates weather conditions, changing over time.

C.2 Devices

The home automation system contains several connected devices. Some of these devices are used passively to measure environmental conditions, i.e., they are sensors, while others are used to actively manipulate and interact with physical real-world components, i.e., they are actuators.

The home automation system contains the following devices:

  • Temperature Sensor measures the environmental temperature and wraps it in a custom datatype including a unit.
  • Weather Sensor measures the weather condition.
  • AC (Air Conditioning) regulates the AC depending on the measured temperature.
  • Blinds regulates the blinds depending on the measured weather condition, e.g., closes the blinds if the weather is sunny.
  • Media Station allows playing movies.
  • Fridge manages products and allows ordering new products. Based on the currently contained products an order might no be realizable.

The Fridge is a special kind of device in our system as it contains itself two additional sensors, measuring weight of and space taken by contained products:

  • The Fridge has a maximum number of storable products.
  • The Fridge has a maximum weight load.
  • Each Product has a price and a weight.

C.3 Functionality and Rules

The home automation system provides the following functionality:

  1. Users can consume products from the Fridge.
  2. Users can order products at the Fridge.
  3. A successful order returns a receipt.
  4. The Fridge allows for querying the currently stored products.
  5. The Fridge allows for querying the history of orders.
  6. Users can play movies at the media station.

The home automation system has to adhere to the following rules:

  1. If the weather is sunny the blinds will close.
  2. If the weather is not sunny the blinds will open (unless a movie is playing).
  3. If a movie is playing the blinds are closed.
  4. A new movie cannot be started if another movie is already playing.
  5. If the temperature is above 20°C the AC starts cooling.
  6. If the temperature is below 20°C the AC turns off.
  7. The Fridge can only process an order if there is enough room in the fridge, i.e., the contained products and newly order products do not exceed the maximum number of storable products.
  8. The Fridge can only process an order if the weight of the sum of the contained products and newly order products does not exceed its maximum weight capacity.
  9. If a product runs out in the fridge it is automatically ordered again.

C.4 Implementation

Use the Akka framework to implement the functionality described above and provide a simple command line interface (REPL) for interacting with the home automation system. The command line interface should provide the means to execute all functionality described above as well as manipulating the environment variables. While designing your architecture consider using a hierarchical setup of Actors and use fitting interaction patterns (some hints are given below). A central registration unit for devices is not necessary, however, you may implement one for easier retrieval of actor references. You may consider using the Blackboard Pattern for implementing this exercise.

Implementation details and hints:

  • The actors of the environment simulator are scheduled periodically (see Scheduling messages to self).
  • The sensors measure the values of the environment (see Request-Response with ask between two actors or the environment pushes the values).
  • The sensors wrap the raw values from the environment for the actuators (including units).
  • The AC and Blinds actuators receive the values from the sensors (see Fire and Forget).
  • The user queries the fridge (see Request-Response).
  • The user consums a product from the fridge (see Ignoring replies).
  • The user orders products. In this case the fridge should relay this request to a separate OrderProcessor actor (see Per session child Actor).
  • Possibly one actor that handles the UI.