aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes a question about RMI implementation's concept Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "a question about RMI implementation Watch "a question about RMI implementation New topic
Author

a question about RMI implementation's concept

ChunYong Guan
Greenhorn

Joined: Nov 18, 2003
Posts: 9
Hello ,every one!Please give me some advice
Assume that :

the class DataAccessRemote doesn't throw the RemoteException which defines in the DataAccessRemote interface.
Is it illegal "Does it voilate the RMI rules?
But in myself test application,the code above runned happlily!
Can Someone tell detailedly what's wrong with me ??
Thanks very much.
Regards!


SJCP 83%,SCWCD,88%<br />SCJD 397<br />come from China
Samuel Pessorrusso
Ranch Hand

Joined: Jul 21, 2005
Posts: 164
That isn't wrong. Who implements the method can throw or not the super class (or interface) defined exception, that isn't a requirement.

Take a look at you Programmer Certification notes...
ChunYong Guan
Greenhorn

Joined: Nov 18, 2003
Posts: 9
Samuel,thanks you very much!Yesterday I read the 'Java tutorial'.
Just as you said! I am so careless ,the implementation class of sample codes never throws the RemoteException ,too.
Thanks again.
But I want to ask:
never concern with the RemoteException and then I never throw the RemoteException. so,The RemoteException is a redundant Exception??
If not ,who uses it and who generates it ?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11526
    
100

Hi ChunYong
But I want to ask:
never concern with the RemoteException and then I never throw the RemoteException. so,The RemoteException is a redundant Exception??
If not ,who uses it and who generates it ?
After you have compiled your source code, you will have to run rmic to compile stubs for the clients. The stub may throw a RemoteException if it has a communication error, however since it must also implement your interface it cannot throw that exception if you don't declare it.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
ChunYong Guan
Greenhorn

Joined: Nov 18, 2003
Posts: 9
Thanks Thanks ,Andrew .
I understand it through your explain .
I have taken the wrong concept about RMI for 2 years.
So , I think about another question :


Can I use such a DataAccessAdapter ?
The client GUI use a DataAccessAdapter's reference to deal with the data(whatever the client GUI is local or remote ,just a DataAccessAdapter's reference.)
If it violates the following rules?

Non-Networked Mode
...
The operating mode is selected using the single command line argument that is permitted. Architecturally, this mode must use the database and GUI from the networked form, but must not use the network server code at all.



[ August 21, 2005: Message edited by: ChunYong Guan ]
[ August 21, 2005: Message edited by: ChunYong Guan ]
ChunYong Guan
Greenhorn

Joined: Nov 18, 2003
Posts: 9
HI,Andrew !
Would you please have a look the question above?(the previous reply of me)
Thanks!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11526
    
100

Hi ChunYong,

Just declaring that a method may throw a network exception and/or having code that can handle that network exception does not necessarily break that rule.

What is more important is whether you neeed to start the server (run RMI / use serialization / use sockets) in order for your standalone mode to work. If you do then you will break that rule.

You have been told that you should be using the same GUI and database in both networked and standalone mode, so there is always going to be some overlap. The difference is determining whether you are running a server (something that multiple clients might be able to connect to) in standalone mode or not.

Regards, Andrew
ChunYong Guan
Greenhorn

Joined: Nov 18, 2003
Posts: 9
Thanks a lot,Andrew.
what I designed above is indeed a overlap.It does a wrong way.

So,I do as follow

So,In my GUI client ,just need a reference of DBAccessFactory.Is this OK ?
by the way ,I think it has too many if/else clauses in this design.Would someboby give me some advice ?
Thanks and Thanks!
Matthew Baranowski
Greenhorn

Joined: Aug 22, 2005
Posts: 5
I am working on the SCJD as well. I think your factory pattern is a bit off. I recommend having your factory have a getDataAccess method with a return type of an interface or abstract base class like the following code:



You use the above class with something like the following:



SCJP
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11526
    
100

Thanks Mathew,

You saved me from saying exactly the same thing

Regards, Andrew
hatim osman
Ranch Hand

Joined: Jun 10, 2005
Posts: 105
Hi Chun, Andrew and Matthew,
First of all, I'd like to thank you for this useful thread. However, I do have a few questions and I hope you bear with me and therefore answer them:
1. In Chun's code, the DataAccessRemote interface doesn't extend the Remote interface, how the stub files will be created then?
2. I observed that the methods in the DataAccessImpl do not throw the RemoteException "Which is very legal", how will the server then generates remote exception then in case somthing goes wrong?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11526
    
100

Hi Hatim
1. In Chun's code, the DataAccessRemote interface doesn't extend the Remote interface, how the stub files will be created then?
He will have to extend the Remote interface for this to work.
2. I observed that the methods in the DataAccessImpl do not throw the RemoteException "Which is very legal", how will the server then generates remote exception then in case somthing goes wrong?
The server you create may not ever need to throw a RemoteException. The RemoteException is needed for RMI though. When you run RMIC, you will generate some stubs which handle the communication process for you. They need to be able to pass communication errors to the client method that called them. To do this, the stub can throw RemoteException.

Regards, Andrew
ChunYong Guan
Greenhorn

Joined: Nov 18, 2003
Posts: 9
Thanks Hatim ,Andrew .
The factory disign is perfect .I like it!
I know what shall I do now!
hatim osman
Ranch Hand

Joined: Jun 10, 2005
Posts: 105
Hi guys...
More power chun. I have a thought and correct me guys if I am wrong, The server implementation is very simple and most of the design issue will be on the client side. I heard of people adopting to such a scenario:
interface DataAcess {
}
interface DataAcessRemote extends DataAcess{
//all methods throw RemoteException
}

What's the idea behind this design? And which interface the exported object should implement?

Thanx in advance
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11526
    
100

Hi Hatim,
and most of the design issue will be on the client side
I think you will find that there are plenty of design issues and problems in creating a server that can safely handle multiple users concurrently as well
I heard of people adopting to such a scenario:What's the idea behind this design? And which interface the exported object should implement?
I think you will find that you cannot do this - since the methods in DataAccess do not throw RemoteException, DataAccessRemote will not be able to do this. What you may find is that there are quite a few posts in this forum from candidates who started down this path and got stuck fairly early on.

If you could do this, it would make the RMI solution a bit easier. However it is more likely that you will have to use the Adapter pattern (or Wrapper pattern) to provide this functionality.

Regards, Andrew
hatim osman
Ranch Hand

Joined: Jun 10, 2005
Posts: 105
Hi...
Thanx Andrew, I thought that too. It's my first time to attempt doing a project using RMI, although I made use of it in very simple situations and rarely as well. However, I am very much confident that I can implement a robust solution using sockets which I am very good at. The idea of failing the exam when using RMI motivates more to use its counterpart sockets in spite of the popularity of RMI strategy among fellow programmers in this forum. Anyway, thank you very much guys for your enlightening advices and wish you all good luck. Will be back soon with more ideas on sockets solution if enough courage isn't available for taking the risk of RMI :-).

Best Wishes
Hatim
hatim osman
Ranch Hand

Joined: Jun 10, 2005
Posts: 105
Hi...
Thanx Andrew, I thought that too. It's my first time to attempt doing a project using RMI, although I made use of it in very simple situations and rarely as well. However, I am very much confident that I can implement a robust solution using sockets which I am very good at. The idea of failing the exam when using RMI motivates more to use its counterpart sockets in spite of the popularity of RMI strategy among fellow programmers in this forum. Anyway, thank you very much guys for your enlightening advices and wish you all good luck. Will be back soon with more ideas on sockets solution if enough courage isn't available for taking the risk of RMI :-).

Best Wishes
Hatim
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a question about RMI implementation's concept