Flow after RPC call in GWT?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | public Class GUi(){ // More Code public void onClick(ClickEvent event) { LoginServer loginServer =new LoginServer(getTextBoxUsername().getText(),getTextBoxPassword().getText()); loginServer.setConnection(connection); connection=loginServer.getConnection(); System.out.println(" connected"+connection); // More code } public class LoginServer { // more code public void setConnection(Boolean connection) { String[] authentication = {username,password}; //RPC call connectionService.connectionServer(authentication, callbackConnection); System.out.println("setConnection" + connection); } public Boolean getConnection() { return connection; } AsyncCallback callbackConnection = new AsyncCallback() { public void onFailure(Throwable caught) { // TODO Auto-generated method stub connection=false; } public void onSuccess(Object result) { connection=true; System.out.println("onSuccess + connection); } }; } |
输出
1 2 3 | setConnectionnull connected null onSuccesstrue |
根据我的输出应该是。
1 2 3 | onSuccesstrue setConnectiontrue connected null |
因为我创建了
然后我调用了方法
我也不明白为什么
当/如果您要您的妻子/女朋友为您带来啤酒,您问她之后第二秒钟就没有啤酒了,您可以继续观看比赛并做出反应,未被阻止等待您的啤酒:这称为异步处理。
类似地,在发送RPC调用后的第二秒,
请参阅https://groups.google.com/d/msg/Google-Web-Toolkit/-soVdfMGug8/vRmqIcAZ5zsJ
1 | setConnectionnull |
这是因为回调函数是异步执行的。也就是说,在响应从服务器到达浏览器之后,将调用此函数。但是代码的另一部分像
1 | connection=loginServer.getConnection(); |
立即执行,直到连接仍然为空。
谢谢,
Ganesh