Calling GWT RPC code from WorkerPool

2 views
Skip to first unread message

fvisticot

unread,
Apr 15, 2009, 5:15:34 PM4/15/09
to Gears Users
I would like to call GWT RPC method from my worker pool for
synchronization process between dbs (client and server)
It seems that the WorkerPool can only call javascript file or text
script...

GWT purpose is to generate javascript as well so it is not possible
to:
1. develop the method/class to invoke in the WorkerPool with GWT.
2. compile this method with GWT compiler
3. call this method from the WorkerPool

Is there an other solution / feature planed for this problem ?

I have allready posted the question in the generic GWT forum:
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/b5c48639565e62c8/6604b47f8022a3fb#6604b47f8022a3fb

Fred

Jason Essington

unread,
Apr 16, 2009, 11:42:16 AM4/16/09
to gears...@googlegroups.com
I am going on some stale gears info here, but ...

On Apr 15, 2009, at 3:15 PM, fvisticot wrote:

>
> I would like to call GWT RPC method from my worker pool for
> synchronization process between dbs (client and server)
> It seems that the WorkerPool can only call javascript file or text
> script...
>
> GWT purpose is to generate javascript as well so it is not possible
> to:
> 1. develop the method/class to invoke in the WorkerPool with GWT.

yeah sure, create a new GWT module for each worker. there is a GALGWT
project that should have some Gears integration stuff in it.

> 2. compile this method with GWT compiler

yup, but you'll need to use the single script linker

> 3. call this method from the WorkerPool

That one is one that I'm not sure on. At one time it was possible to
issue XHR from a worker, but I was told that was a bug. I'm not sure
if worker XHRs have been added or not. I'm sure someone that is more
up to date on Gears can answer that one for you.

-jason

Eric Z. Ayers

unread,
Apr 17, 2009, 7:42:23 AM4/17/09
to Gears Users


On Apr 16, 11:42 am, Jason Essington <jason.essing...@gmail.com>
wrote:
> I am going on some stale gears info here, but ...
> On Apr 15, 2009, at 3:15 PM, fvisticot wrote:
>
>
>
> > I would like to call GWT RPC method from my worker pool for
> > synchronization process between dbs (client and server)
> > It seems that the WorkerPool can only call javascript file or text
> > script...
>
> > GWT purpose is to generate javascript as well so it is not possible
> > to:
> > 1. develop the method/class to invoke in the WorkerPool with GWT.
>
> yeah sure, create a new GWT module for each worker. there is a GALGWT  
> project that should have some Gears integration stuff in it.

In theory, it would be possible to use GWT to generate code for
workers in the worker pool, but I've never done it. If someone else
has, I'd love to hear about it. A new linker or manual trickery would
be needed to eliminate relying on browser load event logic, which is
inappropriate for WorkerPool threads.

> > 2. compile this method with GWT compiler
>
> yup, but you'll need to use the single script linker

Unfortunately, the reliance on browser events and window objects is
present even in the SingleScriptLinker, but you could probably work
around it.

> > 3. call this method from the WorkerPool
>
> That one is one that I'm not sure on. At one time it was possible to  
> issue XHR from a worker, but I was told that was a bug. I'm not sure  
> if worker XHRs have been added or not. I'm sure someone that is more  
> up to date on Gears can answer that one for you.

There is now a way to call an XHR using the HttpRequest object in
WorkerPool, but again, since I haven't written code in GWT for a
WorkerPool, I haven't tried to integrate GWT RPC.

Since GWT RPC is asyncronous, you could do the RPCs in the main thread
and then send the result data as messages to Worker threads.

-Eric.

Jason Essington

unread,
Apr 17, 2009, 11:58:07 AM4/17/09
to gears...@googlegroups.com
On Apr 17, 2009, at 5:42 AM, Eric Z. Ayers wrote:

On Apr 16, 11:42 am, Jason Essington <jason.essing...@gmail.com>
wrote:
I am going on some stale gears info here, but ...
On Apr 15, 2009, at 3:15 PM, fvisticot wrote:



I would like to call GWT RPC method from my worker pool for
synchronization process between dbs (client and server)
It seems that the WorkerPool can only call javascript file or text
script...

GWT purpose is to generate javascript as well so it is not possible
to:
1. develop the method/class to invoke in the WorkerPool with GWT.

yeah sure, create a new GWT module for each worker. there is a GALGWT  
project that should have some Gears integration stuff in it.

In theory, it would be possible to use GWT to generate code for
workers in the worker pool, but I've never done it.  If someone else
has, I'd love to hear about it.  

Yup, done that. but it was back after the first Google Developer day (right after Gears was announced). GWT was at version 1.4 (maybe in RC) I think, and linkers didn't really exist as such.
I ended up modifying the XS template to get the worker code.

When I first did this, it only took about a day to get it up and running, so I'd have to imagine that it'd be much easier now.

A new linker or manual trickery would
be needed to eliminate relying on browser load event logic, which is
inappropriate for WorkerPool threads.

2. compile this method with GWT compiler

yup, but you'll need to use the single script linker

Unfortunately,  the reliance on browser events and window objects is
present even in the SingleScriptLinker, but you could probably work
around it.

Well, this is the "don't shoot yourself in the foot" part. don't use window or any DOM methods ... which means no widgets or UI bits. but it is possible. but again, it is possible.


3. call this method from the WorkerPool

That one is one that I'm not sure on. At one time it was possible to  
issue XHR from a worker, but I was told that was a bug. I'm not sure  
if worker XHRs have been added or not. I'm sure someone that is more  
up to date on Gears can answer that one for you.

There is now a way to call an XHR using the HttpRequest object in
WorkerPool, but again, since I haven't written code in GWT for a
WorkerPool, I haven't tried to integrate GWT RPC.

Well that's good news. theoretically then we could sync in the background


Since GWT RPC is asyncronous, you could do the RPCs in the main thread
and then send the result data as messages to Worker threads.

Can objects now be passed to workers? if not, then performing the RPC in the main thread requires a second serialization/deserialization trip, (only this time both are done in javascript) to get the result into the worker

-jason

fvisticot

unread,
Apr 18, 2009, 4:47:02 PM4/18/09
to Gears Users
This discussion is very interesting and very promising !!!
Is there any sample code, prototype demonstrating this capability ??
I think that calling GWT code from Worker Pool would be an added value
for GWT applications !!!
Fred

Jason Essington

unread,
Apr 21, 2009, 11:50:17 AM4/21/09
to gears...@googlegroups.com
you could start here:
http://code.google.com/docreader/#p=gwt-google-apis&s=gwt-google-
apis&t=GearsGettingStarted

-jason

fvisticot

unread,
Apr 24, 2009, 10:33:48 AM4/24/09
to Gears Users
Jason,
I allready use the Gears for GWT API.
What is difficult for me to understand is how i could call GWT RPC
code from my WorkerPool.
Has you can see in the documentation the workerpool can only call
javascript file !!!! no GWT code !!!!

What i would like to do is to modify the WorkerPool demo provided by
the API:

private void doAsyncCalculation(int numDigits) {

if (workerPool == null) {
workerPool = Factory.getInstance().createWorkerPool();
primeWorkerId = workerPool.createWorkerFromUrl
("pi_spigot_worker.js");
workerPool.setMessageHandler(this);
}
workerPool.sendMessage("START " + numDigits, primeWorkerId);
}

I would like to replace the line:
primeWorkerId = workerPool.createWorkerFromUrl("pi_spigot_worker.js");

With somethink like that:
First Solution: Need to modify/recreate the WorkerPool architecture..
MyWorkerPool myWorkerPool = new MyWorkerPool();
//MyWorkerPool should implements an execute method where the code is
executed...
primeWorkerId = myWorkerPool.execute();

Second Solution:
1. Creating a Java file with the call to the GWT/RCP procedure (this
method will be calle by the worker pool)
2. Compile this java file to generate a .js file
3. Call this js file with input parameters
primeWorkerId = workerPool.createWorkerFromUrl(<generated-code.js>);

Can someone help me !!!

Jason Essington

unread,
Apr 24, 2009, 10:59:55 AM4/24/09
to gears...@googlegroups.com
Hi Fred,

Sorry, as I said, I've not really worked on this much lately due to
lack of time. however there is a fairly detailed discussion from a
couple of years ago when I first decided to get GWT modules to run as
workers.
http://groups.google.com/group/Google-Web-Toolkit-Contributors/browse_thread/thread/d70bdbaeffa597b4

Though the data there is undoubtably outdated, it might still be a bit
useful to you.

-jason

fvisticot

unread,
Apr 24, 2009, 12:11:33 PM4/24/09
to Gears Users
Very interesting !!! i need to understand more in details but very
good discussions.
I will try to create a prototype...

Keep you posted

Fred

On Apr 24, 4:59 pm, Jason Essington <jason.essing...@gmail.com> wrote:
> Hi Fred,
>
> Sorry, as I said, I've not really worked on this much lately due to  
> lack of time. however there is a fairly detailed discussion from a  
> couple of years ago when I first decided to get GWT modules to run as  
> workers.http://groups.google.com/group/Google-Web-Toolkit-Contributors/browse...
Reply all
Reply to author
Forward
0 new messages