This isn't easy to do because the GWT compiler is going to obfuscate all of
the symbols, making the different applications unable to call each other,
even if they have some Java types (interfaces, classes) in common.
You can however use JSNI to register native callbacks and invoke them from a
single GWT application which handles the comet connection. What I'm talking
about is doing something like this:
/** Extend this in each portlet GWT application */
public abstract class SharedCallback {
public SharedCallback() {
install();
}
public abstract void onMessage(JavaScriptObject obj);
private native void install()/*-{
$wnd.add_shared_callback(function(r) {
[EMAIL PROTECTED]::onMessage(Lcom/google/gwt/core/client/JavaScriptObject;)(r);
};
}-*/;
}
/** Define this in the "manager" application */
public class CallbackSet {
private static ArrayList<JavaScriptObject> funs = new ArrayList();
static {
setup();
}
public static void add(JavaScriptObject f) {
funs.add(f);
}
public static void dispatch(JavaScriptObject in) {
for (JavaScriptObject f : funs)
call(f, in);
}
private static native void setup()/*-{
$wnd.add_shared_callback =
@com.you.CallbackSet::add(Lcom/google/gwt/core/client/JavaScriptObject;);
}-*/;
private static native void call(JavaScriptObject f, JavaScriptObject
arg)/*-{
f(arg);
}-*/;
}
You'll need to ensure CallbackSet is initialized before any SharedCallback
actually gets created, and the data you pass over that shared comet
connection will need to be some native JSON structure like a string, or a
JSON object. You can use JSNI and extend JavaScriptObject inside each
application to get access to the data fields, but you won't be able to use
the GWT RPC serialization system to read the result that is coming in.
I also left as an exercise for the reader to de-register SharedCallbacks
after they have been added to the global list; failing to remove them would
cause a portlet application to never GC in the browser even if its UI was
removed.
I also didn't filter the messages into specific applications, or anything
like that. Another exercise for the reader. The code above just blindly
broadcasts everything to every application when dispatch() gets invoked.
So its possible to do, but you need to do some leg-work yourself to keep the
applications separate GWT modules.
On Wed, Dec 3, 2008 at 15:07, [EMAIL PROTECTED] <[EMAIL PROTECTED]
> wrote:
>
> Just a small background on what I'm doing.
>
> I'm writing JSR-286 portlets, mostly using GWT. I'm taking advantage
> of the newer portlet eventing features and having them distributed to
> the GWT portlets in real time, using a Comet implementation similar to
> what is shown in the book "Google Web Toolkit Applications" by Ryan
> Dewsbury. In my current implementation, I have a comet servlet set up
> for each GWT portlet.
>
> It's easy to see what the problem is. Right now I only have two GWT
> portlets developed, so there are two comet servlets being connected to
> at the same time. The load is not so bad with just two applications,
> but the portal will expand with new applications in the coming days.
> Six comet connections at a time per user is a very bad idea, so I want
> to cut it down to just one connection per user.
>
> Implementing a comet servlet with a multiple "channel" support for
> each kind of GWT app in the portal will be the easy part. What I want
> to do, however, is set up a single GWT application on the portal page
> that will handle the comet connection and let other, separate GWT
> applications communicate with it, receiving any new events the apps
> subscribed for.
>
> What I want to know is if it is possible to have two complete seperate
> GWT applications, served on the same HTML page, communicate with each
> other within the browser?
>
> I know I could aggregate all GWT applications into one but that is not
> the goal of the project. They absolutely require to be portlets.
>
> Thanks.
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---