简体   繁体   English

GWT中的codeserver参数如何工作?

[英]How does codeserver parameter in GWT work?

In GWT in order to run the application in hosted mode "dev mode" you append get.codesvr parameter to the url as you can see below. 在GWT中,为了在托管模式“开发模式”下运行应用程序,请将get.codesvr参数附加到URL,如下所示。

/?gwt.codesvr=127.0.0.1:9997 /?gwt.codesvr=127.0.0.1:9997

First question is I want to know how does GWT know when to start a JVM instance to serve .class files instead of compiled JavaScript files? 第一个问题是我想知道GWT如何知道何时启动JVM实例来提供.class文件而不是已编译的JavaScript文件吗? I can't seem to find how GWT works in dev mode. 我似乎找不到GWT如何在开发人员模式下工作。 I do find main( ) in com.google.gwt.devDevMode. 我确实在com.google.gwt.devDevMode中找到了main()。 How does this main( ) be called? 该main()如何调用?

Second question is in the documentation it says that GWT devmode run with Jetty server, however I see actual JavaScript in browser. 第二个问题是在文档中说GWT devmode与Jetty服务器一起运行,但是我在浏览器中看到了实际的JavaScript。 How does this jetty server outputs JavaScript from .class files of the client side code? 这个码头服务器如何从客户端代码的.class文件输出JavaScript?

Thanks. 谢谢。

All the magic done through Sockets and the Browser Plugin. 所有神奇的事情都是通过套接字和浏览器插件完成的。

Design: Out of Process Hosted Mode (OOPHM) 设计:进程外托管模式(OOPHM)

Here is the Essential part. 这是基本部分。

Consider the following GWT code: 考虑以下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. JavaScript :浏览器插件发送带有模块名称的LoadModuleMessage。

Java : the hosted mode server receives the LoadModuleMessage, loads the module and invokes the onModuleLoad in the corresponding EntryPoints. Java :托管模式服务器接收LoadModuleMessage,加载模块并在相应的EntryPoints中调用onModuleLoad。 In this case MyEntryPoint::onModuleLoad is called. 在这种情况下,将调用MyEntryPoint :: onModuleLoad。 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. 编译MyEntryPoint时,将发送LoadJsniMessage来为每个JSNI方法创建浏览器端JavaScript函数,然后,当onModuleLoad调用jsniMethod时,将发送InvokeMessage。

JavaScript : This is the key part of the example. JavaScript :这是示例的关键部分。 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. JavaScript引擎当前正在等待它发送的LoadModuleMessage返回,但是它必须能够在同一线程上调用MyEntryPoint :: jsniMethod的调用。 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. 在这种情况下,线程将接收LoadJsniMessage和InvokeMessage消息,调用jsniMethod并发送包含值1的ReturnMessage。

Java : The read-and-dispatch routine receives the ReturnMessage and knows to return from the call to jsniMethod. Java :读写调度例程接收ReturnMessage,并且知道要从对jsniMethod的调用中返回。 Having fully executed the onModuleLoad method it sends a ReturnMessage and falls back into a top level read-and-dispatch loop. 完全执行onModuleLoad方法后,它将发送ReturnMessage并退回到顶级读取和发送循环。 (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.) (由于所有调用都来自浏览器的UI事件分配,因此仅托管模式服务器在空闲时间需要保留在读取和分配例程中。浏览器只需退出最初调用的JavaScript函数即可返回控制。)

Adding the gwt.codesvr to the querystring is obviously not enough. gwt.codesvr添加到查询字符串显然是不够的。

First, you launch the DevMode ( com.google.gwt.dev.DevMode class), which launches an embedded Jetty server (unless you disabled it through the -noserver argument) and (more importantly) listens for your browser(s) (defaults to only the localhost network interface, on port 9997). 首先,您启动DevMode( com.google.gwt.dev.DevMode类),后者将启动嵌入式Jetty服务器(除非您通过-noserver参数禁用了它), 并且 (更重要的是)监听您的浏览器(默认设置) (仅在端口9997上的本地主机网络接口)。

Then you open your app in your browser with the gwt.codesvr pointing to the address and port the DevMode listens on. 然后,您在浏览器中打开您的应用程序,其中gwt.codesvr 指向 DevMode侦听的地址和端口。 When the *.nocache.js file loads, it detects the gwt.codesvr and loads devmode.html instead of your *.cache.html . 加载*.nocache.js文件时,它将检测gwt.codesvr并加载devmode.html而不是*.cache.html That code will load the GWT Dev Plugin that you installed in your browser (or tell you to install it) and direct it to connect to the DevMode at the address and port specified in the gwt.codesvr query-string argument. 该代码将加载您在浏览器中安装的GWT Dev插件(或告诉您安装它),并指示它在gwt.codesvr查询字符串参数中指定的地址和端口处连接到DevMode。

That way, your browser talks to the DevMode which loads your Java code and compiles and runs it in the JVM. 这样,您的浏览器便会与DevMode对话,后者会加载Java代码并在JVM中编译并运行它。 How that dialog works is described in the GWT wiki as already pointed out by Suresh. 如Suresh所指出,该对话框的工作方式已在GWT Wiki中进行了描述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM