Home arrow static arrow Java Programming [Archive] - module communication via reflection
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - module communication via reflection
10 Duke Stars available
This topic has 1 reply on 1 page.

Posts:14
Registered: 1/14/04
module communication via reflection  
Aug 2, 2004 1:17 AM



 
Morning all,

I need some urgent help on a reflection situation i have. here's the setup:

I have a "container" that has the ability to load modules or module groups these are typically jpanels that
perform some or other database processing.
My problem is this: I need these modules ( they are defined dynamically) to be able to talk to one another via the container i.e. module a sends a message to container that calls module b with this message. Module b performs some processing and returns an object to module a, again via the container.

The way i've tried to do this is define a JTextField and pass that reference to all the modules. Add a caret listener to the JTextfield in the container and voila. When module a calls textfield.setText the caret listener then fires and reads that string from the textfield. then it does some substringing and stuff to find out which object to call, calls it and returns the object. Only problem is that Java seems to lose the reference from which object the call is made. I.e. Module a does the .setText which fires the caretlistener, but somewhere along the line the container picks it up a module b doing the firing. You can imagine the havoc that ensues.

any help would be appreciated.

thanks

Nicholas
 

Posts:196
Registered: 6/24/97
Re: module communication via reflection  
Aug 2, 2004 4:00 AM (reply 1 of 1)



 
Looks like you have over-engineered the solution.

the problem is obvious: AWT/Swing use a set of worker threads for event processing. As are result your call stack will never show what is expected.

Consider using a standard method to solve your problem:

Implement an observer/observable pattern. Use a set of well defined interfaces - one for your publishers and one for the subscribers. (In your example, the modules would implement both the interfaces). The modules can then call a public method in the container that will dynamically find the module that needs to be called up.

Create a delegation model: A 'la AWT/SWING to do your event processing.
Use a ThreadReader/Writer between the modules.

Overall, a textfield is a poor interface for solving your problem. Search for a good website on patterns and find a pattern that exactly suits your problem scenario before trying to code a solution.
 
This topic has 1 reply on 1 page.