GWT-Gears: Sample code using WorkerPool ?

37 views
Skip to first unread message

fvisticot

unread,
Aug 3, 2008, 5:57:25 PM8/3/08
to Google Web Toolkit
I try to find a sample code/demo using WorkerPool object from the GWT-
Gears API ?
Can anyone help me ??

Miguel Méndez

unread,
Aug 4, 2008, 1:38:13 PM8/4/08
to Google-We...@googlegroups.com
We did not include a sample for that feature.  Primarily because all of the hooks are not in place for debugging in hosted mode.

We do have unit tests that show how the features can be used.  Just check out the  http://gwt-google-apis.googlecode.com/svn/trunk/gears/gears/test.
--
Miguel

fvisticot

unread,
Aug 4, 2008, 5:36:50 PM8/4/08
to Google Web Toolkit
Thanks a lot.
With your Test sample my test code is working now. I can process the
next step...

What i would like to do now is to integrate a background syncing
process (with WorkerPool) between the local Gear database and my Mysql
Database...

Without WorkerPool my synchronization is working. I'm using GWT-RPC to
exchange data between browser and server.

My Question:
How to add my syncing code in the Javascript string (i need to use a
GWT java method...)??

I would like to replace the WORKER_JS_SRC with a call to my java
method:

workerId = workerPool.createWorkerFromString(WORKER_JS_SRC);

private static final String WORKER_JS_SRC = ""
+ "function workerInit() {"
+ " google.gears.workerPool.onmessage = function(messageString,
srcWorkerId){"
+ " google.gears.workerPool.sendMessage('done',
srcWorkerId);"
+ " };" + "}" + "workerInit();";

I would like to use this java method instead...
public void sync() {
rpcKeepAlive =
(SyncServiceAsync)GWT.create(SyncService.class);
String rpcUrl = GWT.getModuleBaseURL() + "sync";
((ServiceDefTarget)rpcKeepAlive).setServiceEntryPoint(rpcUrl);

Timer t = new Timer() {
@Override
public void run() {
..sync code

}
};
t.scheduleRepeating(10000);
}


Regards,

Fred


On 4 août, 19:38, "Miguel Méndez" <mmen...@google.com> wrote:
> We did not include a sample for that feature.  Primarily because all of the
> hooks are not in place for debugging in hosted mode.
> We do have unit tests that show how the features can be used.  Just check
> out the  http://gwt-google-apis.googlecode.com/svn/trunk/gears/gears/test.
>

Sumit Chandel

unread,
Aug 7, 2008, 2:28:15 PM8/7/08
to Google-We...@googlegroups.com
Hi Fred,

Unfortunately, calling a GWT method from a worker thread is not possible. This is due to the fact that the worker threads operate in completely separate scopes from the global scope defined in your main GWT application. This restriction also extends to preventing worker threads from being able to access GWT RPC method invocations, and so worker threads cannot perform the full sync with the server-side.

However, worker threads are able to access other Gears APIs, including the Database API. This means that while you can't actually go ahead and communicate with the server during the sync process from within a worker thread, you can at least gather those items that need to be synced from the Gears local database and prep them for transport. Depending on how much data you expect to sync per interval, this could present a significant performance improvement for your application.

You could have the worker thread gather up all of the data that needs to be synced from the Gears database and pass that back to your worker pool to expose to the global scope. From there, you can serialize the data into the records that need to be synced and send it over the wire through the RPC call.

Hope that helps,
-Sumit Chandel

Miguel Méndez

unread,
Aug 8, 2008, 10:34:01 AM8/8/08
to Google-We...@googlegroups.com
Well, it is not impossible we just did not bundle all the pieces into a simple solution.
--
Miguel

Sumit Chandel

unread,
Aug 8, 2008, 6:27:05 PM8/8/08
to Google-We...@googlegroups.com
Actually, according to someone I spoke to Ben Lisbakken from the Gears team, it's currently impossible from the Gears perspective. I.E. You can't call JavaScript functions defined in your main application's domain from worker thread code.

@Fred: It seems like this is becoming more of a Gears issue rather than a GWT related problem, so I would suggest posting up on the Gears forum for even more perspective on what you're trying to do, and how you can accomplish it.


Hope that helps,
-Sumit Chandel

Reply all
Reply to author
Forward
0 new messages