473,385 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Return from one method when another method is called

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
1 2243
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: w i l l | last post by:
Why does this work the way it does? If someone could explain return true, and return false to me I'd greatly appreciate it. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ...
94
by: John Bailo | last post by:
The c# *return* statement has been bothering me the past few months. I don't like the fact that you can have different code paths in a method and have multiple return statements. To me, it...
1
by: Jack Addington | last post by:
I have a 3rd party object that fires an itemchanged event when someone edits some data on a form. This event has a custom eventArgs that has a field called ActionCode. In the code of the event,...
10
by: geoffblanduk_nospam | last post by:
Just curious, we no longer require void on a method that takes no parameters; void methodWithNoParameters(void) has been replaced by void methodWithNoParameters(). Is there a good reason we...
59
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
46
by: Steven T. Hatton | last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it says. http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html <shrug> -- NOUN:1. Money or...
12
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I have a class which "BiologySequence" which looks about like this. public class BiologySequence { private string _Sequence; public string Sequence {
5
by: .rhavin grobert | last post by:
guess you have the following classes... ___________________________________ class { //..a couple of methods ...// }; class A { public: //...// B* GetB() // <- this we'll talk about
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.