PropertiesFactory.java
2.04 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package properties;
import lombok.Data;
import org.apache.commons.io.IOUtils;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.broadcast.Broadcast;
import org.apache.spark.streaming.api.java.JavaStreamingContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
import java.io.InputStream;
import java.io.Serializable;
/**
* Created by markeloff on 2017/7/26.
*/
public class PropertiesFactory implements Serializable {
private static final Logger logger = LoggerFactory.getLogger(PropertiesFactory.class);
private static final String APP_YML_FILE = "app.yml";
private static AllProperties properties;
static {
initProperties();
}
public static void initProperties() {
loadAppYml();
}
public static AllProperties all() {
return properties;
}
public static ESProperties es() {
return properties.getEs();
}
public static KafkaProperties kafka() {
return properties.getKafka();
}
public static SparkProperties spark() {
return properties.getSpark();
}
public static HBaseProperties hbase() { return properties.getHbase(); }
private static void loadAppYml() {
logger.info("enter loadAppYml");
InputStream inputStream = null;
try {
inputStream = PropertiesFactory.class.getClassLoader().getResourceAsStream(APP_YML_FILE);
if (inputStream == null) {
logger.error("inputStream is null");
}
Yaml yaml = new Yaml();
properties = yaml.loadAs(inputStream, AllProperties.class);
logger.info("properties: {} ", properties );
} finally {
IOUtils.closeQuietly(inputStream);
}
logger.info("loadAppYml finish");
}
public static void main(String[] args) {
//initProperties();
System.out.println(es().getHosts().get(0));
System.out.println(kafka().getBrokers());
System.out.println(hbase().getZkquorum());
}
}