Revision: 6805 Author: [email protected] Date: Tue Nov 10 11:13:04 2009 Log: Merges tr...@r6804 into releases/2.0. Merge performed with the following command:
svn merge --ignore-ancestry -c 6804 https://google-web-toolkit.googlecode.com/svn/trunk . http://code.google.com/p/google-web-toolkit/source/detail?r=6805 Modified: /releases/2.0/dev/core/src/com/google/gwt/dev/shell/BrowserListener.java /releases/2.0/dev/core/src/com/google/gwt/dev/shell/remoteui/MessageTransport.java /releases/2.0/dev/core/src/com/google/gwt/dev/shell/remoteui/RemoteUI.java ======================================= --- /releases/2.0/dev/core/src/com/google/gwt/dev/shell/BrowserListener.java Fri Oct 30 11:06:32 2009 +++ /releases/2.0/dev/core/src/com/google/gwt/dev/shell/BrowserListener.java Tue Nov 10 11:13:04 2009 @@ -22,6 +22,7 @@ import java.io.IOException; import java.net.BindException; import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; @@ -48,16 +49,19 @@ private ServerSocket listenSocket; private Thread listenThread; - + private boolean ignoreRemoteDeath = false; - + /** * Listens for new connections from browsers. */ public BrowserListener(final TreeLogger logger, int port, final SessionHandler handler) { try { - listenSocket = new ServerSocket(port); + listenSocket = new ServerSocket(); + listenSocket.setReuseAddress(true); + listenSocket.bind(new InetSocketAddress(port)); + logger.log(TreeLogger.INFO, "Listening at: " + listenSocket.getLocalSocketAddress(), null); listenThread = new Thread() { @@ -73,7 +77,6 @@ try { sock.setTcpNoDelay(true); sock.setKeepAlive(true); - sock.setReuseAddress(true); } catch (SocketException e) { // Ignore non-critical errors. } @@ -106,7 +109,7 @@ /** * @return the endpoint identifier of the listener, of the form host:port - * (where host may be an IP address as well). + * (where host may be an IP address as well). * * @throws UnableToCompleteException if the listener is not running */ @@ -134,12 +137,13 @@ /** * Set any created BrowserChannelServers to ignore remote deaths. * - * <p>This is most commonly wanted by JUnitShell. + * <p> + * This is most commonly wanted by JUnitShell. * * @param ignoreRemoteDeath */ public void setIgnoreRemoteDeath(boolean ignoreRemoteDeath) { - this.ignoreRemoteDeath = ignoreRemoteDeath; + this.ignoreRemoteDeath = ignoreRemoteDeath; } /** ======================================= --- /releases/2.0/dev/core/src/com/google/gwt/dev/shell/remoteui/MessageTransport.java Mon Nov 9 08:06:34 2009 +++ /releases/2.0/dev/core/src/com/google/gwt/dev/shell/remoteui/MessageTransport.java Tue Nov 10 11:13:04 2009 @@ -69,6 +69,19 @@ return failureMessage; } } + + /** + * A callback that is invoked when the transport terminates. + */ + public interface TerminationCallback { + + /** + * Called when the transport terminates. + * + * @param e The exception that led to the termination + */ + void onTermination(Exception e); + } class PendingRequest extends PendingSend { private final ReentrantLock lock = new ReentrantLock(); @@ -222,6 +235,7 @@ private final Thread sendThread; private final ExecutorService serverRequestExecutor; private final PendingRequestMap pendingRequestMap = new PendingRequestMap(); + private final TerminationCallback terminationCallback; /** * Create a new instance using the given streams and request processor. @@ -232,9 +246,27 @@ * @param requestProcessor a callback interface for handling remote client * requests */ + public MessageTransport(InputStream inputStream, OutputStream outputStream, + RequestProcessor requestProcessor) { + this(inputStream, outputStream, requestProcessor, null); + } + + /** + * Create a new instance using the given streams and request processor. + * Closing either stream will cause the termination of the transport. + * + * @param inputStream an input stream for reading messages + * @param outputStream an output stream for writing messages + * @param requestProcessor a callback interface for handling remote client + * requests + * @param terminationCallback a callback that is invoked when the transport + * terminates + */ public MessageTransport(final InputStream inputStream, - final OutputStream outputStream, RequestProcessor requestProcessor) { + final OutputStream outputStream, RequestProcessor requestProcessor, + TerminationCallback terminationCallback) { this.requestProcessor = requestProcessor; + this.terminationCallback = terminationCallback; serverRequestExecutor = Executors.newFixedThreadPool(DEFAULT_SERVICE_THREADS); // This thread terminates on interruption or IO failure @@ -396,5 +428,8 @@ private void terminateDueToException(Exception e) { pendingRequestMap.blockAdds(e); + if (terminationCallback != null) { + terminationCallback.onTermination(e); + } } } ======================================= --- /releases/2.0/dev/core/src/com/google/gwt/dev/shell/remoteui/RemoteUI.java Mon Nov 9 09:38:13 2009 +++ /releases/2.0/dev/core/src/com/google/gwt/dev/shell/remoteui/RemoteUI.java Tue Nov 10 11:13:04 2009 @@ -19,6 +19,8 @@ import com.google.gwt.core.ext.TreeLogger.Type; import com.google.gwt.dev.shell.BrowserListener; import com.google.gwt.dev.ui.DevModeUI; +import com.google.gwt.dev.ui.DoneCallback; +import com.google.gwt.dev.ui.DoneEvent; import com.google.gwt.dev.ui.RestartServerCallback; import com.google.gwt.dev.ui.RestartServerEvent; @@ -29,9 +31,13 @@ import java.util.List; /** - * TODO: Implement me. + * An implementation of a UI for the development mode server that sends UI + * events over the network to a remote viewer. Also receives commands from the + * remote viewer (such as a web server restart) and forwards the requests to the + * development mode server. */ -public class RemoteUI extends DevModeUI { +public class RemoteUI extends DevModeUI implements + MessageTransport.TerminationCallback { private final List<ModuleHandle> modules = new ArrayList<ModuleHandle>(); private final Object modulesLock = new Object(); @@ -51,9 +57,11 @@ this.webServerPort = webServerPort; Socket socket = new Socket(host, port); + socket.setKeepAlive(true); + socket.setTcpNoDelay(true); devModeRequestProcessor = new DevModeServiceRequestProcessor(this); transport = new MessageTransport(socket.getInputStream(), - socket.getOutputStream(), devModeRequestProcessor); + socket.getOutputStream(), devModeRequestProcessor, this); } catch (UnknownHostException e) { throw new RuntimeException(e); } catch (IOException e) { @@ -113,6 +121,16 @@ return handle; } + + public void onTermination(Exception e) { + getTopLogger().log( + TreeLogger.INFO, + "Remote UI connection terminated due to exception: " + + e.getLocalizedMessage()); + getTopLogger().log(TreeLogger.INFO, + "Shutting down development mode server."); + ((DoneCallback) getCallback(DoneEvent.getType())).onDone(); + } public boolean restartWebServer() { if (!supportsRestartWebServer()) { --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
