Zond: перезагрузка настроек
This commit is contained in:
@@ -4,8 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package asys.zond;
|
package asys.zond;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
@@ -26,6 +25,25 @@ public class Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void load() throws IOException {
|
||||||
|
File zondPropertiesFile = new File("zond.properties");
|
||||||
|
if (!zondPropertiesFile.exists()) {
|
||||||
|
InputStream stream = Config.class.getResourceAsStream("/zond.properties");
|
||||||
|
FileOutputStream fos = new FileOutputStream(zondPropertiesFile);
|
||||||
|
byte[] buff = new byte[128];
|
||||||
|
int len;
|
||||||
|
while ((len = stream.read(buff)) > 0) {
|
||||||
|
fos.write(buff, 0, len);
|
||||||
|
}
|
||||||
|
fos.flush();
|
||||||
|
fos.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
FileInputStream fis = new FileInputStream(zondPropertiesFile);
|
||||||
|
load(fis);
|
||||||
|
fis.close();
|
||||||
|
}
|
||||||
|
|
||||||
public String getString(String key) {
|
public String getString(String key) {
|
||||||
return properties.getProperty(key);
|
return properties.getProperty(key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class Main {
|
|||||||
|
|
||||||
private void start(String[] args) {
|
private void start(String[] args) {
|
||||||
try {
|
try {
|
||||||
loadConfig();
|
Config.getInstance().load();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.exit(-2);
|
System.exit(-2);
|
||||||
@@ -54,23 +54,4 @@ public class Main {
|
|||||||
PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(stdout);
|
PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(stdout);
|
||||||
executor.setStreamHandler(pumpStreamHandler);
|
executor.setStreamHandler(pumpStreamHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConfig() throws IOException {
|
|
||||||
File zondPropertiesFile = new File("zond.properties");
|
|
||||||
if (!zondPropertiesFile.exists()) {
|
|
||||||
InputStream stream = Main.class.getResourceAsStream("/zond.properties");
|
|
||||||
FileOutputStream fos = new FileOutputStream(zondPropertiesFile);
|
|
||||||
byte[] buff = new byte[65536];
|
|
||||||
int len;
|
|
||||||
while ((len = stream.read(buff)) > 0) {
|
|
||||||
fos.write(buff, 0, len);
|
|
||||||
}
|
|
||||||
fos.flush();
|
|
||||||
fos.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
FileInputStream fis = new FileInputStream(zondPropertiesFile);
|
|
||||||
Config.getInstance().load(fis);
|
|
||||||
fis.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -65,6 +65,13 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
Connector.getInstance().startReconnect();
|
Connector.getInstance().startReconnect();
|
||||||
} else if (line.equalsIgnoreCase("disconnect")) {
|
} else if (line.equalsIgnoreCase("disconnect")) {
|
||||||
Connector.getInstance().shutdown();
|
Connector.getInstance().shutdown();
|
||||||
|
} else if (line.equalsIgnoreCase("reload")) {
|
||||||
|
Shell.getInstance().getOutput().println("Reload config");
|
||||||
|
try {
|
||||||
|
Config.getInstance().load();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user