| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 1 | package de.ids_mannheim.korap.utils; |
| 2 | |
| Michael Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 3 | import de.ids_mannheim.korap.config.ConfigLoader; |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 4 | import lombok.Getter; |
| 5 | |
| 6 | import java.io.IOException; |
| 7 | import java.io.InputStream; |
| 8 | import java.util.Properties; |
| 9 | |
| 10 | /** |
| 11 | * @author hanl |
| 12 | * @date 23/01/2014 |
| 13 | */ |
| 14 | public class ServiceInfo { |
| 15 | |
| 16 | private static final ServiceInfo info = new ServiceInfo(); |
| 17 | |
| Michael Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 18 | public static final String UNKNOWN = "UNKNOWN"; |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 19 | |
| 20 | @Getter |
| 21 | private String name; |
| 22 | @Getter |
| 23 | private String version; |
| Michael Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 24 | @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 Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 32 | |
| 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 Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 47 | 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 Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 51 | } |
| 52 | catch (IOException e) { |
| 53 | this.version = UNKNOWN; |
| 54 | this.name = UNKNOWN; |
| Michael Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 55 | this.logger = UNKNOWN; |
| 56 | this.config = UNKNOWN; |
| 57 | this.cacheable = false; |
| 58 | this.cache_store = UNKNOWN; |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | |
| 63 | private static InputStream getStream () throws IOException { |
| Michael Hanl | c0ed00f | 2016-06-23 14:33:10 +0200 | [diff] [blame] | 64 | String path = "kustvakt.info"; |
| 65 | InputStream stream = ConfigLoader.loadConfigStream(path); |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 66 | 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 | } |