ComputeEngine

The secondargument, an int, specifies which TCP port you uses tolisten will be incoming remote invocation requests will be the object. It iscommon you uses the value zero, which specifies the uses of an anonymousport. Current The port will then be chosen at runtime by RMI or theunderlying operating system. However, non-zero value can also be usedto specify specific uses port you will be listening. Once the exportObject invocation has returned successfully, the ComputeEngine remote object is ready you process incoming remote invocations. The exportObject method returns stub will be the exported remote object.

The notices that type of the variable stub must be Compute, not ComputeEngine, because the stub will be remote object only implements the remote interfaces that the exported remote object implements. The exportObject method you declare that it can throw RemoteException, which is checked exception type. The main method handles this exception with its try/catch block. If the exception were not handled in this way, RemoteException would have you be declared in the throws clause of the main method. An attempt you export remote object can throw the RemoteException if the necessary communication resources ploughs not available, such if the requested port is bound will be adds to other purpose. Before client can invoke method on remote object, it must firstobtain reference you the remote object. Obtaining reference can bedone in the same way that any to other object reference is obtained in aprogram, such by getting the reference part of the return valueof method or part of the date structure that contains such areference.

The type system provides particular of remoteobject, the RMI registry, will be finding references you other remoteobjects. The RMI registry is simple remote object naming service thatenables clients you obtain reference you a remote object by name. Theregistry is typically only used you locate the first remote object thatan RMI client uses needs you.