Server Push in GWT

1,146 views
Skip to first unread message

Javid

unread,
Jul 13, 2006, 5:10:15 PM7/13/06
to Google Web Toolkit
Hi,
I know the feature of server pushing the data to the client is not
available as part of GWT. But, I did come across some Comet
Implementation with GWT and tried it. But, I am not sure if it would
work for me. I need to be able to send user-defined type objects back
to the client. I badly need this because now I am doing an recursive
poll on the server and my client and server CPU is maxed (NOT good at
all). Has anyone come across a reverse AJAX feature that I could use
with GWT. Is there any possibility that this feature would be supported
by the future releases of GWT?

Thanks for any help,
Javid

swecha

unread,
Jul 14, 2006, 2:01:45 AM7/14/06
to Google Web Toolkit
Not sure how to do server push.. but I am acheiving similar result by
making rpc calls at regular intervals as follow.

class XYZ
{
rpcData rd = null;

//method to get data from Server at regular intervals
private void getServerData() {

// the next two lines make a rpc request. see below for more on these
classes.
rd = new rpcData("serverdata");
Service.getData(rd);
static count=0;
Timer t = new Timer() {
public void run() {
if (rd.isReady()) {
String data = rd.getResponse();
// do something with data
rd = new rpcData("serverdata");
Service.getData(rd);
count=0;
if( for what ever reason you want to end..) {
cancel();
}
} else if( count++ == 0 ) {
//notihing happened for 10 sec.
Window.alert( "Server might be down");
}
}
};
t.scheduleRepeating(1000); // sleep 1 sec
}
}


class rpcData {
String request = null;
String response = null;
String error = null;

public rpcData( String req) {
request=req;
}
boolean isReady() {
if( response != null)
return true;
if( error != null)
return true;
return false;
}

void setResponse( String v) { response = v; }
void setError( String e) { error = e; }

String getRequest() { return request; }
String getResponse() { return response;}
String getError() { return error;}
}

class Service {

public static void getData( final rpcData rd ) {
XYZServiceAsync wcgAsync = (XYZServiceAsync)
GWT.create(XYZWCGService.class);

ServiceDefTarget endpoint = (ServiceDefTarget) wcgAsync;
endpoint.setServiceEntryPoint("/cg/wcg");

AsyncCallback callback = new AsyncCallback() {
public void onSuccess(Object result) {
rd.setResponse((String)result);
}
public void onFailure(Throwable caught) {
rd.setError("Error from Server");
}
};

wcgAsync.getService( rd.getRequest(), callback);
}
.}.

cole...@gmail.com

unread,
Jul 14, 2006, 8:41:08 AM7/14/06
to Google Web Toolkit
If you're worried about server CPU check out Jetty continuations:
http://www.mortbay.com/MB/log/gregw/?permalink=Jetty6Continuations.html

I'm doing what you call a "recursive" poll (which is not really
recursion) where the connection to the server remains open until the
server has some data to send and then closes it. It seems to be
working pretty well and with Jetty continuations you can have a fixed
number of threads, since it uses nonblocking NIO.

-Sam

cole...@gmail.com

unread,
Jul 14, 2006, 9:38:14 AM7/14/06
to Google Web Toolkit
Then again, Continuations might not work so well inside
RemoteServiceServlet since RemoteServiceServlet stores the request in a
ThreadLocal and the continuation could resume in a diferent thread.

Luca Masini

unread,
Jul 20, 2006, 9:15:22 AM7/20/06
to Google Web Toolkit

Espen

unread,
Aug 10, 2006, 12:28:04 PM8/10/06
to Google Web Toolkit
Thanks everybody, the trick with making the server "hold on" to the
request until data is ready, is really working beautifully for me.

In my project, several clients can submit data to the server, and I
want every client to immediately see everybody's submitted data.

I've used the following approach:
I make every client ask for data on startup.
On the server, I perform a test to check whether the client has all the
submitted data. If he has, i perform "this.wait();" in the code on the
server. This makes the client's thread sleep indefinately.
When new data is submitted by a client, "notifyAll();" is performed,
and all the awaiting requests (threads) are able to return the updated
data to their clients.

Using the "wait();" should ensure high performance, as the awaiting
threads don't perform any work and use no cpu while sleeping.

jordi.be...@gmail.com

unread,
Aug 25, 2014, 12:21:35 AM8/25/14
to google-we...@googlegroups.com, Google-We...@googlegroups.com
Doesn't that leak threads? When the client closes her browser your thread is still there waiting forever.
Reply all
Reply to author
Forward
0 new messages