Results 1 to 4 of 4
  1. #1
    a1prashant's Avatar
    a1prashant is offline Member
    Join Date
    Jan 2011
    Posts
    5
    Rep Power
    0

    Default 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

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    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!

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,350
    Blog Entries
    7
    Rep Power
    20

    Default

    Please don't double post: standard communication protocol among modules

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Hmm... I think I'll copy mine into the one in advanced java. This could get complicated...

    Thanks for the warning Jos.
    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!

Similar Threads

  1. i need an example of JSR179 ((Location based Ser)implementation for CDC based device
    By talk_to_vivekmishra in forum CDC and Personal Profile
    Replies: 3
    Last Post: 12-30-2010, 10:07 AM
  2. Replies: 6
    Last Post: 06-04-2010, 08:43 PM
  3. java based implementation on serial communication
    By xll in forum Threads and Synchronization
    Replies: 1
    Last Post: 12-08-2009, 07:45 AM
  4. Entity - Field-Based Access Vs Property Based Access
    By CatchSandeepVaid in forum Enterprise JavaBeans (EJB)
    Replies: 3
    Last Post: 11-02-2009, 07:18 PM
  5. Replies: 1
    Last Post: 07-23-2007, 11:59 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •