ConsoleManager.java
2.96 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.taobao.pamirs.schedule;
import java.io.*;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.taobao.pamirs.schedule.strategy.TBScheduleManagerFactory;
import com.taobao.pamirs.schedule.taskmanager.IScheduleDataManager;
import com.taobao.pamirs.schedule.zk.ScheduleStrategyDataManager4ZK;
import com.taobao.pamirs.schedule.zk.ZKManager;
public class ConsoleManager {
protected static transient Logger log = LoggerFactory.getLogger(ConsoleManager.class);
public final static String configFile = System.getProperty("user.dir") + File.separator
+ "pamirsScheduleConfig.properties";
private static TBScheduleManagerFactory scheduleManagerFactory;
public static boolean isInitial() throws Exception{
return scheduleManagerFactory != null;
}
public static boolean initial() throws Exception{
if(scheduleManagerFactory != null){
return true;
}
File file = new File(configFile);
scheduleManagerFactory = new TBScheduleManagerFactory();
scheduleManagerFactory.start = false;
if(file.exists()){
//Console不启动调度能力
Properties p = new Properties();
InputStream in = new FileInputStream(file);
p.load(in);
in.close();
scheduleManagerFactory.init(p);
log.info("加载Schedule配置文件:" +configFile );
return true;
}else{
return false;
}
}
public static TBScheduleManagerFactory getScheduleManagerFactory() throws Exception {
if(isInitial() == false){
initial();
}
return scheduleManagerFactory;
}
public static IScheduleDataManager getScheduleDataManager() throws Exception{
if(isInitial() == false){
initial();
}
return scheduleManagerFactory.getScheduleDataManager();
}
public static ScheduleStrategyDataManager4ZK getScheduleStrategyManager() throws Exception{
if(isInitial() == false){
initial();
}
return scheduleManagerFactory.getScheduleStrategyManager();
}
public static Properties loadConfig() throws IOException{
File file = new File(configFile);
Properties properties;
if(!file.exists()){
properties = ZKManager.createProperties();
}else{
properties = new Properties();
InputStream in = new FileInputStream(file);
properties.load(in);
in.close();
}
return properties;
}
public static void saveConfigInfo(Properties p) throws Exception {
try {
File file = new File(configFile);
if (file.exists()){
OutputStream outputStream = new FileOutputStream(configFile);
p.store(outputStream ,"");
outputStream.close();
}
} catch (Exception ex) {
throw new Exception("不能写入配置信息到文件:" + configFile,ex);
}
if(scheduleManagerFactory == null){
initial();
}else{
scheduleManagerFactory.reInit(p);
}
}
public static void setScheduleManagerFactory(
TBScheduleManagerFactory scheduleManagerFactory) {
ConsoleManager.scheduleManagerFactory = scheduleManagerFactory;
}
}