Revision: 6353 Author: [email protected] Date: Mon Oct 12 16:39:12 2009 Log: Changes from review feedback.
http://code.google.com/p/google-web-toolkit/source/detail?r=6353 Added: /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/DevModeUI.java /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/HeadlessUI.java Modified: /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/HostedModeBase.java /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/SwingUI.java /changes/jat/abstractui/dev/oophm/overlay/com/google/gwt/dev/HostedMode.java /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserChannel.java /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserChannelServer.java /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserListener.java /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/OophmSessionHandler.java ======================================= --- /dev/null +++ /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/DevModeUI.java Mon Oct 12 16:39:12 2009 @@ -0,0 +1,191 @@ +/* + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.dev; + +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.TreeLogger.Type; +import com.google.gwt.dev.util.log.PrintWriterTreeLogger; + +import java.util.HashMap; +import java.util.Map; + +/** + * Defines the interaction between DevelopmentMode and the UI, so that + * alternate UIs can be implemented. + */ +public abstract class DevModeUI { + + /** + * Callback interface for events from the UI. + */ + public interface Callback { + + /** + * UI-initiated callback for some event. + * + * @param event event name (TODO: make this a type-safe event in some + * way, need to consider alternate UI implementations though) + * @param callbackData arbitrary data, defined for the event type + */ + void callback(String event, Object callbackData); + } + + /** + * Opaque handle to a module - it is returned from loadModule and can + * only be passed to unloadModule, and the client can get a logger for + * messages about that module. + */ + public interface ModuleHandle { + + /** + * @return the logger for this module. + */ + TreeLogger getLogger(); + } + + // TODO: typesafe callbacks rather than strings + + /** + * Event used to indicate the UI is ready to exit. + * + * <p>Argument is ignored. + */ + public static final String DONE = "done"; + + /** + * Event used to request a restart of the server. + * + * <p>Argument is a TreeLogger instance. Registering a callback for this + * event instructs the UI to provide some control for restarting the server. + */ + public static final String RESTART_SERVER = "restart-server"; + + private final Map<String, Callback> callbacks = new HashMap<String, Callback>(); + + /** + * Log level for all logging in this UI. + */ + protected Type logLevel; + + private PrintWriterTreeLogger consoleLogger = null; + + /** + * Create a top-level logger for messages which are not associated with the + * web server or any module. Defaults to logging to stdout. + * + * @return TreeLogger instance to use + */ + public TreeLogger getTopLogger() { + return getConsoleLogger(); + } + + /** + * Create the web server portion of the UI if not already created, and + * return its TreeLogger instance. + * + * @param serverName short name of the web server or null if only the icon + * should be used + * @param serverIcon byte array containing an icon (fitting into 24x24) to + * use for the server, or null if only the name should be used + * @return TreeLogger instance + */ + public abstract TreeLogger getWebServerLogger(String serverName, + byte[] serverIcon); + + /** + * Initialize the UI - must be called before any other method. + * + * <p>Subclasses should call super.initialize(logLevel). + * + * @param logLevel log level for all logging + */ + public void initialize(Type logLevel) { + this.logLevel = logLevel; + } + + /** + * Load a module + * + * @param userAgent full user agent name + * @param remoteSocket name of remote socket endpoint in host:port format + * @param url URL of top-level window + * @param tabKey stable browser tab identifier, or the empty string if no + * such identifier is available + * @param moduleName the name of the module loaded + * @param sessionKey a unique session key + * @param agentTag short-form user agent identifier, suitable for use in + * a label for this connection + * @param agentIcon icon to use for the user agent (fits inside 24x24) or + * null if unavailable + * @param logLevel logging detail requested + * @return a handle to the module + */ + public abstract ModuleHandle loadModule(String userAgent, + String remoteSocket, String url, String tabKey, String moduleName, + String sessionKey, String agentTag, byte[] agentIcon, Type logLevel); + + /** + * Set a callback for the UI to report events. + * + * @param event + * @param callback + */ + public void setCallback(String event, Callback callback) { + callbacks.put(event, callback); + } + + /** + * Unload a previously loaded module. + * + * @param module ModuleHandle instance returned from loadModule on this UI + * instance + */ + public abstract void unloadModule(ModuleHandle module); + + /** + * Call callbacks for a given event. + * + * @param event + * @param callbackData arbitrary object, depending on the event type + */ + protected void callback(String event, Object callbackData) { + Callback callback = callbacks.get(event); + if (callback != null) { + callback.callback(event, callbackData); + } + } + + /** + * @return a console-based logger. + */ + protected TreeLogger getConsoleLogger() { + if (consoleLogger == null) { + consoleLogger = new PrintWriterTreeLogger(); + consoleLogger.setMaxDetail(logLevel); + } + return consoleLogger; + } + + /** + * Returns true if a callback has been registered for an event. + * + * @param event + * @return true if a callback has been registered for event + */ + protected boolean hasCallback(String event) { + return callbacks.get(event) != null; + } +} ======================================= --- /dev/null +++ /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/HeadlessUI.java Mon Oct 12 16:39:12 2009 @@ -0,0 +1,49 @@ +/* + * Copyright 2009 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.dev; + +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.TreeLogger.Type; +import com.google.gwt.dev.HostedModeBase.HostedModeBaseOptions; + +/** + * UI used in headless operation. + */ +public class HeadlessUI extends DevModeUI { + + public HeadlessUI(HostedModeBaseOptions options) { + } + + @Override + public TreeLogger getWebServerLogger(String serverName, byte[] serverIcon) { + return getConsoleLogger(); + } + + @Override + public ModuleHandle loadModule(String userAgent, String remoteSocket, + String url, String tabKey, String moduleName, String sessionKey, + String agentTag, byte[] agentIcon, Type logLevel) { + return new ModuleHandle() { + public TreeLogger getLogger() { + return getConsoleLogger(); + } + }; + } + + @Override + public void unloadModule(ModuleHandle module) { + } +} ======================================= --- /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/HostedModeBase.java Thu Oct 8 15:44:08 2009 +++ /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/HostedModeBase.java Mon Oct 12 16:39:12 2009 @@ -17,10 +17,9 @@ import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.core.ext.UnableToCompleteException; -import com.google.gwt.core.ext.TreeLogger.Type; import com.google.gwt.core.ext.typeinfo.TypeOracle; -import com.google.gwt.dev.HostedModeBase.DevelopmentModeUI.Callback; -import com.google.gwt.dev.HostedModeBase.DevelopmentModeUI.ModuleHandle; +import com.google.gwt.dev.DevModeUI.Callback; +import com.google.gwt.dev.DevModeUI.ModuleHandle; import com.google.gwt.dev.Precompile.PrecompileOptionsImpl; import com.google.gwt.dev.cfg.ModuleDef; import com.google.gwt.dev.cfg.ModuleDefLoader; @@ -45,17 +44,14 @@ import com.google.gwt.dev.util.arg.ArgHandlerScriptStyle; import com.google.gwt.dev.util.arg.OptionGenDir; import com.google.gwt.dev.util.arg.OptionLogLevel; -import com.google.gwt.dev.util.log.PrintWriterTreeLogger; import com.google.gwt.util.tools.ArgHandlerFlag; import com.google.gwt.util.tools.ArgHandlerString; import java.io.File; -import java.io.PrintWriter; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.IdentityHashMap; import java.util.List; @@ -69,153 +65,6 @@ * any GUI dependencies. */ abstract class HostedModeBase { - - /** - * Defines the interaction between DevelopmentMode and the UI, so that - * alternate UIs can be implemented. - */ - public abstract static class DevelopmentModeUI { - - /** - * Callback interface for events from the UI. - */ - public interface Callback { - - /** - * UI-initiated callback for some event. - * - * @param event event name (TODO: make this a type-safe event in some - * way, need to consider alternate UI implementations though) - * @param callbackData arbitrary data, defined for the event type - */ - void callback(String event, Object callbackData); - } - - /** - * Opaque handle to a module - it is returned from loadModule and can - * only be passed to unloadModule, and the client can get a logger for - * messages about that module. - */ - public interface ModuleHandle { - - /** - * @return the logger for this module. - */ - TreeLogger getLogger(); - } - - // TODO: typesafe callbacks rather than strings - - /** - * Event used to indicate the UI is ready to exit. - * - * <p>Argument is ignored. - */ - public static final String DONE = "done"; - - /** - * Event used to request a restart of the server. - * - * <p>Argument is a TreeLogger instance. Registering a callback for this - * event instructs the UI to provide some control for restarting the server. - */ - public static final String RESTART_SERVER = "restart-server"; - - private final Map<String, Callback> callbacks = new HashMap<String, Callback>(); - - /** - * Create a top-level logger for messages which are not associated with the - * web server or any module. Defaults to logging to stdout. - * - * @param logLevel - * @return TreeLogger instance to use - */ - public TreeLogger getTopLogger(TreeLogger.Type logLevel) { - PrintWriterTreeLogger logger = new PrintWriterTreeLogger(); - logger.setMaxDetail(logLevel); - return logger; - } - - /** - * Create the web server portion of the UI if not already created, and - * return its TreeLogger instance. - * - * @param serverName short name of the web server or null if only the icon - * should be used - * @param serverIcon byte array containing an icon (fitting into 24x24) to - * use for the server, or null if only the name should be used - * @return TreeLogger instance - */ - public abstract TreeLogger getWebServerLogger(String serverName, - byte[] serverIcon); - - /** - * Initialize the UI. - */ - public abstract void initialize(); - - /** - * Load a module - * - * @param userAgent full user agent name - * @param remoteSocket name of remote socket endpoint in host:port format - * @param url URL of top-level window - * @param tabKey stable browser tab identifier, or the empty string if no - * such identifier is available - * @param moduleName the name of the module loaded - * @param sessionKey a unique session key - * @param agentTag short-form user agent identifier, suitable for use in - * a label for this connection - * @param agentIcon icon to use for the user agent (fits inside 24x24) or - * null if unavailable - * @param logLevel logging detail requested - * @return a handle to the module - */ - public abstract ModuleHandle loadModule(String userAgent, - String remoteSocket, String url, String tabKey, String moduleName, - String sessionKey, String agentTag, byte[] agentIcon, Type logLevel); - - /** - * Set a callback for the UI to report events. - * - * @param event - * @param callback - */ - public void setCallback(String event, Callback callback) { - callbacks.put(event, callback); - } - - /** - * Unload a previously loaded module. - * - * @param module ModuleHandle instance returned from loadModule on this UI - * instance - */ - public abstract void unloadModule(ModuleHandle module); - - /** - * Call callbacks for a given event. - * - * @param event - * @param callbackData arbitrary object, depending on the event type - */ - protected void callback(String event, Object callbackData) { - Callback callback = callbacks.get(event); - if (callback != null) { - callback.callback(event, callbackData); - } - } - - /** - * Returns true if a callback has been registered for an event. - * - * @param event - * @return true if a callback has been registered for event - */ - protected boolean hasCallback(String event) { - return callbacks.get(event) != null; - } - } public class UiBrowserWidgetHostImpl extends BrowserWidgetHostImpl { @@ -707,7 +556,7 @@ protected final HostedModeBaseOptions options; - protected DevelopmentModeUI ui = null; + protected DevModeUI ui = null; /** * Cheat on the first load's refresh by assuming the module loaded by @@ -860,18 +709,16 @@ */ protected boolean doStartup() { // Create the main app window. - ui.initialize(); + ui.initialize(options.getLogLevel()); + topLogger = ui.getTopLogger(); // Set done callback - ui.setCallback(DevelopmentModeUI.DONE, new Callback() { + ui.setCallback(DevModeUI.DONE, new Callback() { public void callback(String doneEvent, Object ignored) { setDone(); } }); - // Initialize the logger. - initializeLogger(); - // Check for updates final TreeLogger logger = getTopLogger(); final CheckForUpdates updateChecker @@ -1017,8 +864,13 @@ throw new IllegalStateException("Startup code has already been run"); } + // If no UI was specified by command-line args, then create one. if (ui == null) { - ui = new SwingUI(this); + if (headlessMode) { + ui = new HeadlessUI(options); + } else { + ui = new SwingUI(options); + } } started = true; @@ -1039,16 +891,4 @@ return true; } - - private void initializeLogger() { - Type logLevel = options.getLogLevel(); - if (headlessMode) { - PrintWriterTreeLogger logger = new PrintWriterTreeLogger( - new PrintWriter(System.out)); - logger.setMaxDetail(logLevel); - topLogger = logger; - } else { - topLogger = ui.getTopLogger(logLevel); - } - } -} +} ======================================= --- /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/SwingUI.java Mon Oct 5 15:54:05 2009 +++ /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/SwingUI.java Mon Oct 12 16:39:12 2009 @@ -17,11 +17,10 @@ import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.core.ext.TreeLogger.Type; -import com.google.gwt.dev.HostedModeBase.DevelopmentModeUI; +import com.google.gwt.dev.HostedModeBase.HostedModeBaseOptions; import com.google.gwt.dev.WebServerPanel.RestartAction; import com.google.gwt.dev.shell.ShellMainWindow; import com.google.gwt.dev.util.collect.HashMap; -import com.google.gwt.dev.util.log.PrintWriterTreeLogger; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -38,7 +37,7 @@ /** * Implements the Swing UI for development mode. */ -public class SwingUI extends DevelopmentModeUI { +public class SwingUI extends DevModeUI { /** * Module handle for Swing UI. @@ -121,7 +120,7 @@ } } - private final HostedModeBase hostedModeBase; + private final HostedModeBaseOptions options; private final Map<DevelModeTabKey, ModuleTabPanel> tabPanels = new HashMap< DevelModeTabKey, ModuleTabPanel>(); @@ -132,20 +131,22 @@ private TreeLogger topLogger; - public SwingUI(HostedModeBase hostedModeBase) { - this.hostedModeBase = hostedModeBase; + /** + * Create a Swing UI instance. + * + * @param options parsed command-line options + */ + public SwingUI(HostedModeBaseOptions options) { + this.options = options; } @Override - public TreeLogger getTopLogger(Type logLevel) { - return mainWnd == null ? null : mainWnd.getLogger(); + public TreeLogger getTopLogger() { + return topLogger; } @Override public TreeLogger getWebServerLogger(String serverName, byte[] serverIcon) { - if (hostedModeBase.isHeadless()) { - return topLogger; - } if (webServerLog == null) { RestartAction restartAction = null; if (hasCallback(RESTART_SERVER)) { @@ -155,9 +156,8 @@ } }; } - webServerLog = new WebServerPanel(hostedModeBase.getPort(), - hostedModeBase.options.getLogLevel(), - hostedModeBase.options.getLogFile("webserver.log"), restartAction); + webServerLog = new WebServerPanel(options.getPort(), logLevel, + options.getLogFile("webserver.log"), restartAction); Icon serverIconImage = null; if (serverIcon != null) { serverIconImage = new ImageIcon(serverIcon); @@ -168,23 +168,17 @@ } @Override - public void initialize() { - if (hostedModeBase.isHeadless()) { - PrintWriterTreeLogger logger = new PrintWriterTreeLogger(); - logger.setMaxDetail(hostedModeBase.options.getLogLevel()); - topLogger = logger; - return; - } + public void initialize(Type logLevel) { + super.initialize(logLevel); ImageIcon gwtIcon = loadImageIcon("icon24.png"); frame = new JFrame("GWT Development Mode"); tabs = new JTabbedPane(); - if (hostedModeBase.options.alsoLogToFile()) { - hostedModeBase.options.getLogDir().mkdirs(); - } - mainWnd = new ShellMainWindow(hostedModeBase.options.getLogLevel(), - hostedModeBase.options.getLogFile("main.log")); + if (options.alsoLogToFile()) { + options.getLogDir().mkdirs(); + } + mainWnd = new ShellMainWindow(logLevel, options.getLogFile("main.log")); topLogger = mainWnd.getLogger(); - tabs.addTab("Development Mode", gwtIcon, mainWnd, "GWT Development mode"); + tabs.addTab("Development Mode", gwtIcon, mainWnd, "GWT Development Mode"); frame.getContentPane().add(tabs); frame.setSize(950, 700); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); @@ -204,32 +198,26 @@ String agentTag, byte[] agentIcon, TreeLogger.Type logLevel) { ModuleTabPanel tabPanel = null; ModulePanel tab = null; - TreeLogger logger; - if (!hostedModeBase.isHeadless()) { - tabPanel = findModuleTab(userAgent, remoteSocket, url, tabKey, - moduleName, agentIcon); - tab = tabPanel.addModuleSession(logLevel, moduleName, sessionKey, - hostedModeBase.options.getLogFile(String.format("%s-%s-%d.log", - moduleName, agentTag, - getNextSessionCounter(hostedModeBase.options.getLogDir())))); - logger = tab.getLogger(); - TreeLogger branch = logger.branch(TreeLogger.INFO, "Loading module " - + moduleName); - if (url != null) { - branch.log(TreeLogger.INFO, "Top URL: " + url); - } - branch.log(TreeLogger.INFO, "User agent: " + userAgent); - branch.log(TreeLogger.TRACE, "Remote socket: " + remoteSocket); - if (tabKey != null) { - branch.log(TreeLogger.DEBUG, "Tab key: " + tabKey); - } - if (sessionKey != null) { - branch.log(TreeLogger.DEBUG, "Session key: " + sessionKey); - } - // TODO: Switch to a wait cursor? - } else { - logger = topLogger.branch(logLevel, "Module " + moduleName); - } + tabPanel = findModuleTab(userAgent, remoteSocket, url, tabKey, + moduleName, agentIcon); + tab = tabPanel.addModuleSession(logLevel, moduleName, sessionKey, + options.getLogFile(String.format("%s-%s-%d.log", moduleName, agentTag, + getNextSessionCounter(options.getLogDir())))); + TreeLogger logger = tab.getLogger(); + TreeLogger branch = logger.branch(TreeLogger.INFO, "Loading module " + + moduleName); + if (url != null) { + branch.log(TreeLogger.INFO, "Top URL: " + url); + } + branch.log(TreeLogger.INFO, "User agent: " + userAgent); + branch.log(TreeLogger.TRACE, "Remote socket: " + remoteSocket); + if (tabKey != null) { + branch.log(TreeLogger.DEBUG, "Tab key: " + tabKey); + } + if (sessionKey != null) { + branch.log(TreeLogger.DEBUG, "Session key: " + sessionKey); + } + // TODO: Switch to a wait cursor? return new SwingModuleHandle(logger, tab); } ======================================= --- /changes/jat/abstractui/dev/oophm/overlay/com/google/gwt/dev/HostedMode.java Mon Oct 5 15:54:05 2009 +++ /changes/jat/abstractui/dev/oophm/overlay/com/google/gwt/dev/HostedMode.java Mon Oct 12 16:39:12 2009 @@ -22,7 +22,7 @@ import com.google.gwt.core.ext.linker.ArtifactSet; import com.google.gwt.core.ext.linker.impl.StandardLinkerContext; import com.google.gwt.dev.Compiler.CompilerOptionsImpl; -import com.google.gwt.dev.HostedModeBase.DevelopmentModeUI.Callback; +import com.google.gwt.dev.DevModeUI.Callback; import com.google.gwt.dev.cfg.ModuleDef; import com.google.gwt.dev.shell.ArtifactAcceptor; import com.google.gwt.dev.shell.jetty.JettyLauncher; @@ -376,7 +376,7 @@ @Override protected int doStartUpServer() { try { - ui.setCallback(DevelopmentModeUI.RESTART_SERVER, new Callback() { + ui.setCallback(DevModeUI.RESTART_SERVER, new Callback() { public void callback(String event, Object callbackData) { try { server.refresh(); @@ -401,7 +401,7 @@ System.err.println("Unable to start embedded HTTP server"); e.printStackTrace(); } - ui.setCallback(DevelopmentModeUI.RESTART_SERVER, null); + ui.setCallback(DevModeUI.RESTART_SERVER, null); return -1; } ======================================= --- /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserChannel.java Thu Oct 8 15:44:08 2009 +++ /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserChannel.java Mon Oct 12 16:39:12 2009 @@ -25,13 +25,11 @@ import java.io.BufferedOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; -import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.Socket; -import java.net.SocketException; import java.util.Set; /** @@ -1327,15 +1325,11 @@ public static void send(BrowserChannel channel, boolean isException, Value returnValue) throws IOException { - try { - final DataOutputStream stream = channel.getStreamToOtherSide(); - stream.writeByte(MessageType.RETURN.getId()); - stream.writeBoolean(isException); - channel.writeValue(stream, returnValue); + final DataOutputStream stream = channel.getStreamToOtherSide(); + stream.writeByte(MessageType.RETURN.getId()); + stream.writeBoolean(isException); + channel.writeValue(stream, returnValue); stream.flush(); - } catch (SocketException e) { - throw new RemoteDeathError(e); - } } public static void send(BrowserChannel channel, @@ -1644,8 +1638,13 @@ return msg.returnValue; } - public void reactToMessages(SessionHandler handler) throws IOException, - BrowserChannelException { + /** + * React to messages from the other side, where no return value is expected. + * + * @param handler + * @throws RemoteDeathError + */ + public void reactToMessages(SessionHandler handler) { do { try { getStreamToOtherSide().flush(); @@ -1669,19 +1668,25 @@ case QUIT: return; default: - throw new BrowserChannelException("Invalid message type " - + messageType); - } - } catch (SocketException e) { + throw new RemoteDeathError(new BrowserChannelException( + "Invalid message type " + messageType)); + } + } catch (IOException e) { throw new RemoteDeathError(e); - } catch (EOFException e) { + } catch (BrowserChannelException e) { throw new RemoteDeathError(e); } } while (true); } + /** + * React to messages from the other side, where a return value is expected. + * + * @param handler + * @throws RemoteDeathError + */ public ReturnMessage reactToMessagesWhileWaitingForReturn( - SessionHandler handler) throws IOException, BrowserChannelException { + SessionHandler handler) { do { try { getStreamToOtherSide().flush(); @@ -1712,9 +1717,9 @@ throw new BrowserChannelException("Invalid message type " + messageType + " received waiting for return."); } - } catch (SocketException e) { + } catch (IOException e) { throw new RemoteDeathError(e); - } catch (EOFException e) { + } catch (BrowserChannelException e) { throw new RemoteDeathError(e); } } while (true); ======================================= --- /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserChannelServer.java Thu Oct 8 15:44:08 2009 +++ /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserChannelServer.java Mon Oct 12 16:39:12 2009 @@ -82,12 +82,8 @@ SessionHandler handler, boolean ignoreRemoteDeath) throws IOException { super(socket, new ServerObjectRefFactory()); this.handler = handler; - this.logger = initialLogger; this.ignoreRemoteDeath = ignoreRemoteDeath; - Thread thread = new Thread(this); - thread.setDaemon(true); - thread.setName("Hosted mode worker"); - thread.start(); + init(initialLogger); } // @VisibleForTesting @@ -96,12 +92,8 @@ boolean ignoreRemoteDeath) throws IOException { super(inputStream, outputStream, new ServerObjectRefFactory()); this.handler = handler; - this.logger = initialLogger; this.ignoreRemoteDeath = ignoreRemoteDeath; - Thread thread = new Thread(this); - thread.setDaemon(true); - thread.setName("Hosted mode worker"); - thread.start(); + init(initialLogger); } public void freeJsValue(int[] ids) { @@ -252,8 +244,9 @@ String hostedHtmlVersion = hello.getHostedHtmlVersion(); if (minVersion > PROTOCOL_VERSION_CURRENT || maxVersion < PROTOCOL_VERSION_OLDEST) { - connectError = "No supported protocol version in range " + minVersion - + " - " + maxVersion; + connectError = "Client supported protocol version range " + + minVersion + " - " + maxVersion + "; server " + + PROTOCOL_VERSION_OLDEST + " - " + PROTOCOL_VERSION_CURRENT; } else { if (!HostedHtmlVersion.validHostedHtmlVersion(logger, hostedHtmlVersion)) { @@ -262,13 +255,13 @@ return; } } - protocolVersion = Math.min(PROTOCOL_VERSION_CURRENT, maxVersion); if (connectError != null) { logger.log(TreeLogger.ERROR, "Connection error: " + connectError, null); new FatalErrorMessage(this, connectError).send(); return; } + protocolVersion = Math.min(PROTOCOL_VERSION_CURRENT, maxVersion); new ProtocolVersionMessage(this, protocolVersion).send(); type = Message.readMessageType(getStreamFromOtherSide()); @@ -337,10 +330,14 @@ tabKey, sessionKey, iconBytes); try { // send LoadModule response - ReturnMessage.send(this, false, new Value()); + try { + ReturnMessage.send(this, false, new Value()); + } catch (IOException e) { + throw new RemoteDeathError(e); + } reactToMessages(handler); } catch (RemoteDeathError e) { - if (!ignoreRemoteDeath ) { + if (!ignoreRemoteDeath) { logger.log(TreeLogger.ERROR, e.getMessage(), e); } } finally { @@ -455,6 +452,14 @@ throw new UnsupportedOperationException( "No alternate transports supported"); } + + private void init(TreeLogger initialLogger) { + this.logger = initialLogger; + Thread thread = new Thread(this); + thread.setDaemon(true); + thread.setName("Hosted mode worker"); + thread.start(); + } /** * Select a transport from those provided by the client. ======================================= --- /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserListener.java Thu Oct 8 15:44:08 2009 +++ /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserListener.java Mon Oct 12 16:39:12 2009 @@ -91,6 +91,12 @@ } } + /** + * @return the endpoint identifier of the listener, of the form host:port + * (where host may be an IP address as well). + * + * @throws UnableToCompleteException if the listener is not running + */ public String getEndpointIdentifier() throws UnableToCompleteException { if (listenSocket == null) { // If we failed to initialize our socket, just bail here. @@ -104,6 +110,11 @@ } } + /** + * @return the port number of the listening socket. + * + * @throws UnableToCompleteException if the listener is not running + */ public int getSocketPort() throws UnableToCompleteException { if (listenSocket == null) { // If we failed to initialize our socket, just bail here. @@ -111,12 +122,6 @@ } return listenSocket.getLocalPort(); } - - public void start() { - if (listenThread != null) { - listenThread.start(); - } - } /** * Set any created BrowserChannelServers to ignore remote deaths. @@ -128,4 +133,13 @@ public void setIgnoreRemoteDeath(boolean ignoreRemoteDeath) { this.ignoreRemoteDeath = ignoreRemoteDeath; } -} + + /** + * Start the listener thread. + */ + public void start() { + if (listenThread != null) { + listenThread.start(); + } + } +} ======================================= --- /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/OophmSessionHandler.java Mon Oct 5 15:54:05 2009 +++ /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/OophmSessionHandler.java Mon Oct 12 16:39:12 2009 @@ -158,12 +158,11 @@ BrowserChannel channel, String moduleName, String userAgent, String url, String tabKey, String sessionKey, byte[] userAgentIcon) { logger = loadModuleLogger; - // Add a way to get the icon from the client. try { // Attach a new ModuleSpace to make it programmable. // // TODO(jat): pass serverChannel to createModuleSpaceHost instead - // of the remote endpoint when we remove SWT + // of the remote endpoint BrowserChannelServer serverChannel = (BrowserChannelServer) channel; ModuleSpaceHost msh = host.createModuleSpaceHost(loadModuleLogger, moduleName, userAgent, url, tabKey, sessionKey, --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
