Re: [gwt-contrib] Synchronous RPC

2012-02-28 Thread John Tamplin
On Tue, Feb 28, 2012 at 12:02 PM, Deepak Patil deepakpati...@gmail.comwrote:

 any comments about this ?


Sorry, digging through the generated JS code is hard to follow, and there
are library functions referenced but not included that would help clarify a
few things.

If I understand correctly, the gist is to pass a state variable to each
callback, and by that value it knows which piece of code to execute, is
that correct?  That would also mean having to wrap all calls from
non-generated code, which is what I assume those missing library functions
do.

If that is correct, it is an interesting approach, though it does have some
cost.

-- 
John A. Tamplin
Software Engineer (GWT), Google

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

[gwt-contrib] Synchronous RPC

2012-02-20 Thread Deepak Patil
(Author of openwaf.com)

Using asynchronous RPC (GWT.runAsync) forces developer to split there code 
int two parts. It becomes difficult if you want to do some sequential RPC .
I understand Single threaded browser architecture wont allow us to easily 
execute synchronous RPC.

For example to get time from the server using RPC code looks time below 

   

TimerService.getTime(new AsyncCallbackString() {
public void onSuccess(String result) {
lblASync.setText(lblASync.getText()+Result 1:+result+br/);
}
public void onFailure(Throwable caught) {

 }
});

  Here response code goes in onSuccess method.

Just for example we want to get the server time twice synchronously. code 
will look like this

**

*TimerService.getTime(new AsyncCallbackString() {*
   public void onSuccess(String result) {

   lblASync.setText(lblASync.getText()+Result 1:+result+br/);

*   TimerService.getTime(new AsyncCallbackString() {*
 public void onSuccess(String result) {
lblASync.setText(lblASync.getText()+Result 
1:+result+br/);
 }
 public void onFailure(Throwable caught) {}
   });

} public void onFailure(Throwable caught) {} });


Code looks complicated now. Now imagine if we can write simple code like 
below.


lblSync.setText(lblSync.getText()+Result 
1:+TimerService.getTime()+br/);

lblSync.setText(lblSync.getText()+Result 
2:+TimerService.getTime()+br/);


Which does the same thing of the code above this.

I found a workaround for this. We can simulates synchronous RPC using 
asynchronous http requests. Where program is *logically* blocked till you 
receive any response  from the server. 

This is well tested for statements like for,while,if else.

Here compiler takes care of the generating some additional code which will 
return from the function when RPC is made and resume the code at 
appropriate location where it was blocked.

For more details please check  http://openwaf.com/ExRPCSyncAsync.jsp 
http://openwaf.com


You can have a quick look at code below to find a difference

public class ExRPCSyncAsync extends WAFController{
@ViewElement
public Button btnSync;
@ViewElement
public Button btnASync;
@ViewElement
public Label lblSync;
@ViewElement
public Label lblASync;
public ExRPCSyncAsync(){
btnSync.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
startSyncCalls();
}
});
btnASync.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
startASyncCalls();
}
});
}
public void startSyncCalls(){
lblSync.setText();
lblSync.setText(lblSync.getText()+Call 1br/);
lblSync.setText(lblSync.getText()+Result 
1:+TimerService.getTime()+br/);
lblSync.setText(lblSync.getText()+Call 2br/);
lblSync.setText(lblSync.getText()+Result 
2:+TimerService.getTime()+br/);
lblSync.setText(lblSync.getText()+Call 3br/);
lblSync.setText(lblSync.getText()+Result 
3:+TimerService.getTime()+br/);
lblSync.setText(lblSync.getText()+Call 4br/);
lblSync.setText(lblSync.getText()+Result 
4:+TimerService.getTime()+br/);


}
public void startASyncCalls(){
lblASync.setText();
lblASync.setText(lblASync.getText()+Call 1br/);
TimerService.getTime(new AsyncCallbackString() {
public void onSuccess(String result) {
lblASync.setText(lblASync.getText()+Result 1:+result+br/);
}
public void onFailure(Throwable caught) {}
});

lblASync.setText(lblASync.getText()+Call 2br/);
TimerService.getTime(new AsyncCallbackString() {
public void onSuccess(String result) {
lblASync.setText(lblASync.getText()+Result 2:+result+br/);
}
public void onFailure(Throwable caught) {}
});

lblASync.setText(lblASync.getText()+Call 3br/);
TimerService.getTime(new AsyncCallbackString() {
public void onSuccess(String result) {
lblASync.setText(lblASync.getText()+Result 3:+result+br/);
}
public void onFailure(Throwable caught) {}
});

lblASync.setText(lblASync.getText()+Call 4br/);
TimerService.getTime(new AsyncCallbackString() {
public void onSuccess(String result) {
lblASync.setText(lblASync.getText()+Result 4:+result+br/);
}
public void onFailure(Throwable caught) {}
});
}
}








-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Re: [gwt-contrib] Synchronous RPC

2012-02-20 Thread John Tamplin
On Mon, Feb 20, 2012 at 4:05 AM, Deepak Patil deepakpati...@gmail.comwrote:

 (Author of openwaf.com)

 Using asynchronous RPC (GWT.runAsync) forces developer to split there code
 int two parts. It becomes difficult if you want to do some sequential RPC .


BTW, runAsync is totally different from RPC -- it is about code splitting,
so only the code needed for the initial app is downloaded in the initial
download.


 I understand Single threaded browser architecture wont allow us to easily
 execute synchronous RPC.

 For example to get time from the server using RPC code looks time below




 TimerService.getTime(new AsyncCallbackString() {
 public void onSuccess(String result) {
 lblASync.setText(lblASync.getText()+Result 
 1:+result+br/);
 }
 public void onFailure(Throwable caught) {

  }
 });

   Here response code goes in onSuccess method.

 Just for example we want to get the server time twice synchronously. code
 will look like this

 **

 *TimerService.getTime(new AsyncCallbackString() {*
public void onSuccess(String result) {

lblASync.setText(lblASync.getText()+Result 1:+result+br/);

 *   TimerService.getTime(new AsyncCallbackString() {*
  public void onSuccess(String result) {
 lblASync.setText(lblASync.getText()+Result 
 1:+result+br/);
  }
  public void onFailure(Throwable caught) {}
});

 } public void onFailure(Throwable caught) {} });


 Code looks complicated now. Now imagine if we can write simple code like
 below.



 lblSync.setText(lblSync.getText()+Result 
 1:+TimerService.getTime()+br/);

 lblSync.setText(lblSync.getText()+Result 
 2:+TimerService.getTime()+br/);


 Which does the same thing of the code above this.

 I found a workaround for this. We can simulates synchronous RPC using
 asynchronous http requests. Where program is *logically* blocked till you
 receive any response  from the server.

 This is well tested for statements like for,while,if else.

 Here compiler takes care of the generating some additional code which will
 return from the function when RPC is made and resume the code at
 appropriate location where it was blocked.

 For more details please check  http://openwaf.com/ExRPCSyncAsync.jsp
 http://openwaf.com


The web site doesn't give implementation details, but I assume it is by
rewriting the synchronous call to be continuation-passing.  Ie:

function f() {
  block1;
  x1 = asyncCall1();
  block2;
  while (asyncCall2()) {
block3;
  }
  return retval;
}

gets rewritten to:

function f(retCallback) {
  block1;
  asyncCall1(function(x1) {
block2;
loop = function(val) {
  if (val) {
block3;
asyncCall2(loop);
  } else {
retCallback(retval);
  }
};
asyncCall2(loop);
  }
}

The problem with doing this in general is that basically every call in the
app has to be rewritten in this form (if any of them might ever call an
async method), and you wind up with stack depth problems unless the VM has
tail-call elimination (which JS doesn't).

Chaining of async calls is awkward, and I don't think it is a solved
problem yet.

-- 
John A. Tamplin
Software Engineer (GWT), Google

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors