Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: class interfacing to new server question

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Thanked 0 Times in 0 Posts

    Default 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!


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default 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.

Similar Threads

  1. Question concerning nextLine() method in Scanner Class
    By r_sardinas in forum Java SE APIs
    Replies: 2
    Last Post: October 20th, 2010, 08:35 PM
  2. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM
  3. Replies: 2
    Last Post: November 5th, 2009, 10:15 PM
  4. .class to .exe question
    By james137 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 3rd, 2009, 09:18 PM
  5. How to link two classes in java to use it method
    By Sterzerkmode in forum Object Oriented Programming
    Replies: 3
    Last Post: May 13th, 2009, 06:52 AM

Tags for this Thread