summaryrefslogtreecommitdiff
path: root/same/src/main/java/com/orbekk/same/http/TjwsServerContainer.java
blob: b71967c4871e4278cc6f6b3ca20d969c814441a6 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.orbekk.same.http;

import java.util.Properties;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import Acme.Serve.Serve;

public class TjwsServerContainer {
    private static class MyServer extends Serve {
        public void join() {
            try {
                backgroundThread.join();
            } catch (InterruptedException e) {
                return;
            };
        }
    }

    private Logger logger = LoggerFactory.getLogger(getClass());
    private MyServer server;
    
    public static TjwsServerContainer create(int port) {
        MyServer server = new MyServer();
        server.setAttribute(Serve.ARG_PORT, port);
        return new TjwsServerContainer(server);
    }
    
    public TjwsServerContainer(MyServer server) {
        this.server = server;
    }
    
    public int getPort() {
        return (Integer)this.server.getAttribute(Serve.ARG_PORT);
    }
    
    public void start() {
        server.runInBackground();
    }
    
    public void stop() {
        server.stopBackground();
    }
    
    public void join() {
        server.join();
    }
}