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 :

  1. package org.example.temperature.configuration;
  2. /**
  3. * The TemperatureConfiguration service allows one to configure the temperature
  4. * controller.
  5. */
  6. public interface TemperatureConfiguration {
  7. /**
  8. * Configure the controller to reach a given temperature in Kelvin in a
  9. * given room.
  10. *
  11. * @param targetedRoom
  12. * the targeted room name
  13. * @param temperature
  14. * the temperature in Kelvin (>=0)
  15. */
  16. public void setTargetedTemperature(String targetedRoom, float temperature);
  17. /**
  18. * Gets the targetted temperature of a given room.
  19. *
  20. * @param room
  21. * the room name
  22. * @return the temperature in Kelvin
  23. */
  24. public float getTargetedTemperature(String room);
  25. }
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 and check that your service is provided in the Felix console : http://localhost:8080/system/console/bundles.

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:

  1. package org.example.temperature.manager.administration;
  2. /**
  3. * This interface allows to configure the temperature manager responsible for
  4. * configuring the temperature controller.
  5. */
  6. public interface TemperatureManagerAdministration {
  7. /**
  8. * This method is called every time a user think the temperature is too high
  9. * in a given room.
  10. *
  11. * @param roomName
  12. * the room where the temperature should be reconfigured
  13. */
  14. public void temperatureIsTooHigh(String roomName);
  15. /**
  16. * This method is called every time a user think the temperature is too high
  17. * in a given room.
  18. *
  19. * @param roomName
  20. * the room where the temperature should be reconfigured
  21. */
  22. public void temperatureIsTooLow(String roomName);
  23. }
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:

  1. package org.example.temperature.command;
  2. import org.apache.felix.ipojo.annotations.Component;
  3. import org.apache.felix.ipojo.annotations.Instantiate;
  4. import org.apache.felix.ipojo.annotations.Requires;
  5. import org.example.follow.me.manager.FollowMeAdministration;
  6. import org.example.follow.me.manager.IlluminanceGoal;
  7. import fr.liglab.adele.icasa.command.handler.Command;
  8. import fr.liglab.adele.icasa.command.handler.CommandProvider;
  9. //Define this class as an implementation of a component :
  10. @Component
  11. //Create an instance of the component
  12. @Instantiate(name = "temperature.administration.command")
  13. //Use the handler command and declare the command as a command provider. The
  14. //namespace is used to prevent name collision.
  15. @CommandProvider(namespace = "temperature")
  16. public class TemperatureCommandImpl {
  17. // Declare a dependency to a TemperatureAdministration service
  18. @Requires
  19. private TemperatureAdministration m_administrationService;
  20. /**
  21. * Command implementation to express that the temperature is too high in the given room
  22. *
  23. * @param room the given room
  24. */
  25. // Each command should start with a @Command annotation
  26. @Command
  27. public void tempTooHigh(String room) {
  28. m_administrationService.//...
  29. }
  30. @Command
  31. public void tempTooLow(){
  32. //...
  33. }
  34. }
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.follow.me.manager.FollowMeAdministration;
import org.example.follow.me.manager.IlluminanceGoal;
 
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 :

  1. g! tempTooHigh kitchen
  2. g! tempTooLow livingRoom
g! tempTooHigh kitchen
g! tempTooLow livingRoom

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