java - GWT 中的代码服务器参数如何工作?

标签 java gwt gwt-hosted-mode gwt-dev-mode

在 GWT 中,为了在托管模式“开发模式”下运行应用程序,您可以将 get.codesvr 参数附加到 url 中,如下所示。

/?gwt.codesvr=127.0.0.1:9997

第一个问题是我想知道 GWT 如何知道何时启动 JVM 实例来提供 .class 文件而不是编译后的 JavaScript 文件?我似乎无法找到 GWT 在开发模式下如何工作。我确实在 com.google.gwt.devDevMode 中找到了 main( )。这个main()是如何调用的?

第二个问题是在文档中,它说 GWT devmode 与 Jetty 服务器一起运行,但是我在浏览器中看到了实际的 JavaScript。这个jetty服务器如何从客户端代码的.class文件输出JavaScript?

谢谢。

最佳答案

所有的魔法都是通过套接字和浏览器插件完成的。

Design: Out of Process Hosted Mode (OOPHM)

这是基本部分。

考虑以下 GWT 代码:

public class MyEntryPoint implements EntryPoint {
    private static native int jsniMethod() /*-{
      return 1;
    }-*/;

    public void onModuleLoad() {
      jsniMethod();
    }
  }

JavaScript: the browser plugin sends a LoadModuleMessage with the module name.

Java: the hosted mode server receives the LoadModuleMessage, loads the module and invokes the onModuleLoad in the corresponding EntryPoints. In this case MyEntryPoint::onModuleLoad is called. When MyEntryPoint is compiled, a LoadJsniMessage is sent to create browser-side JavaScript functions for each JSNI method, then when onModuleLoad invokes jsniMethod an InvokeMessage is sent.

JavaScript: This is the key part of the example. The JavaScript engine is currently awaiting a return from the LoadModuleMessage it sent, but it must be in a position to invoke the call to MyEntryPoint::jsniMethod on the same thread. This is accomplished by having the thread enter a read-and-dispatch routine following every remote invocation. In this case, the thread receives the LoadJsniMessage and InvokeMessage messages, invokes jsniMethod and sends a ReturnMessage containing the value 1.

Java: The read-and-dispatch routine receives the ReturnMessage and knows to return from the call to jsniMethod. Having fully executed the onModuleLoad method it sends a ReturnMessage and falls back into a top level read-and-dispatch loop. (Since all calls originate from the browser's UI event dispatch, only the hosted mode server needs to remain in a read-and-dispatch routine during idle time. The browser simply returns control by exiting the JavaScript function that was originally called.)

关于java - GWT 中的代码服务器参数如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18584387/

相关文章:

java - 找出哪个包调用服务

java - GET Activity 和地点 - EntryPoint 中的面板

gwt - 重新绑定(bind)错误 - EventBus 不能是抽象的?

java.lang.UnsupportedClassVersionError : Unsupported major. 次要版本 51.0

java - GWT 2.6.1 错误 : Could not find or load main class com. google.gwt.dev.GWTShell

java - 具有泄漏上下文的静态字段

java - 我可以使用 Spring Framework 分离 JDBC 读取和写入吗?

java - Android MP Chart highlightValue 不起作用,抛出 ArrayIndexOutOfBoundsException

java - gwt 序列化策略托管模式不同步

gwt - 如何自动将 gwt.codesvr 附加到页面 URL