Baptiste, The short answer to "is it possible to code the worker in Java", is that we *think* it is possible. Unfortunately, we haven't tried it, and I wouldn't recommend it for anyone not very familiar with GWT.
Essentially the idea is to create another module for your worker thread. The single script linker would be used to create javascript output that you could then load with WorkerPool.createWorkerFromUrl(). As I said, this idea is untested and unsupported at this time. -- Note this section from the documentation at http://code.google.com/apis/gears/api_workerpool.html "Code and data isolation The WorkerPool behaves like a collection of processes, rather than threads. Workers do not share any execution state. Changing a variable in one worker has no effect in any other worker. And created workers do not automatically inherit script code from their parents. Members of a WorkerPool interact with each other only by sending message objects." This means that no matter Java GWT code or direct javascript, workers and the parent wouldn't be able to share code - each would have its own copy after the compiler ran. I will leave the rest of your question for others to comment on as I don't have a lot of experience - but I can say with more certainty that your JSNI callback from a worker thread is not going to work unless you go the single script linker route. On Mon, Sep 8, 2008 at 3:57 AM, Baptiste Boussemart <[EMAIL PROTECTED]> wrote: > > Thank you for your answer. > > = Intro = > > Before you read this long message, can you answer this question: Is it > possible to code the worker in Java? > If it is possible, forget the JSNI, PITA, etc. > > If not, I want to do a JSNI and JSNI callback to my Java methods, like > Jason's PITA (pre-GWT 1.5) > > = Body = > > Still, I am having some trouble. > > I tried a simpler example: > > private static final String WORKER_JS_SRC = "" > + "function workerInit() {" > + " google.gears.workerPool.onmessage = > function(messageString, > srcWorkerId){" > + " google.gears.workerPool.sendMessage('DONE', > srcWorkerId);" > + " };" + "}" + "return workerInit;"; > > public void start() { > // create a new worker thread to start generating primes > final int workerId = workerPool.createWorker(WORKER_JS_SRC); > panel.add(new Label(String.valueOf(workerId))); > workerPool.sendMessage("Test", workerId); > } > > Cool it works. Now I am sure that the signature is still > "function(messageString, srcWorkerId)". > > But maybe the number of arguments is variable in JavaScript. > > The "function(a, b, event)" may be compatible with > "function(messageString, srcWorkerId)", where "a" and "b" are > equivalent respectively to "messageString", "srcWorkerId" and "event" > is an object ("event.body" and "event.sender"), which comes from the > new Gears Worker implementation. > > As I am not sure, I keep "function(messageString, srcWorkerId)". > > > I tried, in the same way the JSNI method. > > private native String worker() /*-{ > function workerInit() { > google.gears.workerPool.onmessage = > function(messageString, > srcWorkerId){ > google.gears.workerPool.sendMessage('DONE', > srcWorkerId); > }; > } > return workerInit;"; > }-*/; > > It doesn't work. > > In the Chandel's message, the code is: > > private native String getSudokuGenerationFunction() /*-{ > function workerMessageHandler(msg, sender) { > try { > //computePrimes computes all primes for the number in > msg > var primes = computePrimes(msg); > gearsWorkerPool.sendMessage(primes, sender); > } catch(e) { > //take corrective action > } > } > var workerCode = String(workerMessageHandler) + ' > gearsWorkerPool.onmessage = workerMessageHandler'; > return workerCode; > }-*/; > > So I tried something alike: > > private native String worker() /*-{ > function workerMessageHandler(msg, sender) { > google.gears.workerPool.sendMessage('done', sender); > } > var workerCode = String(workerMessageHandler) + ' > gearsWorkerPool.onmessage = workerMessageHandler'; > return workerCode; > }-*/; > > Again, it doesn't work. > > > > It is hard to explain, but I tried many ways to do the JSNI method > explained in > http://groups.google.com/group/Google-Web-Toolkit/msg/4aec89cb494e56ce, > and I was not able to get this thing running. > > > In fact, I tried the very interesting work of Jason, the PITA. > But as his work is based on the old implementation pre-GWT 1.5 gwt- > google-api, I changed his code with GWT 1.5 gwt-gears, and it doesn't > work. > > This is why I want to be sure that the JSNI method works, as the PITA > uses also this method. > > > Also I read that it is not possible to do a JSNI callback from the > worker. > Is it always true now? > > = = > > I am not a JavaScript coder, but more a Java developer. > I am very interested in Gears to do applications with GWT (RIA), like > Eclipse does with its RCP. > > I developed some GWT applications with OSGi+Jetty. > > As Chrome has Gears embedded, I thought it was possible to do the same > thing without Jetty and OSGi. > > The main problem I have, it is the development of the worker, which > lacks in Java support. > > Again, as Chandel said: > *4*) Write it in Java code and have it "just work" as you would expect > without any setup tricks (currently planned for a future release of > gwt-google-apis) > > Is it always planned or have you something that works with Java? > > > You have done great work with GWT, Gears and Chrome (multi-threading). > I have, as many developers for a week, a great interest in your > technologies, because I think it is now possible to develop better, > online and offline, web applications. > > If it is possible to code the worker in Java, it would be great. > > Thanks. > > > -- Eric Z. Ayers - GWT Team - Atlanta, GA USA http://code.google.com/webtoolkit/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
