Skip to content
Thomas Schwotzer edited this page Aug 16, 2021 · 11 revisions

ASAP became a fairly huge project after a while. Some useful little classes are implemented over some time. Some could be useful in your application. Feel free to use them. Why implementing such little things over and over again.

AlarmClock

Distributed systems are often need timeouts. A message is sent to another peer. We expect some result within a given time frame. What would we do in real life? Go to bed and set the alarm. Meet class AlarmClock.

class YourClass implements AlarmClockListener {
... 
    // define constants
    public static final int TASK_0 = 0;
    public static final int TASK_1 = 1;

    // implement AlarmClockListener - what happens after alarm
    public void alarmClockRinging(int yourKey) {
        switch (yourKey) {
            case TASK_0: /* do something */; break;
            case TASK_1: /* do something else */; break;
        }
    }

...
    long timeout0 = 1000;
    // set alarm - your class will be called in 1000 milliseconds
    new AlarmClock(timeout0, TASK_0, this).start();
    // another alarm - 5 seconds
    new AlarmClock(5000, TASK_0, this).start();

PeerIDHelper

StreamLinks

Some tricky things came up first when implementing the ASAPHub. The same thing came up in another corner of the project which brought the package streams in this core library.

Here was the task: There is a process. This process has two connections (e.g. a TCP connection) to two other processes (maybe on other machines). Each connection consists of an output- and input stream. Now, this process most connection both processes. It shall act as a mediator. Why? Have a look at our ASAPHub project for an answer. How do we do this? Meet class StreamPairLink.

Clone this wiki locally