GeeCON Prague 2014*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes DBMain method need throw RemoteException? 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 "DBMain method need throw RemoteException?" Watch "DBMain method need throw RemoteException?" New topic
Author

DBMain method need throw RemoteException?

Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
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


Rgds,<br />Song Jing
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
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 ]

SCJP<br />SCJD
Song Jing Lim
Ranch Hand

Joined: Feb 11, 2003
Posts: 56
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

Joined: Feb 11, 2003
Posts: 56
Hi Mark,

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

This had answer my question...

Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by Song Jing Lim:
Hi Mark,

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

This had answer my question...



Search is working again!
 
GeeCON Prague 2014
 
subject: DBMain method need throw RemoteException?