Temperature management

Exercise 2: Configuration and management

In this exercise, you will create an administration service to allow the configuration of the targeted temperatures. As in the follow-me exercises, you also will implement an autonomic manager that will configure your application.

Question 1 – Providing a configuration service: Provide a service “TemperatureConfiguration” for configuring your application.

The FollowMeConfiguration service interface is really simple :

package org.example.temperature.configuration;
 
/**
 * The TemperatureConfiguration service allows one to configure the temperature
 * controller.
 */
public interface TemperatureConfiguration {
 
    /**
     * Configure the controller to reach a given temperature in Kelvin in a
     * given room.
     * 
     * @param targetedRoom
     *            the targeted room name
     * @param temperature
     *            the temperature in Kelvin (>=0)
     */
    public void setTargetedTemperature(String targetedRoom, float temperature);
 
    /**
     * Gets the targetted temperature of a given room.
     * 
     * @param room
     *            the room name
     * @return the temperature in Kelvin
     */
    public float getTargetedTemperature(String room);
 
}

Implement the TemperatureConfiguration interface and provide this interface as a service.

Deploy your application.

Export the package org.example.temperature.configuration as explained in the using multiple bundles tutorial.

Question 2 – Implementing a manager: You will now add a “Temperature Manager” component that will be responsible for configuring the service.

The goal is to allow users to express satisfaction. Your manager will have to learned based on user satisfaction which temperature is expected.

Create a new project “temperature.manager” and add a main component TemperatureManager. The implementation class should be named TemperatureManagerImpl.java and put it into the org.example.temperature.manager.impl package.

Import the package org.example.temperature.configuration as explained in the using multiple bundles tutorial.

Add the dependency to the TemperatureConfiguration service and write a manager so that the targeted temperature is adjusted depending on user satisfaction.temperatureAdministration
To help user to express their satisfaction you will have to implement the TemperatureManagerAdministration interface:

package org.example.temperature.manager.administration;
 
/**
 * This interface allows to configure the temperature manager responsible for
 * configuring the temperature controller.
 */
public interface TemperatureManagerAdministration {
 
    /**
     * This method is called every time a user think the temperature is too high
     * in a given room.
     * 
     * @param roomName
     *            the room where the temperature should be reconfigured
     */
    public void temperatureIsTooHigh(String roomName);
 
    /**
     * This method is called every time a user think the temperature is too high
     * in a given room.
     * 
     * @param roomName
     *            the room where the temperature should be reconfigured
     */
    public void temperatureIsTooLow(String roomName);
}

Your manager will have to figure out which is the adequate temperature for a given room (minTemperature, maxTemperature) based on users satisfaction. You can try to reduce or increase the temperature by 1 Kelvin so as to reach an adequate temperature (i.e. when users stop complaining about temperature).

Stabilization could be issue and you have to consider the time factor. Your user might be complaining about the temperature before the actual targeted temperature is reached. Such complained should be ignored or your system might never be stable.

Question 3 – providing a command: Write a command line that use the TemperatureConfiguration service so as to allow users to express their satisfaction.

Create a new component “Temperature Command” that imports and exports the package “org.example.temperature.manager.administration”.
temperatureCommand
Here is a skeleton of the command implementation:

package org.example.temperature.command;
 
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Requires;
import org.example.temperature.manager.administration.TemperatureAdministration ;

 
import fr.liglab.adele.icasa.command.handler.Command;
import fr.liglab.adele.icasa.command.handler.CommandProvider;
 
//Define this class as an implementation of a component :
@Component
//Create an instance of the component
@Instantiate(name = "temperature.administration.command")
//Use the handler command and declare the command as a command provider. The
//namespace is used to prevent name collision.
@CommandProvider(namespace = "temperature")
public class TemperatureCommandImpl {
 
    // Declare a dependency to a TemperatureAdministration service
    @Requires
    private TemperatureAdministration m_administrationService;
 
 
    /**
     * Command implementation to express that the temperature is too high in the given room
     *
     * @param room the given room
     */
 
    // Each command should start with a @Command annotation
    @Command
    public void tempTooHigh(String room) {
        m_administrationService.//...
    }
 
    @Command
    public void tempTooLow(){
        //...
    }
 
}

Implement the two methods. The commands can be then used directly in the Felix shell :

g! tempTooHigh kitchen
g! tempTooLow livingRoom

Question 4 – test: Using the above command, check that your manager is working.