Results 1 to 4 of 4
- 01-08-2011, 09:51 AM #1
Event, Message based communication
Friends,
There are 2-3 modules in my java project. UI module creates some events which I need to propagate to Logic module where "what to do next" is decided.
Logic module has a thread running and can take care of multiple such Events/Messages that come from other modules.
I want to use Message (i.e. ID, object) based communication between these modules.
Is there any pattern-based or standard method I can follow?
I know JMS (Java message servicing) is very bulky - for P2P communication - and not for this small program. So that is not the solution.
Regards,
PG
- 01-08-2011, 06:24 PM #2
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Its actually a very common design pattern. Usually, what you do is create a listener interface, which is implemented by classes that need to know about events. The class that is being listened to would provide an addXXXListener method, and probably a removeXXXListener method as well, and send the appropriate events to the listeners. The pattern is used by your UI as well, if you're using ActionListener, which I would guess is the case.
Many of my projects now hit at least 5 xxxListener interfaces, just for core UI components to ensure that they update on time.
In your case, as your logic module is running on a different event, you'll want the listener methods to queue events to be handled by the logic thread. However, unless your calculations to decide what to do next can take a long time, I'd suggest getting rid of that extra thread, as it will just complicate your code.
Finally, there is another pattern, as used by Java NIO with its selectors. That one you'll have to look up, as its much more complicated. It only works with multiple threads.If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
- 01-08-2011, 06:31 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Please don't double post: standard communication protocol among modules
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-08-2011, 06:43 PM #4
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Similar Threads
-
i need an example of JSR179 ((Location based Ser)implementation for CDC based device
By talk_to_vivekmishra in forum CDC and Personal ProfileReplies: 3Last Post: 12-30-2010, 10:07 AM -
java message box, how to not show multiple message box with same title or content
By oohay in forum AWT / SwingReplies: 6Last Post: 06-04-2010, 08:43 PM -
java based implementation on serial communication
By xll in forum Threads and SynchronizationReplies: 1Last Post: 12-08-2009, 07:45 AM -
Entity - Field-Based Access Vs Property Based Access
By CatchSandeepVaid in forum Enterprise JavaBeans (EJB)Replies: 3Last Post: 11-02-2009, 07:18 PM -
difference between code based security and role based security
By boy22 in forum New To JavaReplies: 1Last Post: 07-23-2007, 11:59 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks