Author: jflesch
Date: 2007-08-27 15:07:05 +0000 (Mon, 27 Aug 2007)
New Revision: 14887
Modified:
trunk/apps/Thaw/src/thaw/core/Config.java
trunk/apps/Thaw/src/thaw/core/ConfigWindow.java
trunk/apps/Thaw/src/thaw/core/Core.java
trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java
trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java
trunk/apps/Thaw/src/thaw/plugins/InsertPlugin.java
trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java
trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java
trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java
trunk/apps/Thaw/src/thaw/plugins/Restarter.java
trunk/apps/Thaw/src/thaw/plugins/Signatures.java
trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigTab.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostConfigTab.java
trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
Log:
When a change is done on the configuration, only reload the affected plugins
(need testing!)
Modified: trunk/apps/Thaw/src/thaw/core/Config.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Config.java 2007-08-26 21:03:28 UTC (rev
14886)
+++ trunk/apps/Thaw/src/thaw/core/Config.java 2007-08-27 15:07:05 UTC (rev
14887)
@@ -33,13 +33,20 @@
private final File configFile;
private final HashMap parameters; /* String (param) -> String (value) */
+ private final HashMap listeners; /* String (param) -> Vector -> Plugin
*/
private final Vector pluginNames; /* String (plugin names) */
- public Config(final String filename) {
+ private final Core core;
+
+
+ public Config(Core core, final String filename) {
+ this.core = core;
+
configFile = new File(filename);
parameters = new HashMap();
pluginNames = new Vector();
+ listeners = new HashMap();
}
/**
@@ -49,15 +56,79 @@
return ((String)parameters.get(key));
}
+
+ private boolean listenChanges = false;
+ private Vector pluginsToReload = null;
+
/**
+ * called when majors changed will be done to the config
+ * and will imply some plugin reloading
+ */
+ public void startChanges() {
+ listenChanges = true;
+ pluginsToReload = new Vector();
+ }
+
+ /**
* Set the value in the config.
*/
public void setValue(final String key, final String value) {
Logger.debug(this, "Setting value '"+key+"' to '"+value+"'");
- parameters.put(key, value);
+
+ String currentValue = getValue(key);
+
+ if ( (currentValue != null && !currentValue.equals(value))
+ || (currentValue == null && value != null ) ) {
+
+ /* we get the plugin list to reload */
+ Vector pluginList = (Vector)listeners.get(key);
+
+ if (listenChanges && pluginList != null) {
+ for (Iterator it = pluginList.iterator();
+ it.hasNext();) {
+ Plugin plugin = (Plugin)it.next();
+
+ /* if the plugin is not already in the
plugin list to
+ * reload, we add it */
+ if (pluginsToReload.indexOf(plugin) <
0) {
+ Logger.notice(this, "Will have
to reload '"+plugin.getClass().getName()+"' "+
+ "because
'"+key+"' was changed from '"+currentValue+"' to '"+value+"'");
+ pluginsToReload.add(plugin);
+ }
+
+ }
+ }
+
+ /* and to finish, we set the value */
+ parameters.put(key, value);
+ }
}
/**
+ * called after startChanges. Will reload the plugin listening for the
changed
+ * values
+ */
+ public void applyChanges() {
+ for (Iterator it = pluginsToReload.iterator();
+ it.hasNext();) {
+ Plugin plugin = (Plugin)it.next();
+
core.getPluginManager().stopPlugin(plugin.getClass().getName());
+
core.getPluginManager().runPlugin(plugin.getClass().getName());
+ }
+
+ cancelChanges();
+ }
+
+ /**
+ * Will not undo the changes do to the values, but reset to 0 the
plugin list to reload
+ * Use it only if you know what you're doing !
+ */
+ public void cancelChanges() {
+ listenChanges = false;
+ pluginsToReload = null;
+ }
+
+ /**
* Add the plugin at the end of the plugin list.
*/
public void addPlugin(final String name) {
@@ -294,4 +365,18 @@
setDefaultValue("multipleSockets", "true");
setDefaultValue("sameComputer", "true");
}
+
+
+ public void addListener(String name, Plugin plugin) {
+
+ Vector pluginList = (Vector)listeners.get(name);
+
+ if (pluginList == null) {
+ pluginList = new Vector();
+ listeners.put(name, pluginList);
+ }
+
+ if (pluginList.indexOf(plugin) < 0)
+ pluginList.add(plugin);
+ }
}
Modified: trunk/apps/Thaw/src/thaw/core/ConfigWindow.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/ConfigWindow.java 2007-08-26 21:03:28 UTC
(rev 14886)
+++ trunk/apps/Thaw/src/thaw/core/ConfigWindow.java 2007-08-27 15:07:05 UTC
(rev 14887)
@@ -197,6 +197,9 @@
if(e.getSource() == okButton) {
close(false, true);
+ /** the reloader will apply the changes */
+ core.getConfig().startChanges();
+
setChanged();
notifyObservers(okButton);
@@ -255,24 +258,32 @@
dialog.setLocation(screenSize.width/2 -
(dialogSize.width/2),
screenSize.height/2 -
(dialogSize.height/2));
+ /* Imply a whole reset => all the plugins will be
reloaded
+ */
+ if (resetConnection) {
+ core.getConfig().cancelChanges();
- core.getPluginManager().stopPlugins();
+ core.getPluginManager().stopPlugins();
- /* should reinit the whole connection correctly */
- if (resetConnection && !core.initConnection()) {
- new thaw.gui.WarningWindow(dialog,
-
I18n.getMessage("thaw.warning.unableToConnectTo")+
- "
"+core.getConfig().getValue("nodeAddress")+
- ":"+
core.getConfig().getValue("nodePort"));
- }
+ /* should reinit the whole connection correctly
*/
+ if (resetConnection && !core.initConnection()) {
+ new thaw.gui.WarningWindow(dialog,
+
I18n.getMessage("thaw.warning.unableToConnectTo")+
+ "
"+core.getConfig().getValue("nodeAddress")+
+ ":"+
core.getConfig().getValue("nodePort"));
+ }
- needConnectionReset = false;
+ needConnectionReset = false;
- /* put back the config tab */
- addTabs();
+ /* put back the config tab */
+ addTabs();
- core.getPluginManager().loadAndRunPlugins();
+ core.getPluginManager().loadAndRunPlugins();
+ } else { /* !resetConnection */
+ core.getConfig().applyChanges();
+ }
+
dialog.setVisible(false);
}
}
@@ -286,7 +297,7 @@
public void close(boolean notifyCancel, boolean hideWin) {
if (notifyCancel) {
setChanged();
- this.notifyObservers(cancelButton); /* Equivalent to a
click on the cancel button */
+ notifyObservers(cancelButton); /* Equivalent to a click
on the cancel button */
}
core.getMainWindow().setEnabled(true);
Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java 2007-08-26 21:03:28 UTC (rev
14886)
+++ trunk/apps/Thaw/src/thaw/core/Core.java 2007-08-27 15:07:05 UTC (rev
14887)
@@ -157,7 +157,7 @@
* Init configuration. May re-set I18n.
*/
public boolean initConfig() {
- config = new Config(Config.CONFIG_FILE_NAME);
+ config = new Config(this, Config.CONFIG_FILE_NAME);
if(!config.loadConfig()){
config.setDefaultValues();
Modified: trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java 2007-08-26 21:03:28 UTC
(rev 14886)
+++ trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java 2007-08-27 15:07:05 UTC
(rev 14887)
@@ -39,6 +39,8 @@
Logger.info(this, "Starting plugin \"FetchPlugin\" ...");
+ core.getConfig().addListener("advancedMode", this);
+
fetchPanel = new FetchPanel(core, this);
// Prepare the frame
Modified: trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java 2007-08-26 21:03:28 UTC
(rev 14886)
+++ trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java 2007-08-27 15:07:05 UTC
(rev 14887)
@@ -50,6 +50,14 @@
public boolean run(final Core core) {
this.core = core;
+ core.getConfig().addListener("advancedMode",
this);
+ core.getConfig().addListener("indexAutoRefreshActivated",
this);
+ core.getConfig().addListener("indexRefreshInterval",
this);
+ core.getConfig().addListener("nmbIndexesPerRefreshInterval",
this);
+ core.getConfig().addListener("loadIndexTreeOnTheFly",
this);
+ core.getConfig().addListener("indexFetchNegative",
this);
+ core.getConfig().addListener("indexFetchComments",
this);
+ core.getConfig().addListener("minTrustLevel",
this);
if(core.getPluginManager().getPlugin("thaw.plugins.Hsqldb") ==
null) {
Logger.info(this, "Loading Hsqldb plugin");
Modified: trunk/apps/Thaw/src/thaw/plugins/InsertPlugin.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/InsertPlugin.java 2007-08-26 21:03:28 UTC
(rev 14886)
+++ trunk/apps/Thaw/src/thaw/plugins/InsertPlugin.java 2007-08-27 15:07:05 UTC
(rev 14887)
@@ -41,6 +41,8 @@
public boolean run(final Core core) {
this.core = core;
+ core.getConfig().addListener("advancedMode", this);
+
Logger.info(this, "Starting plugin \"InsertPlugin\" ...");
insertPanel = new InsertPanel(this,
Modified: trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java 2007-08-26 21:03:28 UTC
(rev 14886)
+++ trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java 2007-08-27 15:07:05 UTC
(rev 14887)
@@ -40,6 +40,11 @@
public boolean run(Core core) {
this.core = core;
+ core.getConfig().addListener("advancedMode",
this);
+ core.getConfig().addListener("miniFrostAutoRefreshMaxBoards",
this);
+ core.getConfig().addListener("miniFrostArchiveAfter",
this);
+ core.getConfig().addListener("miniFrostDeleteAfter",
this);
+
if (!loadDeps()
|| !initFactories()
|| !cleanUp(core.getConfig())
Modified: trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java 2007-08-26 21:03:28 UTC
(rev 14886)
+++ trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java 2007-08-27 15:07:05 UTC
(rev 14887)
@@ -107,6 +107,8 @@
public boolean run(Core core) {
this.core = core;
+ core.getConfig().addListener("advancedMode", this);
+
advancedMode =
Boolean.valueOf(core.getConfig().getValue("advancedMode")).booleanValue();
unfoldButton = new JButton("<");
Modified: trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java 2007-08-26 21:03:28 UTC
(rev 14886)
+++ trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java 2007-08-27 15:07:05 UTC
(rev 14887)
@@ -56,6 +56,9 @@
public boolean run(final Core core) {
this.core = core;
+ core.getConfig().addListener("advancedMode", this);
+
+
Logger.info(this, "Starting plugin \"QueueWatcher\" ...");
detailPanel = new DetailPanel();
Modified: trunk/apps/Thaw/src/thaw/plugins/Restarter.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/Restarter.java 2007-08-26 21:03:28 UTC
(rev 14886)
+++ trunk/apps/Thaw/src/thaw/plugins/Restarter.java 2007-08-27 15:07:05 UTC
(rev 14887)
@@ -46,6 +46,9 @@
public boolean run(final Core core) {
this.core = core;
+ core.getConfig().addListener("restartInterval", this);
+ core.getConfig().addListener("restartFatals", this);
+
/* Reloading value from the configuration */
try {
if((core.getConfig().getValue("restartInterval") !=
null)
Modified: trunk/apps/Thaw/src/thaw/plugins/Signatures.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/Signatures.java 2007-08-26 21:03:28 UTC
(rev 14886)
+++ trunk/apps/Thaw/src/thaw/plugins/Signatures.java 2007-08-27 15:07:05 UTC
(rev 14887)
@@ -1,10 +1,6 @@
package thaw.plugins;
-import java.awt.event.ActionListener;
-import java.awt.event.ActionEvent;
-
-
import thaw.core.I18n;
import thaw.core.Core;
import thaw.core.Logger;
@@ -16,7 +12,7 @@
import thaw.plugins.signatures.*;
-public class Signatures extends LibraryPlugin implements ActionListener {
+public class Signatures extends LibraryPlugin {
private Core core;
private Hsqldb db;
private SigConfigTab configTab;
@@ -77,6 +73,8 @@
public boolean run(Core core) {
this.core = core;
+ core.getConfig().addListener("minTrustLevel", this);
+
used++;
if(core.getPluginManager().getPlugin("thaw.plugins.Hsqldb") ==
null) {
@@ -104,9 +102,6 @@
thaw.gui.IconBox.minPeers,
configTab.getPanel());
- core.getConfigWindow().getOkButton().addActionListener(this);
-
core.getConfigWindow().getCancelButton().addActionListener(this);
-
return true;
}
@@ -117,8 +112,7 @@
public boolean stop() {
- core.getConfigWindow().getOkButton().removeActionListener(this);
-
core.getConfigWindow().getCancelButton().removeActionListener(this);
+ configTab.destroy();
core.getConfigWindow().removeTab(configTab.getPanel());
used--;
@@ -144,17 +138,4 @@
public javax.swing.ImageIcon getIcon() {
return IconBox.identity;
}
-
-
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == core.getConfigWindow().getOkButton()) {
- configTab.apply();
- return;
- }
-
- if (e.getSource() == core.getConfigWindow().getCancelButton()) {
- configTab.reset();
- return;
- }
- }
}
Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigTab.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigTab.java 2007-08-26
21:03:28 UTC (rev 14886)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigTab.java 2007-08-27
15:07:05 UTC (rev 14887)
@@ -11,6 +11,9 @@
import javax.swing.JTextField;
import javax.swing.JButton;
+import java.util.Observer;
+import java.util.Observable;
+
import thaw.core.Config;
import thaw.core.ConfigWindow;
import thaw.core.I18n;
@@ -21,7 +24,7 @@
/**
* in the config window
*/
-public class IndexConfigTab implements ActionListener {
+public class IndexConfigTab implements ActionListener, Observer {
private ConfigWindow configWindow;
private Config config;
@@ -61,10 +64,7 @@
autorefreshActivated.addActionListener(this);
- configWindow.getOkButton().addActionListener(this);
- configWindow.getCancelButton().addActionListener(this);
-
editBlackList = new
JButton(I18n.getMessage("thaw.plugin.index.editBlackList")+ " ...");
editBlackList.addActionListener(this);
@@ -99,6 +99,7 @@
public void addTab() {
+ configWindow.addObserver(this);
configWindow.addTab(I18n.getMessage("thaw.plugin.index.indexes"),
thaw.gui.IconBox.minIndex,
panel);
@@ -106,6 +107,7 @@
public void removeTab() {
+ configWindow.deleteObserver(this);
saveValues();
configWindow.removeTab(panel);
}
@@ -179,22 +181,20 @@
Boolean.toString(fetchComments.isSelected()));
}
+ public void update(Observable o, Object param) {
+ if (param == configWindow.getOkButton()) {
+ saveValues();
+ } else if (param == configWindow.getCancelButton()) {
+ resetValues();
+ }
+ }
+
public void actionPerformed(ActionEvent e) {
if (e.getSource() == autorefreshActivated) {
updateTextFieldState();
return;
}
- if (e.getSource() == configWindow.getOkButton()) {
- saveValues();
- return;
- }
-
- if (e.getSource() == configWindow.getCancelButton()) {
- resetValues();
- return;
- }
-
if (e.getSource() == editBlackList) {
indexBrowser.getBlackList().displayPanel();
configWindow.close();
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostConfigTab.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostConfigTab.java
2007-08-26 21:03:28 UTC (rev 14886)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostConfigTab.java
2007-08-27 15:07:05 UTC (rev 14887)
@@ -87,12 +87,11 @@
panel.add(new JLabel(""));
panel.add(regexpPanel);
-
- configWindow.addObserver(this);
}
public void display() {
+ configWindow.addObserver(this);
configWindow.addTab(I18n.getMessage("thaw.plugin.miniFrost"),
thaw.gui.IconBox.minReadComments,
panel);
@@ -100,6 +99,7 @@
public void hide() {
+ configWindow.deleteObserver(this);
configWindow.removeTab(panel);
}
Modified: trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
2007-08-26 21:03:28 UTC (rev 14886)
+++ trunk/apps/Thaw/src/thaw/plugins/signatures/SigConfigTab.java
2007-08-27 15:07:05 UTC (rev 14887)
@@ -39,11 +39,15 @@
import thaw.gui.FileChooser;
import thaw.gui.Table;
+import java.util.Observer;
+import java.util.Observable;
+
+
import thaw.plugins.Hsqldb;
-public class SigConfigTab implements ActionListener {
+public class SigConfigTab implements ActionListener, Observer {
private Hsqldb db;
private ConfigWindow configWindow;
private Config config;
@@ -96,8 +100,14 @@
middlePanel.add(minLevel);
configPanel.add(middlePanel, BorderLayout.CENTER);
+
+ configWindow.addObserver(this);
}
+ public void destroy() {
+ configWindow.deleteObserver(this);
+ }
+
public JPanel getPanel() {
return configPanel;
}
@@ -141,6 +151,15 @@
minLevel.setSelectedItem(Identity.trustLevelStr[i]);
}
+
+ public void update(Observable o, Object param) {
+ if (param == configWindow.getOkButton())
+ apply();
+ else if (param == configWindow.getCancelButton())
+ reset();
+ }
+
+
protected class YourIdentitiesPanel implements ActionListener {
private JDialog dialog;