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

    Default standard communication protocol among modules

    Friends,

    I got 2-3 modules in my java project.
    UI module creates some events.
    Logic module has to collect and take actions based on these events.
    FieldEnabler module has to enable-disable fields based on actions chosen by Logic module.

    What shall I use to communicate among these modules.
    Is there any pattern-based or standard method I can follow?
    Any existing framework that I can reuse?

    Regards,
    PG

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,450
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by a1prashant View Post
    Friends,

    I got 2-3 modules in my java project.
    UI module creates some events.
    Logic module has to collect and take actions based on these events.
    FieldEnabler module has to enable-disable fields based on actions chosen by Logic module.

    What shall I use to communicate among these modules.
    Is there any pattern-based or standard method I can follow?
    Any existing framework that I can reuse?
    You're already using a pattern: the Observer/Observable pattern, the UI component(s) are the Observable(s), the listener(s) are the Observer(s). What more do you want?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    a1prashant's Avatar
    a1prashant is offline Member
    Join Date
    Jan 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks for reply,

    well, I understand that I use Observer pattern here.
    I want to know the communication-mechanism that can be used.

    What I want to use is a standard communication protocol / framework.
    A rough idea I've in mind is I would like a Message having a structure
    { id,
    object-it can be either of type boolean / rectangle / button / string / any
    }

    any java-framework or pattern - matching similar solution?

    Regards,
    PG

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

    Default

    I am not sure if I've posted the problem correctly.

    I want something similar to what light version of SOAP (though not XML based totally) would provide. This I should be able to use within modules of a single program running in single process boundary.

    Please help

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

    Default

    I posted this in the thread you posted in New to Java, but I'll copy it here too. Please don't double-post. It drives us nuts trying to track down what has actually been said. Anyway, here it is:

    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!

  6. #6
    a1prashant's Avatar
    a1prashant is offline Member
    Join Date
    Jan 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks Jos and Boyo

    @Boyo: Yes, I've xxxxlistener method used for catching UI events
    There are about 20-30 such events that my UI module would generate
    Each of these have to work on 'message-id & a reference-object-of-some-type'
    So I explored and found something about Proxy classes.
    Something really neutral implementation which I can use directly in my program for transferring 'Message-Object (having id&object)' I'm looking for...

  7. #7
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    It would be unusual to use a serialized messaging system (such as SOAP) to communication inside a process. If you want to abstract away the details of the source, then use an interface and have all your calling classes implement it. That's the way events work in Java, and your code will be very odd (aka unmaintainable) if you try to do something different.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,450
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by a1prashant View Post
    Thanks Jos and Boyo

    @Boyo: Yes, I've xxxxlistener method used for catching UI events
    There are about 20-30 such events that my UI module would generate
    Each of these have to work on 'message-id & a reference-object-of-some-type'
    So I explored and found something about Proxy classes.
    Something really neutral implementation which I can use directly in my program for transferring 'Message-Object (having id&object)' I'm looking for...
    Those listeners don't have to handle the events themselves; they can always delegate the stuff to other methods. Of course you want that delegation done in a more or less uniform way; the event listeners shoudl 'mould' the event in some standard form and pass that around to the other methods.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. modules in notepad
    By joypik in forum New To Java
    Replies: 6
    Last Post: 11-22-2010, 05:47 PM
  2. how many modules?
    By joypik in forum New To Java
    Replies: 13
    Last Post: 08-04-2010, 04:46 AM
  3. Inventory book store -Modules
    By saran87 in forum New To Java
    Replies: 2
    Last Post: 08-24-2009, 02:14 PM
  4. can you recommand site for java modules - (free)
    By itaipee in forum New To Java
    Replies: 3
    Last Post: 01-20-2009, 12:18 PM
  5. Creating J2ee Modules In NetBeans IDE
    By JavaForums in forum NetBeans
    Replies: 0
    Last Post: 07-30-2007, 11:13 PM

Posting Permissions

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