SWEA 2025 Weekplan 13

The learning goals for Week 48 are:

Mon: Docker Containers. Wed: Quality Attributes. Energy-efficiency.

Literature:

Slides:

Notes for this weekplan:

Monday lecture starts at 9.15 and will be on Docker.

Lab classes are tied to the kata below, and the Iteration 10 mandatory exercises. In addition, you may have a look on the exercises below.

Kata

Spend the first 15-20 minutes of the TØ/Lab class in plenum discussing...

The RunApp company is designing a framework for developing running apps for smartphones: the runner’s GPS location is read from the phone’s hardware device, next the location is adjusted to the nearest road or path, and the location is then shown overlaid on a graphical map; similar to the figure on the right.

Designed as a framework, it must support different GPS hardware variants (Initially: from Samsung and Apple) as well as different map services (Initially: from Apple and Google).

The central method in the RunApp app is updatePosOnMap(), which is called every 1 second by the RunApp framework code:

public class RunApp {
  [constructor here ...]
        
  public void updatePosOnMap() {
    Location loc = pollGPSLocation();
    loc = adjustLocationToBeOnARoad(loc);
    mapService.showLocationOnMap(loc);
  }
  private Location pollGPSLocation() {
    return gpsHardware.getCurrentLocation();
  }
  private Location adjustLocationToBeOnARoad(Location l) {
    // algoritms to compute nearest location
    // that is on a road/path
    return adjustedLoc;
  }
}  
        

The two delegates, gpsHardware and mapService, are provided via the constructor to the RunApp class.

Discuss the following points:

  1. Identify the Template Method and identify Frozen and Hot spots.
  2. Argue if the Template Method is made by Separation or by Unification.
  3. Argue why the first line Location loc = poll...() is a hotspot, even though it is a call to a private method in RunApp.
  4. RunApp does not implement an interface? Argue that this is an omission by the lecturer. Argue that the lecturer is correct in not letting RunApp implement any interface.
  5. In the argumentation for letting RunApp implement an interface, argue why it is incorrect to let that interface include the pollGPSLocation() method.
  6. Rewrite the above code to the other Template Method variant (Unification to Separation or vice versa).
  7. Define the interfaces that gpsHardware and mapService must implement.

Optional Exercises:

These are optional exercises. Be sure to solve the mandatory project first, and only if you have a lot of spare time, try having a look at the exercises below.

Install Docker Engine or Desktop

Follow the Docker Desktop guide for installing on your particular machine. Docker Desktop is a GUI based wrapping tool around the Docker Engine that I demonstrate at the lectures. The 'hard core' gals and guys may install the command line Docker Engine instead.

Dockerfile for a Python Hello World program

Solve the PyCon 2018 Tutorial's exercise : 02_dockerfile_essentials

Solving this exercise, you will create a container with Linux and Python installed, add a Python source file to it, and run it - without ever installing Python on your machine!

Containerize Hello-Javalin

The Hello-Spark system can be downloaded from hello-javalin.zip.

You will find a Dockerfile there. Read and understand what this IaC does. And build a hello-javalin image, run it as a container, and test it. Hint: If you cannot contact it, remember that you need to map the container's port to the host ala 'docker run -d -p 4567:4567 (image name)'.

Containerize your HotStone server

Your own HotStone server can of course be containerized. Write the Dockerfile to do so. As base image I recommend 'henrikbaerbak/jdk17-gradle83' or the official 'gradle:8.3-jdk17' which are images with Java 17 and Gradle 8.3 installed already.

AlSoMe: Swarm and Docker in Action

For a complex, potentially multi-machine, swarm based system, you can head over to my AlSoMe Bitbucket repository. This is a crude SnapChat/Messenger/Signal web app, that can be horizontally scaled in a swarm.

Exam Rehearsal

Rehearse a exam situation. Spend 20-25 minutes to read and prepare a 10 minute oral presentation of one of the exercises in the example exam question set: demo-question-2025.pdf.

Next, do a 10 minute presentation at the whiteboard in front of your team.

The team provides constructive feedback on the presentation: Is your presentation clear and understandable, do you discuss the concepts and terms correctly, is you Java example code correct, correct UML, etc. Swap and ensure all in the team gets a chance to rehearse the situation.