Edit syncTimeout property, made Config a singleton

This commit is contained in:
DieGurke 2019-11-09 14:23:26 +01:00
parent cd8a92c619
commit e1ef85d702
4 changed files with 25 additions and 6 deletions

View File

@ -16,6 +16,16 @@ public class Config {
private String server;
private int port;
private File localDB;
private int syncTimeout;
private static Config config;
private Config() {}
public static Config getInstance() {
if (config == null) config = new Config();
return config;
}
/**
* Defaults to the {@code client.properties} file for information.
@ -28,7 +38,8 @@ public class Config {
public void load(Properties properties) {
if (properties.containsKey("server")) server = properties.getProperty("server");
if (properties.containsKey("port")) port = Integer.parseInt(properties.getProperty("port"));
localDB = new File(properties.getProperty("localDB", ".\\localDB"));
localDB = new File(properties.getProperty("localDB", ".\\localDB"));
syncTimeout = Integer.parseInt(properties.getProperty("syncTimeout", "1000"));
}
/**
@ -54,13 +65,16 @@ public class Config {
localDB = new File(args[++i]);
}
if (localDB == null) localDB = new File(".\\localDB");
if (syncTimeout == 0) syncTimeout = 1000;
}
/**
* @return {@code true} if server, port and localDB directory are known.
* @since Envoy v0.1-alpha
*/
public boolean isInitialized() { return server != null && !server.isEmpty() && port > 0 && port < 65566 && localDB != null; }
public boolean isInitialized() {
return server != null && !server.isEmpty() && port > 0 && port < 65566 && localDB != null;
}
/**
* @return the host name of the Envoy server
@ -106,4 +120,8 @@ public class Config {
* @since Envoy v0.1-alpha
**/
public void setLocalDB(File localDB) { this.localDB = localDB; }
public int getSyncTimeout() { return syncTimeout; }
public void setSyncTimeout(int syncTimeout) { this.syncTimeout = syncTimeout; }
}

View File

@ -25,6 +25,7 @@ import javax.swing.border.EmptyBorder;
import envoy.client.Chat;
import envoy.client.Client;
import envoy.client.Config;
import envoy.client.LocalDB;
import envoy.schema.Message;
import envoy.schema.Sync;
@ -235,7 +236,7 @@ public class ChatWindow extends JFrame {
contentPane.revalidate();
loadUsersAndChats();
startSyncThread(5000);
startSyncThread(Config.getInstance().getSyncTimeout());
contentPane.revalidate();
}
@ -260,7 +261,7 @@ public class ChatWindow extends JFrame {
}
/**
* For detailed information see Javadoc of corresponding methods.
* Updates the data model and the ui every x seconds.
*
* @param timeout the amount of time that passes between two requests sent to
* the server

View File

@ -41,7 +41,7 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer<Mess
final String text = value.getContent().get(0).getText();
final String state = value.getMetadata().getState().toString();
final String date = value.getMetadata().getDate() == null ? ""
: new SimpleDateFormat("dd.MM.yyyy hh:mm ")
: new SimpleDateFormat("dd.MM.yyyy HH:mm ")
.format(value.getMetadata().getDate().toGregorianCalendar().getTime());
setText(String.format(

View File

@ -25,7 +25,7 @@ import envoy.exception.EnvoyException;
public class Startup {
public static void main(String[] args) {
Config config = new Config();
Config config = Config.getInstance();
if (args.length > 0) {
config.load(args);
} else {