File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Design for intreraction between two unrelated modules. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Design for intreraction between two unrelated modules." Watch "Design for intreraction between two unrelated modules." New topic
Author

Design for intreraction between two unrelated modules.

john sal
Ranch Hand

Joined: Jul 30, 2010
Posts: 93
In my application there are two unrelated modules.

Now there is a scenario in which I want to send some notification from one module to another if some particular condition is met.

Using messaging service it is easy but we are not using it in our application.

How this can be implemted in java is there any particular API through which it can be achieved?

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

That depends. Do they run on the same machine? The same JVM? One way which I like is to open a socket connection between the two in the case they run on different JVMs.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
sourabh girdhar
Ranch Hand

Joined: Feb 10, 2010
Posts: 71

You can use socket as suggested by John.

You can also use plain java RMI. quite easy and simple method.


SCJP SCWCD AIX SOA
The significant problems we face cannot be solved by the same level of thinking that created them -- Albert Einstein

john sal
Ranch Hand

Joined: Jul 30, 2010
Posts: 93
It is on the same JVM.

Suppose there are two modules A and B and I want to send notification to B from A.

one way is to get the reference of B in A and invoke B's method but that is not the right
approach because i want to keep it generic and do not want to add any dependecies and more over
module B acts as pluggable component which may or may not be there.

Is there other approach for this or any design pattern which can be helpful?



Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

Publisher/subscriber.

Let A have a register method that accepts some sort of subscriber interface S (also known as a listener). A will keep track of a list of these subscribers.
When a change happens, A will then call the appropriate method in S of each subscriber.

B simply implements S, or has a helper class (tip: anonymous local class) that implements S and registers itself (or it's helper class) through A's register method.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Also see the Observer Pattern.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Design for intreraction between two unrelated modules.