blob: 947f69dad87e28791e3478e0ee2dc04d56ee855c [file] [log] [blame]
Michael Hanle56bb892016-05-25 17:34:41 +02001package de.ids_mannheim.korap.utils;
2
Michael Hanlc0ed00f2016-06-23 14:33:10 +02003import de.ids_mannheim.korap.config.ConfigLoader;
Michael Hanle56bb892016-05-25 17:34:41 +02004import lombok.Getter;
5
6import java.io.IOException;
7import java.io.InputStream;
8import java.util.Properties;
9
10/**
11 * @author hanl
12 * @date 23/01/2014
13 */
14public class ServiceInfo {
15
16 private static final ServiceInfo info = new ServiceInfo();
17
Michael Hanlc0ed00f2016-06-23 14:33:10 +020018 public static final String UNKNOWN = "UNKNOWN";
Michael Hanle56bb892016-05-25 17:34:41 +020019
20 @Getter
21 private String name;
22 @Getter
23 private String version;
Michael Hanlc0ed00f2016-06-23 14:33:10 +020024 @Getter
25 private String config;
26 @Getter
27 private String logger;
28 @Getter
29 private Boolean cacheable;
30 @Getter
31 private String cache_store;
Michael Hanle56bb892016-05-25 17:34:41 +020032
33
34 private ServiceInfo () {
35 load();
36 }
37
38
39 private void load () {
40 Properties props = new Properties();
41 try {
42 InputStream stream = getStream();
43 props.load(stream);
44 stream.close();
45 this.version = (String) props.get("kustvakt.version");
46 this.name = (String) props.get("kustvakt.name");
Michael Hanlc0ed00f2016-06-23 14:33:10 +020047 this.config = (String) props.get("kustvakt.properties");
48 this.logger = (String) props.get("kustvakt.logging");
49 this.cacheable = Boolean.valueOf((String) props.get("kustvakt.cache"));
50 this.cache_store = (String) props.get("kustvakt.cache_store");
Michael Hanle56bb892016-05-25 17:34:41 +020051 }
52 catch (IOException e) {
53 this.version = UNKNOWN;
54 this.name = UNKNOWN;
Michael Hanlc0ed00f2016-06-23 14:33:10 +020055 this.logger = UNKNOWN;
56 this.config = UNKNOWN;
57 this.cacheable = false;
58 this.cache_store = UNKNOWN;
Michael Hanle56bb892016-05-25 17:34:41 +020059 }
60 }
61
62
63 private static InputStream getStream () throws IOException {
Michael Hanlc0ed00f2016-06-23 14:33:10 +020064 String path = "kustvakt.info";
65 InputStream stream = ConfigLoader.loadConfigStream(path);
Michael Hanle56bb892016-05-25 17:34:41 +020066 if (stream == null)
67 throw new IOException("stream for resource " + path
68 + " could not be found...");
69 return stream;
70 }
71
72
73 public static ServiceInfo getInfo () {
74 return info;
75 }
76}