Author: jflesch
Date: 2007-03-18 19:20:51 +0000 (Sun, 18 Mar 2007)
New Revision: 12207
Modified:
trunk/apps/Thaw/src/thaw/core/Core.java
trunk/apps/Thaw/src/thaw/core/MainWindow.java
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java
trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
Log:
Put a part of the connection process (ClientHello) into a separate thread +
Change the PeerMonitor display
Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java 2007-03-18 18:34:41 UTC (rev
12206)
+++ trunk/apps/Thaw/src/thaw/core/Core.java 2007-03-18 19:20:51 UTC (rev
12207)
@@ -150,15 +150,84 @@
}
+
/**
+ * My node takes too much time to answer. So now the connection process
is partially threaded.
+ */
+ protected class ConnectionProcess implements Runnable {
+ private Core c;
+
+ public ConnectionProcess(Core c) {
+ this.c = c;
+ }
+
+ public void run() {
+ process();
+ connectionProcess = null;
+ }
+
+ public boolean process() {
+ boolean ret = true;
+
+ clientHello = new FCPClientHello(queryManager,
config.getValue("thawId"));
+
+ if(!clientHello.start(null)) {
+ Logger.warning(this, "Id already used !");
+ subDisconnect();
+ ret = false;
+ } else {
+ Logger.debug(this, "Hello successful");
+ Logger.debug(this, "Node name :
"+clientHello.getNodeName());
+ Logger.debug(this, "FCP version :
"+clientHello.getNodeFCPVersion());
+ Logger.debug(this, "Node version :
"+clientHello.getNodeVersion());
+
+ queueManager.startScheduler();
+
+ queueManager.restartNonPersistent();
+
+ final FCPWatchGlobal watchGlobal = new
FCPWatchGlobal(true);
+ watchGlobal.start(queueManager);
+
+ final FCPQueueLoader queueLoader = new
FCPQueueLoader(config.getValue("thawId"));
+ queueLoader.start(queueManager);
+
+ }
+
+ if(ret && connection.isConnected())
+ connection.addObserver(c);
+
+ if(getMainWindow() != null) {
+ if (ret)
+
getMainWindow().setStatus(IconBox.minConnectAction,
+
I18n.getMessage("thaw.statusBar.ready"));
+ else
+
getMainWindow().setStatus(IconBox.minDisconnectAction,
+
I18n.getMessage("thaw.statusBar.disconnected"), java.awt.Color.RED);
+ }
+
+ return ret;
+ }
+ }
+
+ private ConnectionProcess connectionProcess = null;
+
+
+ /**
* Init the connection to the node.
* If a connection is already established, it will disconnect, so
* if you called canDisconnect() before, then this function can be
called safely.
+ * <br/>
+ * If the connection is opened successfully, ClientHello will be
thread, so you won't have its result
* @see #canDisconnect()
*/
public boolean initConnection() {
boolean ret = true;
+ if (connectionProcess != null) {
+ Logger.notice(this, "A connection process is already
running");
+ return false;
+ }
+
if(getMainWindow() != null) {
getMainWindow().setStatus(IconBox.blueBunny,
I18n.getMessage("thaw.statusBar.connecting"), java.awt.Color.RED);
@@ -217,29 +286,9 @@
QueueKeeper.loadQueue(queueManager,
"thaw.queue.xml");
- clientHello = new FCPClientHello(queryManager,
config.getValue("thawId"));
-
- if(!clientHello.start(null)) {
- Logger.warning(this, "Id already used
!");
- subDisconnect();
- ret = false;
- } else {
- Logger.debug(this, "Hello successful");
- Logger.debug(this, "Node name :
"+clientHello.getNodeName());
- Logger.debug(this, "FCP version :
"+clientHello.getNodeFCPVersion());
- Logger.debug(this, "Node version :
"+clientHello.getNodeVersion());
-
- queueManager.startScheduler();
-
- queueManager.restartNonPersistent();
-
- final FCPWatchGlobal watchGlobal = new
FCPWatchGlobal(true);
- watchGlobal.start(queueManager);
-
- final FCPQueueLoader queueLoader = new
FCPQueueLoader(config.getValue("thawId"));
- queueLoader.start(queueManager);
-
- }
+ connectionProcess = new ConnectionProcess(this);
+ Thread th = new Thread(connectionProcess);
+ th.start();
}
} catch(final Exception e) { /* A little bit not ... "nice" ...
*/
@@ -248,18 +297,6 @@
return false;
}
- if(ret && connection.isConnected())
- connection.addObserver(this);
-
- if(getMainWindow() != null) {
- if (ret)
-
getMainWindow().setStatus(IconBox.minConnectAction,
-
I18n.getMessage("thaw.statusBar.ready"));
- else
-
getMainWindow().setStatus(IconBox.minDisconnectAction,
-
I18n.getMessage("thaw.statusBar.disconnected"), java.awt.Color.RED);
- }
-
return ret;
}
Modified: trunk/apps/Thaw/src/thaw/core/MainWindow.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/MainWindow.java 2007-03-18 18:34:41 UTC
(rev 12206)
+++ trunk/apps/Thaw/src/thaw/core/MainWindow.java 2007-03-18 19:20:51 UTC
(rev 12207)
@@ -177,7 +177,7 @@
statusBar.setSize(500, 30);
- mainWindow.getContentPane().setLayout(new BorderLayout());
+ mainWindow.getContentPane().setLayout(new BorderLayout(5,5));
mainWindow.setJMenuBar(menuBar);
@@ -313,6 +313,12 @@
return true;
}
+ public boolean setSelectedTab(java.awt.Component c) {
+ tabbedPane.setSelectedComponent(c);
+ return true;
+ }
+
+
/**
* Used to remove a tab from the main window.
*/
@@ -514,7 +520,22 @@
return statusBar.getText();
}
+ /**
+ * @param pos can be BorderLayout.EAST or BorderLayout.WEST
+ */
+ public void addComponent(java.awt.Component c, Object pos) {
+ mainWindow.getContentPane().add(c, pos);
+ }
+
+ /**
+ * @see #addComponent(java.awt.Component, Object)
+ */
+ public void removeComponent(java.awt.Component c) {
+ mainWindow.getContentPane().remove(c);
+ }
+
+
public void showDialogAbout() {
final JLabel[] labels = new JLabel[] {
null,
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-03-18 18:34:41 UTC
(rev 12206)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-03-18 19:20:51 UTC
(rev 12207)
@@ -327,6 +327,8 @@
thaw.plugin.peerMonitor.infos.node.uptimeSeconds=Uptime
thaw.plugin.peerMonitor.infos.node.networkSizeEstimateSession=Network size
estimation
thaw.plugin.peerMonitor.infos.node.myName=Node name
+thaw.plugin.peerMonitor.infos.nodeMemory=Node memory
+
thaw.zeroconf.searchingNode=Searching freenet nodes ...
thaw.zeroconf.nodeList=Nodes found:
Modified: trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java 2007-03-18 18:34:41 UTC
(rev 12206)
+++ trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java 2007-03-18 19:20:51 UTC
(rev 12207)
@@ -5,6 +5,8 @@
import java.util.Vector;
import java.util.HashMap;
+import java.awt.BorderLayout;
+
import thaw.core.I18n;
import thaw.core.Core;
@@ -12,7 +14,7 @@
import thaw.fcp.*;
-public class PeerMonitor implements thaw.core.Plugin
+public class PeerMonitor implements thaw.core.Plugin, Observer
{
public final static int DEFAULT_REFRESH_RATE = 10; /* in sec */
@@ -23,6 +25,8 @@
private boolean isRefSet = false;
+ private boolean advancedMode;
+
public PeerMonitor() {
}
@@ -93,12 +97,22 @@
public boolean run(Core core) {
this.core = core;
+ advancedMode =
Boolean.valueOf(core.getConfig().getValue("advancedMode")).booleanValue();
+
+
peerPanel = new PeerMonitorPanel(core.getConfig());
-
core.getMainWindow().addTab(I18n.getMessage("thaw.plugin.peerMonitor.peerMonitor"),
- thaw.gui.IconBox.minPeerMonitor,
- peerPanel.getPanel());
+ if (advancedMode)
+
core.getMainWindow().addTab(I18n.getMessage("thaw.plugin.peerMonitor.peerMonitor"),
+
thaw.gui.IconBox.minPeerMonitor,
+ peerPanel.getTabPanel());
+ if (advancedMode)
+ peerPanel.addObserver(this);
+
+ core.getMainWindow().addComponent(peerPanel.getPeerListPanel(),
+ BorderLayout.EAST);
+
running = true;
isRefSet = false;
Thread th = new Thread(new DisplayRefresher());
@@ -109,7 +123,10 @@
public boolean stop() {
- core.getMainWindow().removeTab(peerPanel.getPanel());
+ if(advancedMode)
+ core.getMainWindow().removeTab(peerPanel.getTabPanel());
+
+
core.getMainWindow().removeComponent(peerPanel.getPeerListPanel());
running = false;
return false;
}
@@ -125,4 +142,8 @@
return thaw.gui.IconBox.peers;
}
+
+ public void update(Observable o, Object param) {
+ core.getMainWindow().setSelectedTab(peerPanel.getTabPanel());
+ }
}
Modified: trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
2007-03-18 18:34:41 UTC (rev 12206)
+++ trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
2007-03-18 19:20:51 UTC (rev 12207)
@@ -25,12 +25,20 @@
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Observable;
+import java.util.Observer;
+
+
import thaw.core.Config;
import thaw.core.I18n;
import thaw.gui.IconBox;
-public class PeerMonitorPanel implements ActionListener, ListSelectionListener
+/**
+ * In fact, here is two panels : A panel with the peer list
+ * and a panel with various details (ref, etc)
+ */
+public class PeerMonitorPanel extends Observable implements ActionListener,
ListSelectionListener
{
/* must match with color list */
public final static String[] STR_STATUS = {
@@ -58,8 +66,11 @@
public final static int STR_INFO_MAX_LNG = 50;
public final static int STR_NODENAME_MAX_LNG = 15;
+ private JPanel refPanel;
- private JPanel panel;
+ private JPanel peerPanel;
+
+ private JPanel tabPanel;
private JPanel mainPanel;
private JLabel refLabel;
@@ -76,11 +87,12 @@
public PeerMonitorPanel(Config config) {
+
advanced =
Boolean.valueOf(config.getValue("advancedMode")).booleanValue();
- panel = new JPanel(new BorderLayout(10, 10));
+ tabPanel = new JPanel(new BorderLayout(10, 10));
- JPanel peerPanel = new JPanel(new BorderLayout());
+ peerPanel = new JPanel(new BorderLayout());
peerList = new JList();
@@ -88,15 +100,25 @@
peerList.addListSelectionListener(this);
Vector v = new Vector();
- v.add(I18n.getMessage("thaw.plugin.peerMonitor.nodeStats"));
+
+ if (advanced)
+
v.add(I18n.getMessage("thaw.plugin.peerMonitor.nodeStats"));
+
peerList.setListData(v);
JLabel peerListLabel = new
JLabel(I18n.getMessage("thaw.plugin.peerMonitor.peerList"));
peerListLabel.setIcon(IconBox.peers);
+
+ memBar = new JProgressBar(0, 100);
+ setMemBar(0, 134217728);
+ memBar.setStringPainted(true);
+
+
peerPanel.add(peerListLabel, BorderLayout.NORTH);
peerPanel.add(new JScrollPane(peerList), BorderLayout.CENTER);
+ peerPanel.add(memBar, BorderLayout.SOUTH);
mainPanel = new JPanel(new GridLayout(2, 1, 10, 10));
@@ -132,13 +154,7 @@
mainPanel.add(globalDetailsPanel);
- memBar = new JProgressBar(0, 100);
- setMemBar(0, 134217728);
- memBar.setStringPainted(true);
-
- panel.add(mainPanel, BorderLayout.CENTER);
- panel.add(peerPanel, BorderLayout.EAST);
- panel.add(memBar, BorderLayout.SOUTH);
+ tabPanel.add(mainPanel, BorderLayout.CENTER);
}
@@ -147,7 +163,7 @@
pourcent = (int)((used * 100) / max);
- memBar.setString("Used memory : "
+
memBar.setString(I18n.getMessage("thaw.plugin.peerMonitor.infos.nodeMemory")+
": "
+ thaw.gui.GUIHelper.getPrintableSize(used)
+ " / "
+ thaw.gui.GUIHelper.getPrintableSize(max)
@@ -245,7 +261,8 @@
{
peers = new Vector();
- peers.add(I18n.getMessage("thaw.plugin.peerMonitor.nodeStats"));
+ if (advanced)
+
peers.add(I18n.getMessage("thaw.plugin.peerMonitor.nodeStats"));
/* TODO : dirty : should use comparator, etc */
for (int i = 0 ; i < STR_STATUS.length ; i++) {
@@ -271,11 +288,15 @@
}
- public JPanel getPanel() {
- return panel;
+ public JPanel getTabPanel() {
+ return tabPanel;
}
+ public JPanel getPeerListPanel() {
+ return peerPanel;
+ }
+
public void actionPerformed(ActionEvent e) {
if (e.getSource() == refCopyButton) {
thaw.gui.GUIHelper.copyToClipboard(refArea.getText());
@@ -424,5 +445,8 @@
displayInfos(I18n.getMessage("thaw.plugin.peerMonitor.peerInfos") + " '" +
peerName + "':",
((Peer)peers.get(e.getFirstIndex())).getParameters());
}
+
+ setChanged();
+ notifyObservers();
}
}