• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

rmi Exception

 
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have two remote object: a RemoteData as a Data wraper. this object is returned by a getRemoteData() in another remote object- DataFactory.
when I run getRemoteData() at client side, I got a large numbers of Exception:
......
java.rmi.unmarshalException:error unmarshalling return; nested exception is: java.io.WriteAbortedException: Writing aborted by exception; java.io.NotSerializableException: java.io.RandomAccessFile
......
need your help, thank you first,
regards,
Damu
 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is client side method:

this is server side :


[ June 17, 2003: Message edited by: damu liu ]
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Damu
Qusay has just been going through the same issue.
NotSerializableException means that you are probably trying to return an instance of RemoteData class that does not do one of:
  • extend UnicastRemoteObject and implement Remote, or
  • implement Serializable


  • RemoteData must do one or the other in order for it to be "returned" over the RMI interface.
    You probably do not want RemoteData to be serializable. If the class were serializable, then the entire class would be shipped over to the client, and would run on the client side. (I did actually toy with doing this - I could have verified whether a client had locked a record before calling unlock without any network traffic - but I decided against it).
    Hopefully this makes sense.
    I have also postd some code in this thread which shows the effects of the two options above, and the effect of not using either of the options.
    Regards, Andrew
    [ June 21, 2003: Message edited by: Andrew Monkhouse ]
     
    Ranch Hand
    Posts: 1327
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    when I use java.rmi.registry.LocateRegistry.createRegistry(port);
    with ports other then 1099 I get
    java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
    java.net.ConnectException: Connection refused: connect
    but with port 1099 it works fine
    anyone know whats wrong and how to solve it?
     
    Andrew Monkhouse
    author and jackaroo
    Posts: 12200
    280
    Mac IntelliJ IDE Firefox Browser Oracle C++ Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Billy
    Is this exception occuring on the line where you are starting the registry, or on the line where you are binding to your registry? I suspect that it will be the bind that is causing the exception.
    Could you please copy those two lines into this thread so we can see them and try and work out what is going on?
    Regards, Andrew
     
    Bigwood Liu
    Ranch Hand
    Posts: 240
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi, Andrew
    Thank you very much! You realy have a warm heart!
    Billy, did you change your rebind() & lookUp() to include the new port like this?

    Regards,
    Damu
    [ June 17, 2003: Message edited by: damu liu ]
    [ June 17, 2003: Message edited by: damu liu ]
    [ June 17, 2003: Message edited by: damu liu ]
     
    Billy Tsai
    Ranch Hand
    Posts: 1327
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    LocateRegistry.createRegistry();
    DBDatabaseImpl record =new DBDatabaseImpl();
    Naming.rebind("DB", record);

    I did some debugging and found out its the Naming.rebind line that where the exception is occurring, but with port 1099 it works fine
    any idea why?
     
    Ranch Hand
    Posts: 31
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    I did some debugging and found out its the Naming.rebind line that where the exception is occurring, but with port 1099 it works fine


    I have the same problem!

    Regards, Xiaoguang
     
    Andrew Monkhouse
    author and jackaroo
    Posts: 12200
    280
    Mac IntelliJ IDE Firefox Browser Oracle C++ Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Billy
    As Damu said, you need to specify the port in your bind or rebind method.
    The Sun RMI tutorial describes the first parameter in the bind method as:


    The first parameter is a URL-formatted java.lang.String representing the location and the name of the remote object. You will need to change the value of host to be the name, or IP address, of your server machine. If the host is omitted from the URL, the host defaults to the local host. Also, you don't need to specify a protocol in the URL. For example, supplying Compute as the name in the Naming.rebind call is allowed. Optionally a port number may be supplied in the URL; for example, the name //host:1234/objectname is legal. If the port is omitted, it defaults to 1099. You must specify the port number only if a server creates a registry on a port other than the default 1099. The default port is useful in that it provides a well-known place to look for the remote objects that offer services on a particular host.


    Regards, Andrew
     
    Billy Tsai
    Ranch Hand
    Posts: 1327
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    okay I figured out the problem
    I need
    Naming.rebind("rmi://localhost:"+port+"/DB", record);
    and not
    Naming.rebind("DB", record);

    Thanks for your help
     
    Bigwood Liu
    Ranch Hand
    Posts: 240
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    hi, Andrew
    I have been fighting with this Exception for several days, and didn't get a solution. After searching this forum, I found that John Chien had asked this question one year ago. He met the same problem, and figured it out half by himself. He gave a detail steps: remove the Serializable from RemoteData and its interface,and make RemoteData extends UnicastRemoteObject. I did as what he said. Yeeeeeeeeeeeh...
    Thank you for your kindness help.
    Regards,
    Damu
     
    Bigwood Liu
    Ranch Hand
    Posts: 240
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    hi,
    Can anyone give a analysis?
    I think the RemoteData is a remote object. what the client needs is a reference. It should be exported to client, but not be serialized to client.
    As serialized object, because it should exist at client side, so a copy is sent to the client side by serializing a object.
    Regards,
    Damu
     
    Andrew Monkhouse
    author and jackaroo
    Posts: 12200
    280
    Mac IntelliJ IDE Firefox Browser Oracle C++ Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Damu
    It appears my earlier link was going to the wrong thread. I wish someone had told me, then I would have fixed it. Anyway, if you want to look at it, the correct thread is here. This has code that will show you how to have in the server either a class that implements serialized or a class that extends UnicastRemoteObject. They have different uses, as (hopefully) is obvious when you run the code.
    As I had said


    NotSerializableException means that you are probably trying to return an instance of RemoteData class that does not do one of:

  • extend UnicastRemoteObject and implement Remote, or
  • implement Serializable

  • RemoteData must do one or the other in order for it to be "returned" over the RMI interface.


    Only one of those options is necessary. I deliberately shied away from suggesting which one.
    Damu: [RemoteData] should be exported to client, but not be serialized to client.
    Sounds like a good way to handle it. Serialization can be useful, but I dont think it is necessary for the assignment.
    Regards, Andrew
     
    Bigwood Liu
    Ranch Hand
    Posts: 240
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Andrew,
    I read your posted example. Very good.
    Thank you.
    Regards,
    Damu
     
    What's that smell? Hey, sniff this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic