Objectives

Now that you have finished the first milestone, the objective of this phase is to reflect on what you have produced so far.

For this, we provide you with some example code for contact discovery:

What's in there

The code presented there is less ambitious than the one you add for your first milestone. In a nutshell, it simply listens on a single port for incoming UDP messages containing the name of a contact to add to the contact list.

As such, it is not a correction for what you have produced but instead aims at demonstrating some of the things that one should find in a typical java project:

  • build configuration: this project can be run and imported based only on the pom.xml file.
  • code organization: code is organized in loosely coupled packages. For instance, the packages chatsystem.network and chatsystem.contacts are completely independent of each other and only combined in the main class.
  • thread safety: access to shared resources (e.g. the contact list) is protected by mutex (with the java synchronized keyword)
  • tests: uses junit for testing both the network code, the user list code and their combined usage.
  • error handling: custom error types (e.g. chatsystem.contacts.ContactAlreadyExists), and explicit handling of unrecoverable error (error raised higher the chain of responsibility) or recoverable error (handled locally and continue processing)
  • observer design pattern:
    • implemented by the UDPServer class to make it adaptable to different contexts
    • used by the view to have it react to changes in the contact list
  • singleton design pattern: to ensure that there is a unique instance of the ContactList and that is usable across the application
  • logging: usage of the log4j library (the configuration provided simply prints to the console)
  • continuous integration: each time the code is pushed to github, the code is compiled and tested (and a notification is sent if that fails). This is enabled by the .github/worflows/java.yaml file that sets up Github actions.
  • consistent coding style: the code here (loosely) adheres to the Java Coding Conventions that are used by virtually all java programmers.

How to use it

The final code is given for reference. For each commit, we provide you with a video of your instructor writing down the code and commenting on why it is done this way.

The explanations in the recordings are not very detailed to keep the videos reasonably short and to the point. It is our assumptions that, with your experience from the first milestone, these are sufficient for you to grasp the technical details and the motivation for what is presented. But of course, feel free to ask your instructors if something remains unclear after spending some time on it.

These series of videos are split in two parts:

Before each video is given a list of the topics you can expect to be covered and a link to the commit of the code written. The videos are given in chronological order: at the beginning of the first one, the repository is empty and at the end of the last, the repository is as it is today.