Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Java
Expertise: Intermediate
Jun 25, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Identify Host That Called Remote Method

When creating remote objects for use with Java's Remote Method Invocation (RMI), you'll often extend java.rmi.server.UnicastRemoteObject. When you do extend UnicastRemoteObject, it becomes easy for the remote methods to determine the host name of the caller. This can be useful for security or logging purposes, as it allows you to limit and/or record which hosts perform remote method calls. To identify the host that called a particular method, use the getClientHost() method. For example:

public void myRemoteMethod() {
try {
String client = getClientHost();
System.out.println("Called by " + client);
}  //  try
catch (ServerNotActiveException snae) {
		System.out.println("Server not active");
}  //  catch (ServerNotActiveException snae)
}  //  public void myRemoteMethod()

The getClientHost() method returns a String instance containing the name of the host which called the method. This allows you to easily determine where remote method calls originate from and to implement auditing or security which stores or processes that information.

Brett Spell
Thanks for your registration, follow us on our social networks to keep up-to-date