• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

own interface in Bodgit and Scraper

 
mohini lalwani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should I create my own interface which is going to implement SUN's interface?
reason behind this is I have to make Remote interface which should extend SUN's interface and every method in remote interface should throws
RemoteException .
So is it okay i will create my own interface which will extend Sun 's interface and only difference between my own interface and Sun 's interface is that every method in my own interface will throw RemoteException.
For sack of RMI I would like to do this .

Please reply is it okay to create own interface which will extend SUN's interface ???

thanks
pramod
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot extend an interface by adding "throws RemoteException" to its methods. It does not compile.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, partner!

Well, you can create an interface that extends Sun's interface. I did that, where I added 5 extra methods to the interface that extends Sun's interface. But none of the extra methods throw RemoteExceptions. What I did: I created another interface for the Server, which has the same methods with same signatures as Sun's interface (+ getAllRecords and startServer, 2 custom methods), and these methods also throw RemoteExceptions. For instance, here's my create method of the Server interface:



The implementation of this interface uses the Data class, which is the implementation of Sun's interface.



So, you can extend Sun's interface, but don't throw RemoteExceptions there. This is just for your server.
 
mohini lalwani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Alecsandru ,

then tell me how to handle RemoteException in class which is implementing the Remote Interface ?

I made Remote interface which actually extends Sun's interface
e.g. ContractorDatabaseRemote
ContractorDatabaseImpl implements ContractorDatabaseRemote interface .
how to handle RemoteException of each method of ContractorDatabaseImpl ??
 
Jeffry Kristianto Yanuar
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pramod karnani:

how to handle RemoteException of each method of ContractorDatabaseImpl ??



At least you have to use exception.printStackTrace() method or using logging API. Just don't leave the catch block left empty. In the GUI level, you can also show the JOptionPane to the user.


If you use plain socket just like me, you wouldn't be concerned about that RemoteException but you must develop your own protocol which is a tedious thing. So choosing RMI is a wise choice.

Good Luck !!!

Jeffry Kristianto Yanuar (Java Instructor)
SCJP 5.0, SCJA, SCJD (UrlyBird 1.3.2)
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using a business layer, and the interfaces from this business layer are created by me. So I can chose to throw whatever I want, including RemoteException, from both local and remote interfaces. What you can do with your approach (the two layer approach) - just create another interface, which is like SUN's but also throws RemoteException. From its implementation, delegate to the SUN's interface implementation (like Robert said). In GUI you have to create an adapter from SUN's interface to the remote interface (or the other way round), such that you can work with both local and remote implementations as if they were implementing the same interface... (hope I was clear enough... )

Dealing with the exception - you do that in the GUI layer. I chose to show error messages to the user from the controllers, but you can do it another way.
 
mohini lalwani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic