Source file:
/**
*
* user:xingxiaobing
* DATE:2015-02-13
* Implementation of the remote interface
*/
public class Helloimpl extends UnicastRemoteObjectimplements Ihello{
/**
* Because the UnicastRemoteObject constructor throws a RemoteException exception, the default constructor here must be written and must declare a RemoteException exception to be thrown
*
* @throws RemoteException
*/
Public Helloimpl () throws RemoteException {
}
/**
* Simple return to "Hello world!" "Words
*
* @return return "Hello world! "Words
* @throws java.rmi.RemoteException
*/
Public StringHelloWorld ()Throws RemoteException {
Return "Hello world!";
}
/**
* A simple business method that returns the appropriate greeting according to the name of the incoming person
*
* @param somebodyname names
* @return return the appropriate greeting
* @throws java.rmi.RemoteException
*/
public string Sayhellotosomebody (String somebodyname) throws RemoteException {
Return "Hello," + Somebodyname + "!";
}
}
Using the Rmic command in the project Bin directory
After anti-compilation
Package RMI;
Import Java.lang.reflect.Method;
Import Java.rmi.Remote;
Import java.rmi.RemoteException;
Import java.rmi.UnexpectedException;
Import Java.rmi.server.RemoteObject;
Import Java.rmi.server.RemoteRef;
Import java.rmi.server.RemoteStub;
Implement the same interface as the real object
// RemoteStub
class is a public superclass of client stubs, providing a framework that supports a large number of remote reference semantics
Public final class Helloimpl_stub extends Remotestub
implements Ihello,Remote
{
Private static final long serialversionuid = 2L;
private static Method $method _helloworld_0;
private static Method $method _sayhellotosomebody_1;
Static
{
Try
{
$method _helloworld_0 = Remote.class.getMethod ("HelloWorld", new Class[0]);
$method _sayhellotosomebody_1 = Tmp50_47.getmethod ("Sayhellotosomebody", new class[] {string.class});
}
catch (Nosuchmethodexception localnosuchmethodexception)
{
throw New Nosuchmethoderror ("Stub class initialization failed");
}
}
Public helloimpl_stub (Remoteref paramremoteref)
{
Super (PARAMREMOTEREF);
}
Public StringHelloWorld ()
Throws RemoteException
{
Object Localobject;
Try
{
//Helloword method for invoking real objects
Localobject =This.ref.invoke (This, $method _helloworld_0, NULL, 32013462L);
Return ((String) localobject);
}
catch (RuntimeException localruntimeexception)
{
Throw localruntimeexception;
}
catch (RemoteException localremoteexception)
{
Throw localremoteexception;
}
catch (Exception localexception)
{
throw new Unexpectedexception ("Undeclared checked exception", localexception);
}
}
public string Sayhellotosomebody (string paramstring)
Throws RemoteException
{
Try
{
Object Localobject = This.ref.invoke (this, $method _sayhellotosomebody_1, new object[] {paramstring}, -1641805534l);
Return ((String) localobject);
}
catch (RuntimeException localruntimeexception)
{
Throw localruntimeexception;
}
catch (RemoteException localremoteexception)
{
Throw localremoteexception;
}
catch (Exception localexception)
{
throw new Unexpectedexception ("Undeclared checked exception", localexception);
}
}
}
Apparently Helloimpl_stub is an agent of Helloimpl.
The process of dynamically generating helloimpl_stub is the process of dynamically creating an agent.
After the Java RMI stub is deserialized, the dynamic proxy