Thanks for any help,
Javid
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);
}
.}.
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 ha scritto:
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.