Changeset 67

Show
Ignore:
Timestamp:
11/12/05 23:11:05 (5 years ago)
Author:
dsandler
Message:

Big change to the way status is reported during node startup.

ClientStatus? has been moved to net.feedtree.core.Client, where everyone can
contribute to it. It's static, unfortunately, but this allows us to observe
problems during the *construction* of a Client object.

GUI application: Messages are reported to the screen. Errors are either
transient (in which case they are reported like other status messages) or
fatal (in which case they result in a dialog and a System.exit()).

Fixes:

#25 FeedTreeProxy GUI should tell you immediately if firewall/NAT settings

are wrong

#26 GUI doesn't give enough startup feedback

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • feedtree/trunk/src/net/feedtree/core/client/Client.java

    r23 r67  
    123123    } 
    124124     
     125    // ------------------------------------------------------------ 
     126    public static class ClientStatus extends Observable { 
     127        public static final int STATUS_NOT_STARTED = 0; 
     128        public static final int STATUS_STARTING = 1; 
     129        public static final int STATUS_RUNNING = 1000; 
     130        public static final int STATUS_ERROR = -1; 
     131        public static final int STATUS_FATAL_ERROR = -1000; 
     132         
     133        public Client client = null; 
     134        public int value = STATUS_NOT_STARTED; 
     135        public String message = ""; 
     136        public ClientStatus() { } 
     137        protected void setClient (Client client) {  
     138            this.client = client;  
     139        } 
     140        public void notifyStatus(int status) {  
     141            notifyStatus(status, ""); 
     142        } 
     143        public void notifyStatus(int status, String message) {  
     144            this.value = status; 
     145            this.message = message; 
     146            setChanged(); 
     147            notifyObservers(new Integer(status)); 
     148        } 
     149    }; 
     150 
     151    protected static ClientStatus status = new ClientStatus(); 
     152 
     153    public static ClientStatus clientStatus() { return status; } 
     154     
    125155    // ------------------------------------------------------------ 
    126156    protected class Responder implements Application { 
     
    210240    public static Node start_node(int port, String bootHost, int bootPort, boolean waitForReady) { 
    211241        Node node = null; 
     242 
     243        status.notifyStatus(ClientStatus.STATUS_STARTING, 
     244                "Starting FeedTree client"); 
    212245         
    213246        Environment pastryEnv = new Environment(); 
     
    223256        } catch (IOException exc) { 
    224257            Logger.global.severe("error: couldn't create node factory; bailing"); 
    225             System.exit(1); 
     258            status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR,  
     259                    "Error loading Pastry network code"); 
     260             
     261            return null; 
    226262        } 
    227263 
     
    230266            if (attempts == 0) { 
    231267                Logger.global.warning("[Failed to bootstrap node 5 times. Exiting.]"); 
    232                 System.exit(1); 
     268                 
     269                status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR, 
     270                        "Could not join network"); 
    233271            } 
    234272 
     
    251289                            = new InetSocketAddress(bootHostList[i], bootPort); 
    252290                    } 
    253                      
     291 
     292                    status.notifyStatus(ClientStatus.STATUS_STARTING, 
     293                            "Detecting public IP address"); 
     294                                 
    254295                    InetAddress natAddr = NAT.findNatAddress( 
    255296                            port, bootSocketList, pastryEnv); 
     
    261302                        + bootHost + ":" + bootPort + "]"); 
    262303                         
     304                    status.notifyStatus(ClientStatus.STATUS_STARTING, 
     305                            "Contacting bootstrap host"); 
     306                                 
    263307                    node = factory.newNode( 
    264308                        factory.getNodeHandle(bootSocketList[0]), 
     
    266310                } catch (java.io.StreamCorruptedException exc) { 
    267311                    Logger.global.severe("Stream corruption error while finding bootstrap.  Sleeping and trying again."); 
     312                    status.notifyStatus(ClientStatus.STATUS_ERROR, 
     313                            "Network error; re-trying"); 
     314 
    268315                    if (node != null && node instanceof SocketPastryNode) { 
    269316                        ((PastryNode)node).destroy(); 
     
    274321                    } 
    275322                    continue; 
     323                } catch (java.net.UnknownHostException exc) { 
     324                    status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR, 
     325                            "Bootstrap host unknown: " + bootHost); 
     326                     
     327                    return null; 
    276328                } catch (Exception exc) { 
    277329                    Logger.global.severe("Unexpected exception while finding bootstrap: " + exc); 
    278330                    exc.printStackTrace(); 
    279331                    Logger.global.severe("Exiting."); 
    280                     System.exit(1); 
     332                     
     333                    status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR, 
     334                            "Exception while contacting network:\n   "  
     335                            + exc.toString()); 
     336                     
     337                    return null; 
    281338                } 
    282339            } else { 
    283340                Logger.global.fine("[No bootstrap, starting new ring]"); 
    284341     
     342                status.notifyStatus(ClientStatus.STATUS_STARTING, 
     343                        "Starting new network"); 
     344                     
    285345                node = factory.newNode(null); 
    286346 
     
    288348                    Logger.global.warning("[Could not start node; perhaps one is already running?]"); 
    289349                    Logger.global.warning("Exiting."); 
    290                     System.exit(1); 
     350                     
     351                    status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR, 
     352                            "Could not start node (already running?)"); 
     353 
     354                    return null; 
    291355                } 
    292356            } 
     
    294358            Logger.global.fine("[Created node: " + node + "]"); 
    295359 
     360            status.notifyStatus(ClientStatus.STATUS_STARTING, 
     361                    "Created network node"); 
     362 
    296363            if (waitForReady) { 
     364                status.notifyStatus(ClientStatus.STATUS_STARTING, 
     365                        "Waiting for node to join network"); 
     366 
    297367                synchronized (node) { 
    298368                    int waits = 12; 
     
    300370                        if (waits == 0) { 
    301371                            Logger.global.info("[Failed to bootstrap node into network after 60 sec.  Scrapping node and re-starting in 5-15 sec.]"); 
     372 
     373                            status.notifyStatus(ClientStatus.STATUS_ERROR, 
     374                                    "Failed to connect; re-trying shortly"); 
     375 
    302376                            ((PastryNode)node).destroy(); 
    303377                            try { 
     
    318392        } 
    319393         
     394        status.notifyStatus(ClientStatus.STATUS_STARTING, 
     395                "FeedTree client ready"); 
     396 
    320397        return node; 
    321398    } 
  • feedtree/trunk/src/net/feedtree/proxyapp/WebProxyClient.java

    r66 r67  
    9696    } 
    9797 
    98     public static class ClientStatus extends Observable { 
    99         public static final int STATUS_NOT_STARTED = 0; 
    100         public static final int STATUS_STARTING = 1; 
    101         public static final int STATUS_STARTING_NODE = 2; 
    102         public static final int STATUS_STARTING_PROXIES = 3; 
    103         public static final int STATUS_READY = 100; 
    104         public static final int STATUS_ERROR = -1; 
    105          
    106         public WebProxyClient client = null; 
    107         public int value = STATUS_NOT_STARTED; 
    108         public String errstr = ""; 
    109         public ClientStatus() { } 
    110         protected void setClient (WebProxyClient client) {  
    111             this.client = client;  
    112         } 
    113         public void notifyStatus(int status) {  
    114             notifyStatus(status, ""); 
    115         } 
    116         public void notifyStatus(int status, String errstr) {  
    117             this.value = status; 
    118             this.errstr = errstr; 
    119             setChanged(); 
    120             notifyObservers(new Integer(status)); 
    121         } 
    122     }; 
    123  
    124     public static ClientStatus status = new ClientStatus(); 
    125      
    12698    protected class AbandonedFeedReaper { 
    12799        protected Timer m_scheduler = new Timer(); 
     
    11451117    } 
    11461118    public static void main(String[] args) { 
    1147         status.notifyStatus(ClientStatus.STATUS_STARTING); 
     1119        Client.clientStatus().notifyStatus(ClientStatus.STATUS_STARTING,  
     1120                "Starting up"); 
    11481121 
    11491122        int myPort = Client.PASTRY_PORT; 
     
    13161289 
    13171290        // Start the node 
    1318         status.notifyStatus(ClientStatus.STATUS_STARTING_NODE); 
    1319  
    13201291        Node node = Client.start_node(myPort, bs, bsPort, true); 
    1321          
    1322         status.notifyStatus(ClientStatus.STATUS_STARTING_PROXIES); 
     1292 
     1293        if (node == null) { return; } 
     1294         
     1295        Client.clientStatus().notifyStatus(ClientStatus.STATUS_STARTING, 
     1296                "Starting HTTP services"); 
    13231297         
    13241298        Access.SocketRule[] accessRuleArray = null; 
     
    13351309            reporting, reaping); 
    13361310 
    1337         status.notifyStatus(ClientStatus.STATUS_READY); 
     1311        Client.clientStatus().notifyStatus(ClientStatus.STATUS_RUNNING, 
     1312                "Ready"); 
    13381313    } 
    13391314 
  • feedtree/trunk/src/net/feedtree/proxyapp/gui/AppControl.java

    r54 r67  
    3131     
    3232    public AppGUI gui; 
    33     public WebProxyClient.ClientStatus status; 
     33    public Client.ClientStatus status; 
    3434    public Preferences prefs; 
    3535    public JDialog dlg; 
     
    6464    public AppControl(AppGUI gui) { 
    6565        this.gui = gui; 
    66         this.status = new WebProxyClient.ClientStatus(); 
     66        this.status = Client.clientStatus(); 
    6767    } 
    6868 
     
    171171    } 
    172172 
    173     public void restart() { 
    174         // Highly experimental! 
    175         // 
    176         /*  
    177         ((rice.pastry.PastryNode)(WebProxyClient.global.getNode())).destroy(); 
    178         WebProxyClient.global = null; 
    179  
    180         status.notifyStatus(WebProxyClient.ClientStatus.STATUS_NOT_STARTED); 
    181          
    182         try { 
    183             Thread.sleep(1000); 
    184         } catch (java.lang.InterruptedException exc) { } 
    185          
    186         run(); 
    187         */ 
    188  
    189         System.exit(0); 
    190     } 
    191  
    192173    public void run() { 
    193174        prefs = Preferences.userRoot().node(PREFS_NODE_NAME); 
    194175 
    195         status.notifyStatus(WebProxyClient.ClientStatus.STATUS_STARTING); 
     176        Client.clientStatus().notifyStatus( 
     177                Client.ClientStatus.STATUS_STARTING, 
     178                "Starting up"); 
    196179 
    197180        int myPort = prefs.getInt(PR_PASTRY_PORT, Client.PASTRY_PORT); 
     
    276259 
    277260        // Start the node 
    278         status.notifyStatus(WebProxyClient.ClientStatus.STATUS_STARTING_NODE); 
    279  
    280261        Node node = Client.start_node(myPort, bs, bsPort, true); 
    281262         
    282         status.notifyStatus(WebProxyClient.ClientStatus.STATUS_STARTING_PROXIES); 
     263        Client.clientStatus().notifyStatus( 
     264                Client.ClientStatus.STATUS_STARTING, 
     265                "Starting HTTP services"); 
    283266         
    284267        Access.SocketRule[] accessRuleArray = null; 
     
    295278            reporting, reaping); 
    296279 
    297         status.notifyStatus(WebProxyClient.ClientStatus.STATUS_READY); 
     280        Client.clientStatus().notifyStatus( 
     281                Client.ClientStatus.STATUS_RUNNING, 
     282                "Ready"); 
    298283    } 
    299284} 
  • feedtree/trunk/src/net/feedtree/proxyapp/gui/AppGUI.java

    r62 r67  
    88 
    99import net.feedtree.proxyapp.*; 
     10import net.feedtree.core.client.*; 
    1011 
    1112import javax.swing.*; 
     
    104105 
    105106    public void update(Observable obj, Object arg) { 
     107        boolean stopProgress = false; 
     108 
    106109        int status = ((Integer)arg).intValue(); 
    107         WebProxyClient.ClientStatus statusObj =  
    108             (WebProxyClient.ClientStatus)obj; 
    109  
    110         if (status < 0) { 
    111             // .. 
     110        Client.ClientStatus statusObj = (Client.ClientStatus)obj; 
     111 
     112        if (status < 0 || status == Client.ClientStatus.STATUS_RUNNING) { 
     113            stopProgress = true; 
    112114        } else if (status >= 0) { 
    113115            progressBar.setValue(progressBar.getValue() + 1); 
    114116        } 
    115117 
    116         boolean stopProgress = false; 
    117118        String msg = ""; 
    118119        switch (status) { 
    119             case WebProxyClient.ClientStatus.STATUS_NOT_STARTED: 
    120                 msg = "Not started."; break; 
    121             case WebProxyClient.ClientStatus.STATUS_STARTING: 
    122                 msg = "Starting up..."; break; 
    123             case WebProxyClient.ClientStatus.STATUS_STARTING_NODE: 
    124                 msg = "Connecting to network..."; break; 
    125             case WebProxyClient.ClientStatus.STATUS_STARTING_PROXIES: 
    126                 msg = "Starting web proxy..."; break; 
    127             case WebProxyClient.ClientStatus.STATUS_READY: 
    128                 msg = "Ready.";  
    129                 stopProgress = true; 
    130                 break; 
    131             case WebProxyClient.ClientStatus.STATUS_ERROR: 
    132                 msg = "Could not start."; 
    133                 stopProgress = true;  
     120            case Client.ClientStatus.STATUS_NOT_STARTED: 
     121                msg = "Not started.";  
     122                break; 
     123            case Client.ClientStatus.STATUS_STARTING: 
     124                msg = statusObj.message + "...";  
     125                break; 
     126            case Client.ClientStatus.STATUS_RUNNING: 
     127                msg = statusObj.message + ".";  
     128                break; 
     129            case Client.ClientStatus.STATUS_ERROR: 
     130                msg = "Error: " + statusObj.message + "."; 
     131                break; 
     132            case Client.ClientStatus.STATUS_FATAL_ERROR: 
     133                msg = "Fatal: " + statusObj.message + "."; 
     134                JOptionPane.showMessageDialog( 
     135                    null, 
     136                    "FeedTree could not start because of an error:\n" 
     137                        + statusObj.message, 
     138                    "Error", 
     139                    JOptionPane.ERROR_MESSAGE 
     140                ); 
     141 
     142                System.exit(1); 
     143 
     144                break; 
     145            default: 
     146                msg = statusObj.message; 
    134147                break; 
    135148        } 
     
    161174            int port = client.getProxyPort(); 
    162175             
    163             /* 
    164              * This logic is totally faulty!  This will give 
    165              * us the *external* address, and it's entirely likely 
    166              * that the port for the HTTP proxy isn't forwarded from that 
    167              * external address (only port 29690). 
    168              * 
    169             InetSocketAddress addr = client.getLocalNodeAddress(); 
    170             if (addr != null) { 
    171                 hostname = addr.getHostName(); 
    172             } else { 
    173                 hostname = "localhost"; 
    174             } 
    175             */ 
    176176            try { 
    177177                hostname = InetAddress.getLocalHost().getHostName();