class interfacing to new server question
Hi Guys
I am a bit unclear on what the best approach is given the following scenario:
I have a program I am writing which needs to interface to my server and database. To do so, I have written a ServerRequest class (actually its an interface with an implementation and a factory class to instantiate... although for the purposes of this question, I don't think that makes a difference)
Other classes instantiate the ServerRequest class and make various requests to the server through it. The ServerRequest class creates a new thread, and handles the http request.
Unfortunately, I need my listener for the server's response to be from the original class which had the ServerRequest instance, and not the ServerRequest class itself. Barring that, I would still need to get the information back to the original class from the ServerRequest.
In other languages, I would simply pass a function from the original class to the ServerRequest class to be the listener. However, I don't think that is practical in Java.
Can anyone point me in the right direction for the best way to attack this?
Thanks in advance!
Avtar
Re: class interfacing to new server question
This has been cross-posted at:
class interfaces to server. Cross-posting is not against the rules of this forum, but I will point you in the direction of some explanations for why cross-posting is frowned upon here.
With server client communication, you must be careful to pass listeners between the two, as the server/client contain different references to the same object values but not the same object. Listeners must somehow manage communication between the two, the simplest is to require the server method to return a value/object. If you have a long running task, use something like a MessageDriven bean.