This discussion is archived
11 Replies Latest reply: Dec 16, 2011 3:34 PM by Owen Thomas RSS

Who sent this object?

Owen Thomas Newbie
Currently Being Moderated
Hi. Simple question; probably asked for the millionth time.

I appear to have encountered a situation where a program I am writing needs to know the source of a de-serialised object passed in as a parameter to a remote method call. I assume this can be done by overriding readObject, and putting the caller stub in a transient field of the de-serialised object, and accessing this field in the server as appropriate?

Is this a good way to do this? If so, could someone please provide code to show me how it is done? If not, can someone please provide code to show me how it is done properly?

Thanks,

Owen.
  • 1. Re: Who sent this object?
    EJP Guru
    Currently Being Moderated
    What exactly do you mean by 'source', and what exactly does the caller stub have to do with establishing it, and where exactly are you going to get the caller stub from at the server side during deserialization?

    Are you perhaps looking for RemoteServer.getClientHost()?
  • 2. Re: Who sent this object?
    Owen Thomas Newbie
    Currently Being Moderated
    EJP wrote:
    Are you perhaps looking for RemoteServer.getClientHost()?
    Hmmm...

    Yes, I believe I am.

    It returns a string. What does the string contain? How do I get the RemoteServer from within readObject?
  • 3. Re: Who sent this object?
    gimbal2 Guru
    Currently Being Moderated
    Owen Thomas wrote:
    EJP wrote:
    Are you perhaps looking for RemoteServer.getClientHost()?
    Hmmm...

    Yes, I believe I am.

    It returns a string. What does the string contain? How do I get the RemoteServer from within readObject?
    I know absolutely nothing about RMI, but that doesn't stop me from looking up the javadoc and seeing that getClientHost() is in fact static.
  • 4. Re: Who sent this object?
    Owen Thomas Newbie
    Currently Being Moderated
    gimbal2 wrote:
    I know absolutely nothing about RMI, but that doesn't stop me from looking up the javadoc and seeing that getClientHost() is in fact static.
    Ahh. Detail one might easily miss. Thanks.

    The Javadoc doesn't appear to say anything about what the string means... (?)
  • 5. Re: Who sent this object?
    EJP Guru
    Currently Being Moderated
    What does the string contain?
    It contains what it says in the Javadoc.
    How do I get the RemoteServer from within readObject?
    You don't need one as it's static, but why do you need it 'within readObject()' at all? Surely you only need it within the lifetime of the remote method?
  • 6. Re: Who sent this object?
    Owen Thomas Newbie
    Currently Being Moderated
    EJP wrote:
    What does the string contain?
    It contains what it says in the Javadoc.
    The javadoc to SE 6 goes into no greater detail than "a string representation of the client host". So, what does this mean? Does this method return the remote client's IP? URI? Something else that uniquely identifies the client process?
    How do I get the RemoteServer from within readObject?
    You don't need one as it's static, but why do you need it 'within readObject()' at all? Surely you only need it within the lifetime of the remote method?
    Indeed, I can probably call it from the remote method and use it there.
  • 7. Re: Who sent this object?
    gimbal2 Guru
    Currently Being Moderated
    Owen Thomas wrote:
    The javadoc to SE 6 goes into no greater detail than "a string representation of the client host". So, what does this mean?
    One could make the logical assumption that it is either the host name or the host IP. To have more proof, actually call the method and see for yourself.

    A small tip on finding information: simply paste what you seek information about into google. In this case I literally pasted "RemoteServer.getClientHost()" in there. After the obvious links to the javadocs, I also spotted some a link to an old bug report that literally mentions that the host IP address is returned in stead of the host name, while the latter would be more logical if you read the (agreed, vague) javadoc documentation.

    If all else fails: you are probably using an IDE. If you have it setup properly you can CTRL+click into JDK code. That way you can actually see the source code of the getClientHost() method and see what it calls under water, which gives you more ammunition for google/javadoc searches.
  • 8. Re: Who sent this object?
    Owen Thomas Newbie
    Currently Being Moderated
    gimbal2 wrote:
    Owen Thomas wrote:
    The javadoc to SE 6 goes into no greater detail than "a string representation of the client host". So, what does this mean?
    One could make the logical assumption that it is either the host name or the host IP. To have more proof, actually call the method and see for yourself.

    A small tip on finding information: simply paste what you seek information about into google. In this case I literally pasted "RemoteServer.getClientHost()" in there. After the obvious links to the javadocs, I also spotted some a link to an old bug report that literally mentions that the host IP address is returned in stead of the host name, while the latter would be more logical if you read the (agreed, vague) javadoc documentation.

    If all else fails: you are probably using an IDE. If you have it setup properly you can CTRL+click into JDK code. That way you can actually see the source code of the getClientHost() method and see what it calls under water, which gives you more ammunition for google/javadoc searches.
    Fair enough. I guess I'll have to check it for myself. Maybe the Javadoc is vague because this value might be dependent on the type of hardware and network the client and server use. I think that getClientHost might not give me what I need. I'd rather like an RMI stub from the caller, but my knowledge of RMI is limited by what I need to use it for. It appears that RMI doesn't create anything like a 'caller RMI stub', so I suppose I'll provide a process ID myself.

    More thought is required by me on this question, but I might have another answer available to me.

    Thanks to both of you for the tips.

    Edited by: Owen Thomas on Dec 16, 2011 5:17 AM
  • 9. Re: Who sent this object?
    gimbal2 Guru
    Currently Being Moderated
    Owen Thomas wrote:
    Fair enough. I guess I'll have to check it for myself. Maybe the Javadoc is vague because this value might be dependent on the type of hardware and network the client and server use. I think that getClientHost might not give me what I need. I'd rather like an RMI stub from the caller, but my knowledge of RMI is limited by what I need to use it for. It appears that RMI doesn't create anything like a 'caller RMI stub', so I suppose I'll provide a process ID myself.
    If I have to believe the bug report, it is only the host IP that is returned because that is the information the underlying socket provides. It was an old bug report (which I needed to lift from the Google cache), but Sun always hammered on backwards compatibility so I doubt they ever changed that behavior.
    but my knowledge of RMI is limited
    Shameless plug time: EJP actually wrote a book about it ;)

    http://www.amazon.com/java-TM-rmi-Remote-Invocation/dp/0201700433/
  • 10. Re: Who sent this object?
    EJP Guru
    Currently Being Moderated
    It appears that RMI doesn't create anything like a 'caller RMI stub'
    Not surprising, as you just invented it in this thread ;-)
  • 11. Re: Who sent this object?
    Owen Thomas Newbie
    Currently Being Moderated
    EJP wrote:
    It appears that RMI doesn't create anything like a 'caller RMI stub'
    Not surprising, as you just invented it in this thread ;-)
    It was a hunch that was proven wrong.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points