• 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

DBMain method need throw RemoteException?

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

From Sun insturction, I need implement few methods such as:
public void lock(int recNo) throws RecordNotFoundException;

Well for remote rmi call, I had implement a interface and implementaiton as below:

public interface DataRemote extends Remote, DBMain {
}

public class DataImpl extends UnicastRemoteObject
implements DataRemote {
...
private DBMain db = null;
....
public void lock(int recNo) throws RecordNotFoundException{
db.lock(recNo);
}
}

Since DBMain methods don't throw RemoteException exception, so at DataImpl I also didn't throw RemoteException.

Well, when I exec remotely I face below exception:
java.lang.IllegalArgumentException: illegal remote method encountered: public abstract void suncertify.db.DBMain.lock(int) throws suncertify.db.RecordNotFoundException

So I put RemoteException on both DBMain and DataImpl, error gone.

My questions is at DBMain those method signature should follow what Sun instruction right? Also add in that RemoteException means nothing for local call.

Any help on that? I had try to just add RemoteException to DataImpl method but face compilaiton error as 'overridden method does not throw java.rmi.RemoteException'



Please help.

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

Originally posted by Song Jing Lim:
Hi

From Sun insturction, I need implement few methods such as:
public void lock(int recNo) throws RecordNotFoundException;

Well for remote rmi call, I had implement a interface and implementaiton as below:

public interface DataRemote extends Remote, DBMain {
}

public class DataImpl extends UnicastRemoteObject
implements DataRemote {
...
private DBMain db = null;
....
public void lock(int recNo) throws RecordNotFoundException{
db.lock(recNo);
}
}

Since DBMain methods don't throw RemoteException exception, so at DataImpl I also didn't throw RemoteException.

Well, when I exec remotely I face below exception:
java.lang.IllegalArgumentException: illegal remote method encountered: public abstract void suncertify.db.DBMain.lock(int) throws suncertify.db.RecordNotFoundException

So I put RemoteException on both DBMain and DataImpl, error gone.

My questions is at DBMain those method signature should follow what Sun instruction right? Also add in that RemoteException means nothing for local call.

Any help on that? I had try to just add RemoteException to DataImpl method but face compilaiton error as 'overridden method does not throw java.rmi.RemoteException'



Please help.

Thanks



You need to have another class to provide network connectivity as you cannot change the DBMain interface and as its methods cannot throw remote exceptions it can only be used locally and not over RMI.

You could look up the apapter pattern as a possible solution to this problem. Using this pattern you define a class with methods that throw a RemoteException. You can then delegate to the Data class to do the actual work.


Mark.
[ January 05, 2007: Message edited by: Mark Smyth ]
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks buddy.

Actually I also using adaptor method as show below:

public interface DataRemote extends Remote, DBMain {
}

public class DataImpl extends UnicastRemoteObject
implements DataRemote {
...
private DBMain db = null;
....
public DataImpl(String dbLocation) throws RemoteException {
db = new Data(dbLocation);
}
...
public void lock(int recNo) throws RecordNotFoundException{
db.lock(recNo);
}
}

public class Data implements DBMain{
...
}

The only difference is my adaptor class (DataImpl) are implement DBMain. As local call return Data which also implement DBMain, when main program calling either local or remote will use the Factory return difference object implement same parent class (DBMain). Example:

private DBMain connection;
...
switch (connectionType) {
case DIRECT:
connection = suncertify.direct.Connector.getLocal(dbLocation);
break;
case RMI:
connection = suncertify.remote.Connector.getRemote(dbLocation, port);
break;
}

The problem is DataImpl (remote call) which implement DBMain need throw RemoteException and compiler not allow (bcoz DBMain don't throw it).

If my DataImpl didn't implement DBMain, it work fine but I need have 2 difference module process local and remote call.

Please guide...

Thanks
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

I had found a soluion:
https://coderanch.com/t/183727/java-developer-SCJD/certification/NX-DBAccess-RemoteException

This had answer my question...

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

Originally posted by Song Jing Lim:
Hi Mark,

I had found a soluion:
https://coderanch.com/t/183727/java-developer-SCJD/certification/NX-DBAccess-RemoteException

This had answer my question...



Search is working again!
reply
    Bookmark Topic Watch Topic
  • New Topic