Lab 1 - Introduction

Lab tasks

The tasks for today are:

First remote method invocation

Remote method invocation over a network

Measuring remote method invocation

In this part, you will run a program that makes multiple remote calls with increasingly large arguments. We should expect the call to take more time when larger arguments are used. Also, calls made over the network will be slower than on just localhost. We will use a Jupyter notebook to plot the data in a chart.

Code examples

In these labs, you will have to write programs in Java an C++. Basic knowledge of these languages is sufficient, but to make it easier, here are some small tasks that may remind you of how a few particular features work in those languages. You may encounter similar problems when solving the tasks in the following labs.

Java reminder - equality

Identify the problem in the following code and fix it.

    public static void main(String[] args){
        if(args.length < 1){
            System.out.printf("No command given%n");
            return;
        }
        if(command == "generate")
            generate();
        else if(command == "analyze")
            generate();
        else
            System.out.printf("Unknown command %s%n", command);
    }

Java reminder - synchronization

Fix the following code, so that it works correctly when the methods increment and read are called form different threads.

class Data {
    private int counter;
    public void inc(){
        ++counter;
    }
    public int read(){
        return counter;
    }
}

C++ reminder - object lifetime

Identify the problem in the following code and fix it.

  class Data{
    string value;
  }
  class Component{
    Data* data;
    Component(Data* data): data(data){}
  }
  shared_ptr<Component> create_component(){
    Data data;
    return make_shared<Component>(&data);
  }

C++ reminder - map comparison

Implement the following function which checks whether two map collection contain the same elements (the same key-value pairs). (Hint: it might be easier than you expect).

  bool check_equal(
    std::map<string, string> mapA,
    std::map<string, string> mapB) {

  }

C++ reminder - polymorphism

Given the class hierarchy, implement the following function which prints the value from every object it receives.

(Hint: Either add virtual methods to the classes, or check the type using dynamic_cast.

  class Base {}
  class A: public Base { public: int value; }
  class B: public Base { public: string value; }
  class C: public Base { public: bool value; }

  void print(Base& object){

  }