• 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

Strange RMI - Error

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,

I have a strange RMI Error:

I startup my server.

I connect 1..x Clients.

I shutdown the server.


The Clients still work: The changes are persisted in the file and the changes made by clients 1 can be seen by Client 2.

How can that be ?
Shouldn´t I get some Information that the Server is down, not connectable or so ?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Daniel,

That is indeed strange RMI behavior you should indeed expect some kind of RemoteException.

How do you stop/shutdown your server? Can you connect a client after server shutdown?

Kind regards,
Roel
 
Daniel Breitner
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well ... this I am going to find out

But I found out something else yesterday:

I made the mistake of creating the RandomAccessFile on the Client. Means: Client gets Reference to Business Interface, and Business Interface, upon first access, creates the DAO which then accesses the RandomAccessFile.

I now switched it to first creating everything on the Server and then publishing it by RMI.


BUT :

Whatever I do: The DAO is null on the Client. There is no "NotSerializableException" - nothing. It´s just as if the DAO got filtered out.


My structure is like that (sorry for trying to write UML with text ;) )


BusinessInterface <- BusinessImpl - DB <- Data - DAO <- FileSystemDAO - RandomAccessFile


Does anyone of you have an idea why the DAO may be null when the BusinessInterface is retrieved on the client ?
 
Daniel Breitner
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem solved !!!


Problem 1:

I created the DAO on the Client -> even without a Server the two Clioents were still workingh on the File. The File was the Server ...


Problem 2:

My Business Implementation didn´t extend UnicastRemoteObject. This led to a strange error where only some objects were null (don´t ask me why).

Now everything is fine
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Daniel,

This is how my structure looks:
And it is the BusinessServiceImpl which gets exported and is exposed through RMI.

You don't talk directly with the RMI registry, but through a stub (client) and a skeleton (server). These files are generated using the RemoteBusinessService. From Java 5 this is done automatically (you can also generate them with rmic tool, what I did when I submitted my assignment). More info about RMI basics can be found here.

Kind regards,
Roel
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Breitner wrote:My Business Implementation didn´t extend UnicastRemoteObject.

This is not needed, because you are using inheritance and your business implementation is not a (specialized version of the) UnicastRemoteObject. And if you wanted to extend your Business implementation from another class, you will have a problem too (because Java doesn't support multiple inheritance as you know).

You could use exportObject method in UnicastRemoteObject (before exposing it through RMI) to have same functionality as extending from the UnicastRemoteObject.

Daniel Breitner wrote:Now everything is fine

Well done!


Kind regards,
Roel
 
Daniel Breitner
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:Hi Daniel,

And it is the BusinessServiceImpl which gets exported and is exposed through RMI.

You don't talk directly with the RMI registry, but through a stub (client) and a skeleton (server). These files are generated using the RemoteBusinessService.
Kind regards,
Roel




On question to that :

When I publish my BusinessInterface by RMI it would mean that all my methods have to throw a RemoteException.

When I want to use this Interface in my Controller, it would then have to catch those Exceptions.

I would even have to catch them if I was working locally (no network connection).

Is this allowed when my assignment says "must not use any network functionality at all when running locally" ?
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Daniel,

My solution looks like this:So that's valid code and you are not using network functionality, because you simply get an instance of LocalBusinessServiceImpl (instead of a stub of RemoteBusinessServiceImpl). Other ranchers have created another LocalBusinessService, extending the BusinessService redefining each method without the RemoteException in the throws-clause.

Kind regards,
Roel
 
Daniel Breitner
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But wouldn´t that mean that you have to change your BusinessService interface when you want to switch to another networking approach ?
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Daniel,

With the approach (I described in my previous post) you can do without a problem:but of course you have to catch the RemoteException too (which is not a problem, because my client is totally unaware of the mode it is running in). I use one client for both local and networked mode, keeps my code simple and clean.
If you want to use LocalBusinessService you will of course have to make distinction between local and network business service, which will clutter up your code (but you don't have to catch the RemoteException).
In the end it is a decision you have to make depending on your complete architecture. If you have just 1 client for both modes, I don't think there is no added values in using a LocalBusinessService, because you will have a call to the find-method which is invoked on either the local business service implementation or a stub of the remote business service implementation

Kind regards,
Roel
 
Daniel Breitner
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I meant was:

If your BusinessInterface already specified RemoteException, then this means that if you want to switch a NON-RMI networking approach, you´d also have to change your BusinessInterface
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah ok, now I get your question If you want to use another networking approach (which is not RMI) you'll have indeed to make changes to your business interface (or create a complete new interface). So you are spot-on with your assumption!

Kind regards,
Roel
 
reply
    Bookmark Topic Watch Topic
  • New Topic