shaungyuehuoniao / gwt-ext

Automatically exported from code.google.com/p/gwt-ext
0 stars 2 forks source link

PubSub not working correctly, only one subscriber sees the published message #457

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Simplified example:

package xxx.Topclass;

import com.gwtext.client.pagebus.PageBus;
import com.gwtext.client.pagebus.SubscriptionCallback;

import xxx.FirstClass;
import xxx.SecondClass;
import xxx.StaticMessageTopics;

public class TopClass {
    private FirstClass = new FirstClass();
    private SecondClass = new SecondClass();

    public TopClass {
            PageBus.subscribe(StaticMessageTopics.TEST_TOPIC, new 
SubscriptionCallback() {  
                public void execute(String subject, Object message) {                 
                    System.out.println("TopClass recieved published 
method");
                    }  
            }); 

        // set up stuff

        // set up listener from webserver
        handleServerMessage();  
    }

    public void handleServerMessage(Object message) {
        PageBus.publish(StaticMessageTopics.TEST_TOPIC, message);
    }
}

package xxx.FirstClass

import com.gwtext.client.pagebus.PageBus;
import com.gwtext.client.pagebus.SubscriptionCallback;

public class FirstClass {
    public FirstClass {
            PageBus.subscribe(StaticMessageTopics.TEST_TOPIC, new 
SubscriptionCallback() {  
                public void execute(String subject, Object message) {                 
                    System.out.println("FirstClass recieved published 
method");
                    }  
            });

    }
}

package xxx.SecondClass

import com.gwtext.client.pagebus.PageBus;
import com.gwtext.client.pagebus.SubscriptionCallback;

public class SencondClass {
    public SecondClass {
            PageBus.subscribe(StaticMessageTopics.TEST_TOPIC, new 
SubscriptionCallback() {  
                public void execute(String subject, Object message) {                 
                    System.out.println("SecondClass recieved published 
method");
                    }  
            });

    }
}

*****************
now when I run my app - the console will only show:
SecondClass recieved published method

I actually have more classes that want to subscribe.  Further, in my code, 
the TopClass doesn't subscribe for the message its publishing, but when I 
was debugging, I thought I would give it shot and saw that even it didn't 
successfully recieve the message it had published.  In addition, I've 
noticed that the SecondClass may not always be the one that gets the 
message, for example, the FirstClass may successfully get it first (but be 
the only one that sees it).  I had even tried letting every class that 
subscribed, re-publish the subject and got a stack overflow exeception.  
Now my classes have a lot more substance to them, is it possible something 
else (like toastwindow) might interfere w/ pubsub?  Lastly, just for 
completeness, my TopClass.gwt.xml and TopClass.html have all the correct 
reference including <inherits name="com.gwtext.Pagebus"/>

What is the expected output? What do you see instead?
The console should show (not in this exact order): 
TopClass recieved published method
FirstClass recieved published method
SecondClass recieved published method

What version of the product are you using? On what operating system?
I have gwtext 2.0.5 and running on vista

Please provide any additional information below.
I can give more details if needed

Original issue reported on code.google.com by eirmos...@gmail.com on 14 Nov 2008 at 4:46

GoogleCodeExporter commented 8 years ago
I figured out the problem and its rather tricky as no exceptions were being 
thrown.  
One of the classes that would handle a subscriber message was not experiencing 
an 
unhandled exception.  The class was to update a store object by adding a 
record.  It 
was calling store.addsort() which I thought would default to add if no sort was 
applied.  However, an unhandled exception was being thrown.  Which stopped the 
pubsub 
from continuing to publish the message to the rest of the subscribers.

Original comment by eirmos...@gmail.com on 14 Nov 2008 at 9:10