CS 696 Emerging Technologies: Distributed Objects |
---|
public class Foo { public void method( Object parameter ) { result = parameter.someMethod( echo ); } }Pass-by-Value (Copy)
public class Foo extends UnicastRemoteObject implements FooRemote { public void remoteMethod( Object parameter ) { result = parameter.someMethod( echo ); } }
package whitney.rmi.examples.basic; import java.util.Vector; public interface VectorParameter extends java.rmi.Remote { public Vector modify( Vector input ) throws java.rmi.RemoteException; }
package whitney.rmi.examples.basic; import java.rmi.*; import java.rmi.server.UnicastRemoteObject; import java.rmi.registry.Registry; import java.util.Vector; import sdsu.rmi.registry.Registrar; import sdsu.util.ProgramProperties; import java.io.IOException; public class VectorParameterServer extends UnicastRemoteObject implements VectorParameter { public VectorParameterServer() throws RemoteException {} public Vector modify( Vector input ) throws RemoteException { input.addElement( "Hi Mom"); return input; } public static String RMI_NAME = "cs696/VectorParameter"; static String serverClass = "whitney.rmi.examples.basic.VectorParameterServer"; public static void main(String args[]) throws RemoteException, IOException { int port = getPort( args ); String nameList = Registrar.verboseRebind( port, RMI_NAME, serverClass); System.out.println( nameList ); } private static int getPort( String args[] ) throws IOException { ProgramProperties flags = new ProgramProperties( args ); int defaultPort = Registry.REGISTRY_PORT; int port = flags.getInt( "p", defaultPort ); return port; } }
package whitney.rmi.examples.basic; import java.rmi.*; import java.rmi.registry.Registry; import java.net.MalformedURLException; import java.io.IOException; import java.util.Vector; import sdsu.util.ProgramProperties; public class VectorParameterClient { public static void main(String args[]) { try { String serverLabel = VectorParameterServer.RMI_NAME; String server = getServerURL( args, serverLabel ); VectorParameter remote = (VectorParameter) Naming.lookup( server ); Vector data = new Vector(); Vector remoteData = remote.modify( data ); System.out.println( "remote " + remoteData); System.out.println( "local " + data); if ( data == remoteData ) System.out.println( "equal" ); else System.out.println( "not equal" ); } catch ( Exception error) { error.printStackTrace(); } } private static String getServerURL( String args[], String serverLabel ) throws IOException { String hostKey = "h"; String portKey = "p"; ProgramProperties flags = new ProgramProperties( args ); String host = null; if ( flags.containsKey( hostKey ) ) host = flags.getString( hostKey ); else { System.out.println( "Missing flag " + hostKey ); System.exit( 0 ); } int defaultPort = Registry.REGISTRY_PORT; int port = flags.getInt( portKey, defaultPort ); return "rmi://" + host + ":" + port + "/" + serverLabel; } }
package whitney.rmi.examples.basic; public class Foo { String name = "Roger"; }
package whitney.rmi.examples.basic; public interface ParameterTrouble extends java.rmi.Remote { public void tryMe( Foo input ) throws java.rmi.RemoteException; }
package whitney.rmi.examples.basic; import java.rmi.*; import java.rmi.server.UnicastRemoteObject; import java.rmi.registry.Registry; import sdsu.rmi.registry.Registrar; import sdsu.util.ProgramProperties; import java.io.IOException; public class ParameterTroubleServer extends UnicastRemoteObject implements ParameterTrouble { public ParameterTroubleServer() throws RemoteException {} public void tryMe( Foo input ) throws RemoteException {} public static String RMI_NAME = "cs696/ParameterTrouble"; static String serverClass = "whitney.rmi.examples.basic.ParameterTroubleServer"; public static void main(String args[]) throws RemoteException, IOException { int port = getPort( args ); String nameList = Registrar.verboseRebind( port, RMI_NAME, serverClass); System.out.println( nameList ); } private static int getPort( String args[] ) throws IOException { ProgramProperties flags = new ProgramProperties( args ); int defaultPort = Registry.REGISTRY_PORT; int port = flags.getInt( "p", defaultPort ); return port; } }
package whitney.rmi.examples.basic; import java.rmi.*; import java.rmi.registry.Registry; import java.net.MalformedURLException; import java.io.IOException; import sdsu.util.ProgramProperties; public class ParameterTroubleClient { public static void main(String args[]) { try { String serverLabel = ParameterTroubleServer.RMI_NAME; String server = getServerURL( args, serverLabel ); ParameterTrouble remote = (ParameterTrouble) Naming.lookup( server ); remote.tryMe( new Foo() ); } catch ( Exception error) { error.printStackTrace(); } } private static String getServerURL( String args[], String serverLabel ) throws IOException { String hostKey = "h"; String portKey = "p"; ProgramProperties flags = new ProgramProperties( args ); String host = null; if ( flags.containsKey( hostKey ) ) host = flags.getString( hostKey ); else { System.out.println( "Missing flag " + hostKey ); System.exit( 0 ); } int defaultPort = Registry.REGISTRY_PORT; int port = flags.getInt( portKey, defaultPort ); return "rmi://" + host + ":" + port + "/" + serverLabel; } }
java.rmi.MarshalException: Error marshaling arguments; nested exception is: java.io.NotSerializableException: whitney.rmi.examples.basic.Foo at java.lang.Throwable.<init>(Compiled Code) at java.lang.Exception.<init>(Compiled Code) at java.io.IOException.<init>(Compiled Code) at java.rmi.RemoteException.<init>(Compiled Code) at java.rmi.MarshalException.<init>(Compiled Code) at whitney.rmi.examples.basic.ParameterTroubleServer_Stub.tryMe(Compiled Code) at whitney.rmi.examples.basic.ParameterTroubleClient.main(Compiled Code)
public interface RemoteParameter extends java.rmi.Remote { public RemoteParameter itWorks( ) throws java.rmi.RemoteException; }
public class RemoteParameterClient { public static void main(String args[]) { try { String serverLabel = RemoteParameterServer.RMI_NAME; String server = getServerURL( args, serverLabel ); RemoteParameter remote = (RemoteParameter) Naming.lookup( server ); RemoteParameter aReference = remote.itWorks( ); System.out.println( "It Works"); } catch ( Exception error) {} }
public class RemoteParameterServer extends UnicastRemoteObject implements RemoteParameter { public RemoteParameter itWorks( ) throws RemoteException { return this; }