I have a question about the Observer patterne.
I have tried to implement it im my application but without result. First my idea was to save all the client Object references in A linked List in a bean on the server. Then each time a certain event ocurs on my server I will call a method fire() which iterate through my linked list and finds all my client references. Then I will make a "call back" to all the clients which are in my linked list. But my teacher tells my that is not the way to do. He belives that there is a much easier way to make sure that all the clients get updates. But he does't know how to do it. So my question is how do I implements Observer Design patterns in the J2ee enviroment ??
-
Obeserver Design Patterne. (7 messages)
- Posted by: Thomas W
- Posted on: October 10 2001 07:16 EDT
Threaded Messages (7)
- Obeserver Design Patterne. by Joost van de Wijgerd on October 10 2001 07:20 EDT
- Obeserver Design Patterne. by Thomas W on October 10 2001 07:58 EDT
-
Obeserver Design Patterne. by Cristina Belderrain on October 10 2001 11:30 EDT
- Obeserver Design Patterne. by Gal Binyamini on October 10 2001 06:59 EDT
-
Obeserver Design Patterne. by Thomas W on October 22 2001 01:44 EDT
-
Observer Design Pattern by Cristina Belderrain on October 22 2001 09:57 EDT
- Observer Design Pattern by Thomas W on October 26 2001 02:49 EDT
-
Observer Design Pattern by Cristina Belderrain on October 22 2001 09:57 EDT
-
Obeserver Design Patterne. by Cristina Belderrain on October 10 2001 11:30 EDT
- Obeserver Design Patterne. by Thomas W on October 10 2001 07:58 EDT
-
Obeserver Design Patterne.[ Go to top ]
- Posted by: Joost van de Wijgerd
- Posted on: October 10 2001 07:20 EDT
- in response to Thomas W
Read this excellent pattern article from Greg,
https://www.theserverside.com/patterns/ObserverPattern.jsp
It even has sample code, how easy can it be?
Joost. -
Obeserver Design Patterne.[ Go to top ]
- Posted by: Thomas W
- Posted on: October 10 2001 07:58 EDT
- in response to Joost van de Wijgerd
joost I have read this article. Greg uses a Set to save the references. But in his example he call update method on the Bean. What i need is a way to make a call back to all my clients and not the Bean. In RMI which is underneath the j2ee you use a interface whith a update method. The server use this interface to call a update method on the client. Is that possible in j2ee ?
Secondly My teacher claim that there should be a easier way to do this, instead of saving all the references in a Set. He claims that the j2ee enviroment has a better way to do this ? -
Obeserver Design Patterne.[ Go to top ]
- Posted by: Cristina Belderrain
- Posted on: October 10 2001 11:30 EDT
- in response to Thomas W
Hi Thomas,
first, I think you won't be able to call back a J2EE client using RMI, unless your client is a Java application. Even if it is an applet, the recommended design is to place a servlet between it and the EJB tier. That's because Web clients should talk to the server using HTTP, not RMI over IIOP (which is usually blocked by firewalls).
A better way to implement the Observer pattern under J2EE, in my opinion, is to make use of Message Driven Beans in publish-subscribe mode.
I think you'll need a stateful session bean to represent each client. The stateful session bean publishes a JMS message on behalf of the client. The message driven bean consumes the message and publishes the result. All clients subscribing to this topic will be notified about the just published result as if they were getting a call back.
Hope this helps,
Cris
-
Obeserver Design Patterne.[ Go to top ]
- Posted by: Gal Binyamini
- Posted on: October 10 2001 18:59 EDT
- in response to Cristina Belderrain
I would recommend you read Tyler Jewels's MDB book chapter available online before you attempt using Cristina's suggestion. There are a number of common gotcha's in implementing such an approach (as well as interesting, similar alternatives) and they are covered quite thoroughly.
Gal -
Obeserver Design Patterne.[ Go to top ]
- Posted by: Thomas W
- Posted on: October 22 2001 01:44 EDT
- in response to Cristina Belderrain
Cris would it be possible for you to show me some source code please. So far your suggestion seems to be a solotion to my problem eventhough it seems to be a little bit complicated. So if I see some code I would probearly be able to do it my self. :-)
RGDS
Thomas W -
Observer Design Pattern[ Go to top ]
- Posted by: Cristina Belderrain
- Posted on: October 22 2001 09:57 EDT
- in response to Thomas W
Hi Thomas,
first, I suggest you take a look at the MDB tutorial posted here at The Server Side:
https://www.theserverside.com/resources/article.jsp?l=Pramati-MDB
Then, you can also study the proto-pattern I sent to The Server Side a few months ago:
https://www.theserverside.com/resources/article.jsp?l=Message-Driven-Beans-And-Encapsulated-Business-Rules
Item 2.8, "Consequences and Related Ideas", explores a possible implementation of the Observer pattern using MDBs. Please notice it's just an idea: I haven't further developed and tested that code (although I will as soon as I have some spare time :-)).
Hope this helps,
Cris
-
Observer Design Pattern[ Go to top ]
- Posted by: Thomas W
- Posted on: October 26 2001 02:49 EDT
- in response to Cristina Belderrain
Cristina I have just one question. JSM works with the Bean but when it comes to the client - callback it seems not to be working.