Index: /feedtree/trunk/src/net/feedtree/proxyapp/gui/AppControl.java =================================================================== --- /feedtree/trunk/src/net/feedtree/proxyapp/gui/AppControl.java (revision 54) +++ /feedtree/trunk/src/net/feedtree/proxyapp/gui/AppControl.java (revision 67) @@ -31,5 +31,5 @@ public AppGUI gui; - public WebProxyClient.ClientStatus status; + public Client.ClientStatus status; public Preferences prefs; public JDialog dlg; @@ -64,5 +64,5 @@ public AppControl(AppGUI gui) { this.gui = gui; - this.status = new WebProxyClient.ClientStatus(); + this.status = Client.clientStatus(); } @@ -171,27 +171,10 @@ } - public void restart() { - // Highly experimental! - // - /* - ((rice.pastry.PastryNode)(WebProxyClient.global.getNode())).destroy(); - WebProxyClient.global = null; - - status.notifyStatus(WebProxyClient.ClientStatus.STATUS_NOT_STARTED); - - try { - Thread.sleep(1000); - } catch (java.lang.InterruptedException exc) { } - - run(); - */ - - System.exit(0); - } - public void run() { prefs = Preferences.userRoot().node(PREFS_NODE_NAME); - status.notifyStatus(WebProxyClient.ClientStatus.STATUS_STARTING); + Client.clientStatus().notifyStatus( + Client.ClientStatus.STATUS_STARTING, + "Starting up"); int myPort = prefs.getInt(PR_PASTRY_PORT, Client.PASTRY_PORT); @@ -276,9 +259,9 @@ // Start the node - status.notifyStatus(WebProxyClient.ClientStatus.STATUS_STARTING_NODE); - Node node = Client.start_node(myPort, bs, bsPort, true); - status.notifyStatus(WebProxyClient.ClientStatus.STATUS_STARTING_PROXIES); + Client.clientStatus().notifyStatus( + Client.ClientStatus.STATUS_STARTING, + "Starting HTTP services"); Access.SocketRule[] accessRuleArray = null; @@ -295,5 +278,7 @@ reporting, reaping); - status.notifyStatus(WebProxyClient.ClientStatus.STATUS_READY); + Client.clientStatus().notifyStatus( + Client.ClientStatus.STATUS_RUNNING, + "Ready"); } } Index: /feedtree/trunk/src/net/feedtree/proxyapp/gui/AppGUI.java =================================================================== --- /feedtree/trunk/src/net/feedtree/proxyapp/gui/AppGUI.java (revision 62) +++ /feedtree/trunk/src/net/feedtree/proxyapp/gui/AppGUI.java (revision 67) @@ -8,4 +8,5 @@ import net.feedtree.proxyapp.*; +import net.feedtree.core.client.*; import javax.swing.*; @@ -104,32 +105,44 @@ public void update(Observable obj, Object arg) { + boolean stopProgress = false; + int status = ((Integer)arg).intValue(); - WebProxyClient.ClientStatus statusObj = - (WebProxyClient.ClientStatus)obj; - - if (status < 0) { - // .. + Client.ClientStatus statusObj = (Client.ClientStatus)obj; + + if (status < 0 || status == Client.ClientStatus.STATUS_RUNNING) { + stopProgress = true; } else if (status >= 0) { progressBar.setValue(progressBar.getValue() + 1); } - boolean stopProgress = false; String msg = ""; switch (status) { - case WebProxyClient.ClientStatus.STATUS_NOT_STARTED: - msg = "Not started."; break; - case WebProxyClient.ClientStatus.STATUS_STARTING: - msg = "Starting up..."; break; - case WebProxyClient.ClientStatus.STATUS_STARTING_NODE: - msg = "Connecting to network..."; break; - case WebProxyClient.ClientStatus.STATUS_STARTING_PROXIES: - msg = "Starting web proxy..."; break; - case WebProxyClient.ClientStatus.STATUS_READY: - msg = "Ready."; - stopProgress = true; - break; - case WebProxyClient.ClientStatus.STATUS_ERROR: - msg = "Could not start."; - stopProgress = true; + case Client.ClientStatus.STATUS_NOT_STARTED: + msg = "Not started."; + break; + case Client.ClientStatus.STATUS_STARTING: + msg = statusObj.message + "..."; + break; + case Client.ClientStatus.STATUS_RUNNING: + msg = statusObj.message + "."; + break; + case Client.ClientStatus.STATUS_ERROR: + msg = "Error: " + statusObj.message + "."; + break; + case Client.ClientStatus.STATUS_FATAL_ERROR: + msg = "Fatal: " + statusObj.message + "."; + JOptionPane.showMessageDialog( + null, + "FeedTree could not start because of an error:\n" + + statusObj.message, + "Error", + JOptionPane.ERROR_MESSAGE + ); + + System.exit(1); + + break; + default: + msg = statusObj.message; break; } @@ -161,17 +174,4 @@ int port = client.getProxyPort(); - /* - * This logic is totally faulty! This will give - * us the *external* address, and it's entirely likely - * that the port for the HTTP proxy isn't forwarded from that - * external address (only port 29690). - * - InetSocketAddress addr = client.getLocalNodeAddress(); - if (addr != null) { - hostname = addr.getHostName(); - } else { - hostname = "localhost"; - } - */ try { hostname = InetAddress.getLocalHost().getHostName(); Index: /feedtree/trunk/src/net/feedtree/proxyapp/WebProxyClient.java =================================================================== --- /feedtree/trunk/src/net/feedtree/proxyapp/WebProxyClient.java (revision 66) +++ /feedtree/trunk/src/net/feedtree/proxyapp/WebProxyClient.java (revision 67) @@ -96,32 +96,4 @@ } - public static class ClientStatus extends Observable { - public static final int STATUS_NOT_STARTED = 0; - public static final int STATUS_STARTING = 1; - public static final int STATUS_STARTING_NODE = 2; - public static final int STATUS_STARTING_PROXIES = 3; - public static final int STATUS_READY = 100; - public static final int STATUS_ERROR = -1; - - public WebProxyClient client = null; - public int value = STATUS_NOT_STARTED; - public String errstr = ""; - public ClientStatus() { } - protected void setClient (WebProxyClient client) { - this.client = client; - } - public void notifyStatus(int status) { - notifyStatus(status, ""); - } - public void notifyStatus(int status, String errstr) { - this.value = status; - this.errstr = errstr; - setChanged(); - notifyObservers(new Integer(status)); - } - }; - - public static ClientStatus status = new ClientStatus(); - protected class AbandonedFeedReaper { protected Timer m_scheduler = new Timer(); @@ -1145,5 +1117,6 @@ } public static void main(String[] args) { - status.notifyStatus(ClientStatus.STATUS_STARTING); + Client.clientStatus().notifyStatus(ClientStatus.STATUS_STARTING, + "Starting up"); int myPort = Client.PASTRY_PORT; @@ -1316,9 +1289,10 @@ // Start the node - status.notifyStatus(ClientStatus.STATUS_STARTING_NODE); - Node node = Client.start_node(myPort, bs, bsPort, true); - - status.notifyStatus(ClientStatus.STATUS_STARTING_PROXIES); + + if (node == null) { return; } + + Client.clientStatus().notifyStatus(ClientStatus.STATUS_STARTING, + "Starting HTTP services"); Access.SocketRule[] accessRuleArray = null; @@ -1335,5 +1309,6 @@ reporting, reaping); - status.notifyStatus(ClientStatus.STATUS_READY); + Client.clientStatus().notifyStatus(ClientStatus.STATUS_RUNNING, + "Ready"); } Index: /feedtree/trunk/src/net/feedtree/core/client/Client.java =================================================================== --- /feedtree/trunk/src/net/feedtree/core/client/Client.java (revision 23) +++ /feedtree/trunk/src/net/feedtree/core/client/Client.java (revision 67) @@ -123,4 +123,34 @@ } + // ------------------------------------------------------------ + public static class ClientStatus extends Observable { + public static final int STATUS_NOT_STARTED = 0; + public static final int STATUS_STARTING = 1; + public static final int STATUS_RUNNING = 1000; + public static final int STATUS_ERROR = -1; + public static final int STATUS_FATAL_ERROR = -1000; + + public Client client = null; + public int value = STATUS_NOT_STARTED; + public String message = ""; + public ClientStatus() { } + protected void setClient (Client client) { + this.client = client; + } + public void notifyStatus(int status) { + notifyStatus(status, ""); + } + public void notifyStatus(int status, String message) { + this.value = status; + this.message = message; + setChanged(); + notifyObservers(new Integer(status)); + } + }; + + protected static ClientStatus status = new ClientStatus(); + + public static ClientStatus clientStatus() { return status; } + // ------------------------------------------------------------ protected class Responder implements Application { @@ -210,4 +240,7 @@ public static Node start_node(int port, String bootHost, int bootPort, boolean waitForReady) { Node node = null; + + status.notifyStatus(ClientStatus.STATUS_STARTING, + "Starting FeedTree client"); Environment pastryEnv = new Environment(); @@ -223,5 +256,8 @@ } catch (IOException exc) { Logger.global.severe("error: couldn't create node factory; bailing"); - System.exit(1); + status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR, + "Error loading Pastry network code"); + + return null; } @@ -230,5 +266,7 @@ if (attempts == 0) { Logger.global.warning("[Failed to bootstrap node 5 times. Exiting.]"); - System.exit(1); + + status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR, + "Could not join network"); } @@ -251,5 +289,8 @@ = new InetSocketAddress(bootHostList[i], bootPort); } - + + status.notifyStatus(ClientStatus.STATUS_STARTING, + "Detecting public IP address"); + InetAddress natAddr = NAT.findNatAddress( port, bootSocketList, pastryEnv); @@ -261,4 +302,7 @@ + bootHost + ":" + bootPort + "]"); + status.notifyStatus(ClientStatus.STATUS_STARTING, + "Contacting bootstrap host"); + node = factory.newNode( factory.getNodeHandle(bootSocketList[0]), @@ -266,4 +310,7 @@ } catch (java.io.StreamCorruptedException exc) { Logger.global.severe("Stream corruption error while finding bootstrap. Sleeping and trying again."); + status.notifyStatus(ClientStatus.STATUS_ERROR, + "Network error; re-trying"); + if (node != null && node instanceof SocketPastryNode) { ((PastryNode)node).destroy(); @@ -274,13 +321,26 @@ } continue; + } catch (java.net.UnknownHostException exc) { + status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR, + "Bootstrap host unknown: " + bootHost); + + return null; } catch (Exception exc) { Logger.global.severe("Unexpected exception while finding bootstrap: " + exc); exc.printStackTrace(); Logger.global.severe("Exiting."); - System.exit(1); + + status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR, + "Exception while contacting network:\n " + + exc.toString()); + + return null; } } else { Logger.global.fine("[No bootstrap, starting new ring]"); + status.notifyStatus(ClientStatus.STATUS_STARTING, + "Starting new network"); + node = factory.newNode(null); @@ -288,5 +348,9 @@ Logger.global.warning("[Could not start node; perhaps one is already running?]"); Logger.global.warning("Exiting."); - System.exit(1); + + status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR, + "Could not start node (already running?)"); + + return null; } } @@ -294,5 +358,11 @@ Logger.global.fine("[Created node: " + node + "]"); + status.notifyStatus(ClientStatus.STATUS_STARTING, + "Created network node"); + if (waitForReady) { + status.notifyStatus(ClientStatus.STATUS_STARTING, + "Waiting for node to join network"); + synchronized (node) { int waits = 12; @@ -300,4 +370,8 @@ if (waits == 0) { Logger.global.info("[Failed to bootstrap node into network after 60 sec. Scrapping node and re-starting in 5-15 sec.]"); + + status.notifyStatus(ClientStatus.STATUS_ERROR, + "Failed to connect; re-trying shortly"); + ((PastryNode)node).destroy(); try { @@ -318,4 +392,7 @@ } + status.notifyStatus(ClientStatus.STATUS_STARTING, + "FeedTree client ready"); + return node; }