Changeset 67
- Timestamp:
- 11/12/05 23:11:05 (5 years ago)
- Files:
-
- feedtree/trunk/src/net/feedtree/core/client/Client.java (modified) (12 diffs)
- feedtree/trunk/src/net/feedtree/proxyapp/WebProxyClient.java (modified) (4 diffs)
- feedtree/trunk/src/net/feedtree/proxyapp/gui/AppControl.java (modified) (5 diffs)
- feedtree/trunk/src/net/feedtree/proxyapp/gui/AppGUI.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
feedtree/trunk/src/net/feedtree/core/client/Client.java
r23 r67 123 123 } 124 124 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 125 155 // ------------------------------------------------------------ 126 156 protected class Responder implements Application { … … 210 240 public static Node start_node(int port, String bootHost, int bootPort, boolean waitForReady) { 211 241 Node node = null; 242 243 status.notifyStatus(ClientStatus.STATUS_STARTING, 244 "Starting FeedTree client"); 212 245 213 246 Environment pastryEnv = new Environment(); … … 223 256 } catch (IOException exc) { 224 257 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; 226 262 } 227 263 … … 230 266 if (attempts == 0) { 231 267 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"); 233 271 } 234 272 … … 251 289 = new InetSocketAddress(bootHostList[i], bootPort); 252 290 } 253 291 292 status.notifyStatus(ClientStatus.STATUS_STARTING, 293 "Detecting public IP address"); 294 254 295 InetAddress natAddr = NAT.findNatAddress( 255 296 port, bootSocketList, pastryEnv); … … 261 302 + bootHost + ":" + bootPort + "]"); 262 303 304 status.notifyStatus(ClientStatus.STATUS_STARTING, 305 "Contacting bootstrap host"); 306 263 307 node = factory.newNode( 264 308 factory.getNodeHandle(bootSocketList[0]), … … 266 310 } catch (java.io.StreamCorruptedException exc) { 267 311 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 268 315 if (node != null && node instanceof SocketPastryNode) { 269 316 ((PastryNode)node).destroy(); … … 274 321 } 275 322 continue; 323 } catch (java.net.UnknownHostException exc) { 324 status.notifyStatus(ClientStatus.STATUS_FATAL_ERROR, 325 "Bootstrap host unknown: " + bootHost); 326 327 return null; 276 328 } catch (Exception exc) { 277 329 Logger.global.severe("Unexpected exception while finding bootstrap: " + exc); 278 330 exc.printStackTrace(); 279 331 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; 281 338 } 282 339 } else { 283 340 Logger.global.fine("[No bootstrap, starting new ring]"); 284 341 342 status.notifyStatus(ClientStatus.STATUS_STARTING, 343 "Starting new network"); 344 285 345 node = factory.newNode(null); 286 346 … … 288 348 Logger.global.warning("[Could not start node; perhaps one is already running?]"); 289 349 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; 291 355 } 292 356 } … … 294 358 Logger.global.fine("[Created node: " + node + "]"); 295 359 360 status.notifyStatus(ClientStatus.STATUS_STARTING, 361 "Created network node"); 362 296 363 if (waitForReady) { 364 status.notifyStatus(ClientStatus.STATUS_STARTING, 365 "Waiting for node to join network"); 366 297 367 synchronized (node) { 298 368 int waits = 12; … … 300 370 if (waits == 0) { 301 371 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 302 376 ((PastryNode)node).destroy(); 303 377 try { … … 318 392 } 319 393 394 status.notifyStatus(ClientStatus.STATUS_STARTING, 395 "FeedTree client ready"); 396 320 397 return node; 321 398 } feedtree/trunk/src/net/feedtree/proxyapp/WebProxyClient.java
r66 r67 96 96 } 97 97 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 126 98 protected class AbandonedFeedReaper { 127 99 protected Timer m_scheduler = new Timer(); … … 1145 1117 } 1146 1118 public static void main(String[] args) { 1147 status.notifyStatus(ClientStatus.STATUS_STARTING); 1119 Client.clientStatus().notifyStatus(ClientStatus.STATUS_STARTING, 1120 "Starting up"); 1148 1121 1149 1122 int myPort = Client.PASTRY_PORT; … … 1316 1289 1317 1290 // Start the node 1318 status.notifyStatus(ClientStatus.STATUS_STARTING_NODE);1319 1320 1291 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"); 1323 1297 1324 1298 Access.SocketRule[] accessRuleArray = null; … … 1335 1309 reporting, reaping); 1336 1310 1337 status.notifyStatus(ClientStatus.STATUS_READY); 1311 Client.clientStatus().notifyStatus(ClientStatus.STATUS_RUNNING, 1312 "Ready"); 1338 1313 } 1339 1314 feedtree/trunk/src/net/feedtree/proxyapp/gui/AppControl.java
r54 r67 31 31 32 32 public AppGUI gui; 33 public WebProxyClient.ClientStatus status;33 public Client.ClientStatus status; 34 34 public Preferences prefs; 35 35 public JDialog dlg; … … 64 64 public AppControl(AppGUI gui) { 65 65 this.gui = gui; 66 this.status = new WebProxyClient.ClientStatus();66 this.status = Client.clientStatus(); 67 67 } 68 68 … … 171 171 } 172 172 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 192 173 public void run() { 193 174 prefs = Preferences.userRoot().node(PREFS_NODE_NAME); 194 175 195 status.notifyStatus(WebProxyClient.ClientStatus.STATUS_STARTING); 176 Client.clientStatus().notifyStatus( 177 Client.ClientStatus.STATUS_STARTING, 178 "Starting up"); 196 179 197 180 int myPort = prefs.getInt(PR_PASTRY_PORT, Client.PASTRY_PORT); … … 276 259 277 260 // Start the node 278 status.notifyStatus(WebProxyClient.ClientStatus.STATUS_STARTING_NODE);279 280 261 Node node = Client.start_node(myPort, bs, bsPort, true); 281 262 282 status.notifyStatus(WebProxyClient.ClientStatus.STATUS_STARTING_PROXIES); 263 Client.clientStatus().notifyStatus( 264 Client.ClientStatus.STATUS_STARTING, 265 "Starting HTTP services"); 283 266 284 267 Access.SocketRule[] accessRuleArray = null; … … 295 278 reporting, reaping); 296 279 297 status.notifyStatus(WebProxyClient.ClientStatus.STATUS_READY); 280 Client.clientStatus().notifyStatus( 281 Client.ClientStatus.STATUS_RUNNING, 282 "Ready"); 298 283 } 299 284 } feedtree/trunk/src/net/feedtree/proxyapp/gui/AppGUI.java
r62 r67 8 8 9 9 import net.feedtree.proxyapp.*; 10 import net.feedtree.core.client.*; 10 11 11 12 import javax.swing.*; … … 104 105 105 106 public void update(Observable obj, Object arg) { 107 boolean stopProgress = false; 108 106 109 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; 112 114 } else if (status >= 0) { 113 115 progressBar.setValue(progressBar.getValue() + 1); 114 116 } 115 117 116 boolean stopProgress = false;117 118 String msg = ""; 118 119 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; 134 147 break; 135 148 } … … 161 174 int port = client.getProxyPort(); 162 175 163 /*164 * This logic is totally faulty! This will give165 * us the *external* address, and it's entirely likely166 * that the port for the HTTP proxy isn't forwarded from that167 * 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 */176 176 try { 177 177 hostname = InetAddress.getLocalHost().getHostName();
