Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement the Observer pattern with Java RMI?

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?

like image 826
Aaron Digulla Avatar asked Jul 27 '09 12:07

Aaron Digulla


People also ask

What is the observer pattern in Java?

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 to implement the Observer interface in Java?

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.

How do I define an observable in Java?

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.

Why do observers register to a subject?

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


2 Answers

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.

like image 22
Tom Hawtin - tackline Avatar answered Sep 20 '22 06:09

Tom Hawtin - tackline


http://sites.google.com/site/jamespandavan/Home/java/sample-remote-observer-based-on-rmi

like image 193
blah Avatar answered Sep 18 '22 06:09

blah