Results 1 to 6 of 6
  1. #1
    nicoeschpiko is offline Member
    Join Date
    Dec 2010
    Location
    New Engaland
    Posts
    11
    Rep Power
    0

    Default passing objects w/RMI

    I am wondering if objects passed as parameters in RMI methods need to exist within the context of classes that implement interfaces? I have created a client class that implements an interface:

    Java Code:
    public class Client extends java.rmi.server.UnicastRemoteObject implements ATMListener {
    where ATMListener is:
    Java Code:
    public interface ATMListener extends java.rmi.Remote {
    and the client itself can successfully be passed as a parameter to an RMI method. However, when I try to pass other objects with a class definition extending java.rmi.server.UnicastRemoteObject, which are self-contained (i.e. are not class files implementing interfaces as in the Client's case), I get the error java.lang.IllegalArgumentException: argument type mismatch associated with the RMI method that the object serves as a parameter. Do these objects need to be defined as the Client is (an interface that extends java.rmi.Remote, and an implementation class that extends java.rmi.server.UnicastRemoteObject and implements the interface)? If so, what is the reason for this? It is also very likely that I am totally off base with this error, in which case suggestions as to the cause are very welcome. Thanks in advance for your assistance!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by nicoeschpiko View Post
    I am wondering if objects passed as parameters in RMI methods need to exist within the context of classes that implement interfaces? I have created a client class that implements an interface:
    Their classes need to implement the Serializable interface, that's all. Of course they can implement other interfaces as well.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    nicoeschpiko is offline Member
    Join Date
    Dec 2010
    Location
    New Engaland
    Posts
    11
    Rep Power
    0

    Default

    The objects I am trying to pass both extend java.rmi.server.UnicastRemoteObject (which implements Serializable). These classes are defined as:
    Java Code:
    package class.project;
    
    import java.rmi.RemoteException;
    
    
    public class AccountInfo extends java.rmi.server.UnicastRemoteObject {
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    	private int account_number;
    	private int pin_number;
    	
    	public AccountInfo(int account_number, int pin_number) throws RemoteException {
    		super();
    		this.account_number = account_number;
    		this.pin_number = pin_number;
    	}
    	
    	public int getAccountNumber() {
    		return this.account_number;
    	}
    	
    	public void setAccountNumber(int account_number) {
    		this.account_number = account_number;
    	}
    	
    	public int getPinNumber() {
    		return this.pin_number;
    	}
    	
    	public void setPinNumber(int pin_number) {
    		this.pin_number = pin_number;
    	}
    }
    and

    Java Code:
    package class.project;
    
    import java.rmi.RemoteException;
    
    
    public class TransactionNotification extends java.rmi.server.UnicastRemoteObject {
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    	private String notification;
    	
    	public TransactionNotification (String msg) throws RemoteException {
    		super();
    		notification = msg;
    	}
    	
    	public String toString() {
    		return notification;
    	} 
    }
    The method defined in the ATM class that exists on the registry is:
    Java Code:
    public Float getBalance(AccountInfo account_info) throws java.rmi.RemoteException, ATMException, SecurityException, Exception {
    and this listener method existing on the client returns the same error message:
    Java Code:
    public void receiveTransactionNotification(TransactionNotification tn)
    .

    Please let me know if the calls to these methods need to be provided for clarification. Thanks!

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by nicoeschpiko View Post
    The objects I am trying to pass both extend java.rmi.server.UnicastRemoteObject (which implements Serializable). These classes are defined as: [ snip ]

    Please let me know if the calls to these methods need to be provided for clarification. Thanks!
    Don't do that; any object extending UnicastRemoteObject is supposed to stay a remote object and just skeletons and/or stubs are passed around. Ordinary objects that should go over the wire should just implement Serializable.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    nicoeschpiko is offline Member
    Join Date
    Dec 2010
    Location
    New Engaland
    Posts
    11
    Rep Power
    0

    Default

    Thanks! I later realized that the object only needed to be passed by value, so the suggestion was appropriate. However, I am still curious as to how the stub equivalent would have been implemented.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by nicoeschpiko View Post
    Thanks! I later realized that the object only needed to be passed by value, so the suggestion was appropriate. However, I am still curious as to how the stub equivalent would have been implemented.
    I don't understand your question; stubs live on the client side calling into a naming service (rmi registry) that supplies a skeleton that serves as a proxy for the real thing living on the server side. In the old day you had to generate those stubs and skeletons yourself with the rmic tool; nowadays it is done just before running the server object(s) and running the stub object(s).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Passing Objects
    By Java_Developer in forum New To Java
    Replies: 6
    Last Post: 10-29-2009, 02:32 PM
  2. MVC passing objects
    By simo_mon in forum New To Java
    Replies: 1
    Last Post: 07-17-2009, 07:57 AM
  3. Passing objects into constructors
    By aaronfsimons in forum New To Java
    Replies: 8
    Last Post: 04-14-2009, 01:08 PM
  4. Passing objects in Java
    By jbostjr in forum New To Java
    Replies: 1
    Last Post: 10-30-2007, 11:15 PM
  5. Passing objects in Java
    By jbostjr in forum Advanced Java
    Replies: 1
    Last Post: 10-30-2007, 06:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •