By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,554 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,554 IT Pros & Developers. It's quick & easy.

Return from one method when another method is called

P: n/a
I have an http module (not made by me):

To connect to a server and send a request, there is a method like
this:

public void sendRequest(String query){
....
}

When the server responds, it calls another method in the same class:

public void respons(String results){
....
}
I want to combine these two methods so that my application can use one
method looking something like this:

public String sendRequest(String xml){
....
}

which returns the results. Is this possible?

I think it must be to include the second method someway in the first
method and wait for the respons, but I don't know how to do so.

To summarize, the problem is to make one method return something when
another method is called. I guess there are some smart ways around
this problem, but I haven't found any yet.
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I want to combine these two methods so that my application can use one
method looking something like this:
public String sendRequest(String xml){
...
}
which returns the results. Is this possible? I think it must be to include the second method someway in the first
method and wait for the respons, but I don't know how to do so.

To summarize, the problem is to make one method return something when
another method is called. I guess there are some smart ways around
this problem, but I haven't found any yet.


You'll need some object to lock on, so you can wait for the response.
However, in your current setup I cannot figure any way to wait for the
response. Please take a look at Mark Grand's "Future" design pattern at:

http://www.clickblocks.org/patterns1...ed.html#Future

This is an approach that worked for me; I needed to send multiple
requests to a site and await each response 'synchronously' in its own
thread and return the response to the caller. This design pattern
encapsulates sync/async issues (a bit more than you actually need) and
provides locking.

This all means you can call a method and receive its return variable as
if the communication went synchronously, even though the actual
communication was asynchronously.

Regards,

Joost van Stuijvenberg
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.