RMI interface

P

Pete

HI

I am currently working on my SCJD assignment and if you are aware of
this, it is really composed of 3 parts - client side, network layer &
server side.

I am at the stage of implememting the network layer and need some
advice of what I have done is reasonable or are there some issues that
I have overlooked.
I appreciate presenting snippets of code is not the best .. I am
sorry.

Below is my remote interface definition.

public interface DatabaseRemote extends Remote {

public String[] readRecord(long recNo) throws
RecordNotFoundException, RemoteException;

public void updateRecord(long recNo, String[] data, long lockCookie)
throws RecordNotFoundException, SecurityException, RemoteException;

public void deleteRecord(long recNo, long lockCookie)
throws RecordNotFoundException, SecurityException, RemoteException;

public long[] findByCriteria(String[] criteria)throws
InvalidArgumentException, RemoteException;

public long createRecord(String[] data) throws
InvalidArgumentException, DuplicateKeyException, RemoteException;

public long lockRecord(long recNo) throws RecordNotFoundException,
RemoteException;

public void unlock(long recNo, long cookie) throws SecurityException,
RemoteException;

}



The remote interface provides all the methods that need to supported
on the server side. Is this approach good or should I consider an
alternative approach where by a remote object is returned to the
client which provides all the methods that need to supported ie as per
DatabaseRemote above. With the alternative approach, the remote
interface to the client would a single method which would return a
remote object
public interface DatabaseRemote extends Remote {

public RemoteClient getClient( ) throws RemoteException;

}
public interface RemoteClient extends Remote {

public String[] readRecord(long recNo) throws
RecordNotFoundException, RemoteException;

public void updateRecord(long recNo, String[] data, long lockCookie)
throws RecordNotFoundException, SecurityException, RemoteException;

public void deleteRecord(long recNo, long lockCookie)
throws RecordNotFoundException, SecurityException, RemoteException;

public long[] findByCriteria(String[] criteria)throws
InvalidArgumentException, RemoteException;

public long createRecord(String[] data) throws
InvalidArgumentException, DuplicateKeyException, RemoteException;

public long lockRecord(long recNo) throws RecordNotFoundException,
RemoteException;

public void unlock(long recNo, long cookie) throws SecurityException,
RemoteException;

}

1) What are pros and cons of the two approachs.?

2) When I throw any of the above exceptions ( RecordNotFoundException,
SecurityException, InvalidArgumentException ) from my data layer, I
presume they will be propagated back to the client, or do I have to do
something extra ?

3) There no objects exchanged between the client and server so I don't
think I need to implement serializble maybe for new excpetions that I
have declared ie RecordNotFoundException, DuplicateKeyException &
InvalidArgumentException. Is this correct.

Any feedback would be very much appreciated. Thank you.

Pete
 
E

EJP

Pete said:
1) What are pros and cons of the two approachs.?

If you return a new RemoteClient object to each client, you can maintain
server-side state for that client. Effectively each such object
represents a session. Whether that's a good or a bad idea is up to you ;-)
2) When I throw any of the above exceptions ( RecordNotFoundException,
SecurityException, InvalidArgumentException ) from my data layer, I
presume they will be propagated back to the client, or do I have to do
something extra ?

No, it is propagated for you. NB to keep things clean and keep client
programmers from cheating I strongly recommend that you *don't* make
your application exceptions extend RemoteException.
3) There no objects exchanged between the client and server so I don't
think I need to implement serializble maybe for new excpetions that I
have declared ie RecordNotFoundException, DuplicateKeyException &
InvalidArgumentException. Is this correct.

Yes.
 
L

Lew

Pete said:
3) There no objects exchanged between the client and server so I don't
think I need to implement serializble [sic] maybe for new excpetions that I
have declared ie [sic] RecordNotFoundException, DuplicateKeyException &
InvalidArgumentException. Is this correct[?]

I am guessing that you mean java.io.Serializable.

Sort of. It is not correct for exceptions if by "need to implement
Serializable" you mean to include an explicit 'implements' clause in the
exception definition.

java.lang.Exception implements java.io.Serializable, so as long as you extend
Exception you have implemented Serializable.
<http://java.sun.com/javase/6/docs/api/java/lang/Exception.html>

I wouldn't define a new exception InvalidArgumentException unless you want it
to be a checked exception. If you are content with a RuntimeException, then
IllegalArgumentException should do. Since by the name it seems that this
exception represents programmer error, and not an unavoidable extrinsic
problem, it should be a RuntimeException, therefore prefer
IllegalArgumentException.
 
P

Pete

Pete said:
3) There no objects exchanged between the client and server so I don't
think I need to implement serializble [sic] maybe for new excpetions that I
have declared ie [sic] RecordNotFoundException, DuplicateKeyException &
InvalidArgumentException. Is this correct[?]

I am guessing that you mean java.io.Serializable.

Sort of.  It is not correct for exceptions if by "need to implement
Serializable" you mean to include an explicit 'implements' clause in the
exception definition.

java.lang.Exception implements java.io.Serializable, so as long as you extend
Exception you have implemented Serializable.
<http://java.sun.com/javase/6/docs/api/java/lang/Exception.html>

I wouldn't define a new exception InvalidArgumentException unless you want it
to be a checked exception.  If you are content with a RuntimeException, then
IllegalArgumentException should do.  Since by the name it seems that this
exception represents programmer error, and not an unavoidable extrinsic
problem, it should be a RuntimeException, therefore prefer
IllegalArgumentException.


Many thanks for the response.

Both InvalidArgumentException and RecordNotFoundException exceptions
extend RuntimeException and they
need to be checked to ensure that the client application will detect
and act on the error condition.
Probably put up a error dialog box.

I did mean "implements java.io.Serializable", however, as you say it
is already implementet so not an issue.
1) What are pros and cons of the two approachs.?

In my assignment I am keen on the approach where I present all the
required methods on the Remote Interface and for the client to invoke
methods accordingly.
This seems simple and straight forward. But for the assignment I
really need to justify this
approach and with some technical reasons. Any suggests of pros and
cons would be appreciated.

EJP, what you say is I guess a feature. However, in my assignment it
is not really needed. The
client can function correctly with invoking appropriate methods on the
remote interface.


Thank

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top