I have a client that starts a long running process on the server. At regular intervals, I'd like to show the user what's happening in the background. The most simple approach is to poll the server but I'm wondering if there wasn't a way to implement the Observer pattern for this. Unfortunately, I'm using RMI to talk to the server and I fear that I have to turn my client into an RMI server for this.
Is there another way that I'm missing?
Overview In this tutorial, we'll describe the Observer pattern and take a look at a few Java implementation alternatives. 2. What Is the Observer Pattern? Observer is a behavioral design pattern. It specifies communication between objects: observable and observers. An observable is an object which notifies observers about the changes in its state.
When the change of a state in one object must be reflected in another object without keeping the objects tight coupled. When the framework we writes and needs to be enhanced in future with new observers with minimal chamges. Create a ResponseHandler1 class the will implement the java.util.Observer interface. //This is a class.
To define the observable, we need to extend Java's Observable class: Note that we don't need to call the observer's update () method directly. We just call setChanged () and notifyObservers (), and the Observable class will do the rest for us.
Observers register themselves to a subject to get a notification when there is a change made inside that subject. A observer object can register or unregister from subject at any point of time. It helps is making the objects objects loosely coupled. 1. When to use observer design pattern
RMI can in general support two way communication. (And yeah, RMI is a PITA to set up, and do anything else with.)
However, the HTTP transport that works over a CGI script(!) does not support it.
http://sites.google.com/site/jamespandavan/Home/java/sample-remote-observer-based-on-rmi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With