summaryrefslogtreecommitdiff
path: root/statserver/src/main/java/com/orbekk/stats/Server.java
blob: 2655ca564809f523b6f7be87a45bdb90f38d00a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.orbekk.stats;

import com.orbekk.protobuf.SimpleProtobufServer;

public class Server {
    private final Experiment1Impl exp1 = new Experiment1Impl();
    
    public static void main(String[] args) {
        new Server().run();
    }
    
    public void run() {
        addShutdownHook();
        SimpleProtobufServer server = SimpleProtobufServer.create(
                Common.PORT);
        server.registerService(exp1);
        System.out.println("Waiting for samples...");
        server.start();
    }
    
    public void addShutdownHook() {
        class ShutdownTask implements Runnable {
            @Override public void run() {
                exp1.writeSamples("experiment1.data");
            }
        }
        Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownTask()));
    }
}