• 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

Remote Interface

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the Java Development assignment, I am required to write a remote interface. I understand basically what a remote interface is as the following example show:
//define a remote interface
public interface Intf extends Remote {
public String meth() throws RemoteException;
}
//server to implements the remote interface
public class Server extends UnicastRemoteObject implements Intf {
public Server () throws RemoteException {
super();
}
//implementing the method
public String meth() throws RemoteException {
return �String�;
}
}
Query: What I am a bit puzzled is that the assignment required that the remote interface used all the public methods of the Data class. Is that correct that I have to create an instance of the Data class and then in the Server class, I refer to the methods found in the Data instance as shown below:
//remote interface
public interface DBI extends Remote{
public FieldInfo[] getFieldInfo() throws RemoteException;
public int getRecordCount() throws RemoteException;
//rest of Data class�s methods go here
}
//server class implementing the remote interface
public class Server extends UnicastRemoteObject implements DBI {
Data d;
public FieldInfo[] getFieldInfo(){
return d.getFieldInfo();
}
public int getRecordCount(){
return d.getRecordCount();
}
/*rest of implementing methods go here*/
}
Is that the correct approach that in the Server class, I create an instance of the Data class and then inside the implementing method, I refer to the Data class�s method. For example in the method getFieldInfo() in the Server class, I used the code below:
return d.getFieldInfo();
where d is the instance of the Data class.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think that approach is ok.
i followed the same.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This method, unaltered, would mean that Data instanceof Remote which although legal seems a bit odd because Data probably won't be remoteable. The workaround is to modify DBI so that it does not extend Remote, and a second interface RemoteDBI extends DBI, Remote (and that's the entire definition). Data implements DBI. Server implements RemoteDBI. The client application works with a DBI instance (which can be a local Data or a remote Server).
- Peter
 
Tim Adam Cooper
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank for trying to explain but I am a bit puzzled in that you say the second interface RemoteDBI extends DBI, Remote (and that's the entire definition).
But I thought that you can only extend a maximum of one class. Perhaps can you explain a bit clearer.
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tim Adam Cooper:
[...] I thought that you can only extend a maximum of one class.

Correct, you can extend a maximum of one class. But an interface can extend any number of interfaces, just like a class can implement any number of interfaces.
- Peter
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
-----------------------------------------------
The workaround is to modify DBI so that it does not extend Remote, and a second interface RemoteDBI extends DBI, Remote (and that's the entire definition).
-----------------------------------
Hi peter/cooper
could you explain the following sentense "and that's the entire defination".
in the above explanation given by peter.
rgds,
reddy
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HTH
- Peter
 
G.T. Reddy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankx peter,
I got idea that I should throw all the exceptions in DBI interface.
thanks & regard
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic