This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Review please. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Review please." Watch "Review please." New topic
Author

Review please.

Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hello to all.
Please review my design and revert. I'me almost finished with the coding (just need to review some
internal details of some methods and also review the javadoc comments) and I will move to the help
system, readme and the design choices (I must see a lot of papers that I've writen during the last
couple of months to write the design but...).
The packages are as follows:
suncertify.db
-------------
public interface DataInterface extends Remote - All the public methods of Data class throwing
the Exceptions already defined in Data class plus RemoteException
public class FieldInfo implements Serializable - No changes
public class DataInfo implements Serializable - No changes
public class DatabaseException extends Exception - No changes
public class Data implements DataInterface - Changed the deprecated methods to read and write
using the default encoding. Method lock and unlock are left blank.
public class DatabaseConnectionFactory - Returns the local or remote connection
public class LockManager - for locking and unlocking
suncertify.db.table
-------------------
public class DataTableModel extends AbstractTableModel - To handle any database that has been
created using a Data class
public class DataTableHeaderRenderer extends JPanel implements TableCellRenderer - To create the
table header showing the field names in 2 lines - It uses any table created with Data class
suncertify.utils
----------------
public class NumericDocument extends PlainDocument - A class that only accepts numbers
public class NumericTextField extends JTextField - A JTextField that only accepts numbers
public class ExtensionFilter extends FileFilter - Filters a file by it's extension
public class FileNameFilter extends FileFilter - Filters a file by it's name
public final class ExceptionDialog - To show errors
suncertify.client
-----------------
public class FBNClient extends JFrame - Shows the initial dialog that allow the user to choose
from local or network mode.
public final class FBNFieldConstants - Constants with the position of each field in the database
and also the lenght of each field
public class LocalDatabaseImplementation extends DataInterface - The local data class. Throws only
the exceptions defined in the Data class
public class FBNMainWindow extends JFrame - The main program window. Two threads are used, one
to read/search the database and other to process the reservation. The main window is very
simple, a toolbar on the top with 4 buttons (search, reserve, help and exit). Above its a
panel with two combo boxes filled with the origin airport and destination airport. We select
what we want to view here, and after we press the search button (maybe the search button
should be just after the destination airport combo!). Above I have the JTable and at the
bottom I have other panel where I put some information when any of the threads is running
(like a status bar). When a reservation is being made, a window apears informing the user
to wait while we process the request.
public class FBNAsksNumberOfSeatsToReserve extends JDialog - Asks how many seats to reserve in the
selected flight
public class FBNProcessReservation - Makes the reservation. All the exceptions thrown are handeled
here. No exceptions thrown to the main window.
public class NoSeatsAvailableException extends Exception
public class NotEnoughSeatsAvailableException extends Exception
suncertify.server
-----------------
public interface DataInterfaceFactory extends Remote - One method defined here
(public DataInterface getDatabaseInstance() throws RemoteException).
public class FBNServer extends UnicastRemoteObject implements DataInterfaceFactory - Just returns
a new DataInterface
public class RemoteDataImplementation extends UnicastRemoteObject implements DataInterface - The
database instance that is passed to each client.
One finel note, no command line parameters to start the client. All information is gathered from
a window. The only that accepts command line parameters is the server that wants the database location.
Thanks,
Miguel
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Miguel,
I have couple of questions regarding the following statement

suncertify.server
-----------------
public interface DataInterfaceFactory extends Remote - One method defined here
(public DataInterface getDatabaseInstance() throws RemoteException).
public class FBNServer extends UnicastRemoteObject implements DataInterfaceFactory - Just returns
a new DataInterface
public class RemoteDataImplementation extends UnicastRemoteObject implements DataInterface - The
database instance that is passed to each client

1) For your FBNServer you are going to return new DataInterface? Why? Shouldn't you be returning the same RemoteObject that exists?
2) What are the flow of things that happen when a remote client tries to connect?
Please explain
Thanks
Amish
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by Amish Patel:
Hi Miguel,
I have couple of questions regarding the following statement

1) For your FBNServer you are going to return new DataInterface? Why? Shouldn't you be returning the same RemoteObject that the first client created for a particular filePath? Meaning Client A connects Remotely to a server he gets a RemoteData, Client B connects remotely to the same server he should also get the same RemoteData correct?
2) What are the flow of things that happen when a remote client tries to connect?
Please explain
Thanks
Amish
Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hello Amish.
For the FBNServer i've used a RMI Factory so that any client that connects to the server gets a new RemoteDataImplementation. With this, I will have the clientID that's needed in order to lock and unlock the records.
The Data class used by the RemoteDataImplementation is the same for all the clients that connects to the server (is static), but any client that connects get's a new object created from RemoteDataImplementation.

In the client part I have a factory that returns a DataInterface. If in local mode, it creates a new instance of the Data class, if in network mode it calls this method from the server.
Hope that i've been clear.
Miguel
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Miguel
Regarding Data being static.....
What if in the future rather than having db.db file there are two files, db.db and db1.db. How will your current implementation handle this? I am just trying to understand and not criticizing your design.
-Amish
Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hello again.
You are right . I think that the best is to define the static Data in the FBNServer class and pass it to the RemoteDataImplementation.
The Data for now is still static and if we want to add "db1.db" we add a new static Data to the FBNServer and a new method to the DataInterfaceFactory that will return a new instance of RemoteDataInterface but with a new Data.
I think is this . I'm a bit sleepy and tired now. I think that I will go to bed . Tomorow we will discuss some more things!
Thanks,
Miguel
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

The Data for now is still static and if we want to add "db1.db" we add a new static Data to the FBNServer and a new method to the DataInterfaceFactory that will return a new instance of RemoteDataInterface but with a new Data.

So, if you need to service 5 databases, you will have 5 static instances of Data and 5 different methods to return them? Something is wrong...
How about one single method in the factory and 5 non-static instances of Data in a collection instead?
Eugene.
[ January 27, 2003: Message edited by: Eugene Kononov ]
Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hello.
Well, I must say that you are right Eugene, but like I've writen yesterday I was sleepy and tired (after a weekend I need other one ).
Now I've changed the remote server as follows:

The Map here will be filed with all the database names as key plus a RemoteDatabase that contains a instance of Data class and LockManager.
When I ask for a DatabaseInstance, I check in the map if I have it opened and then I return a new DataInterface. Like this I can have multiple databases opened by the server. The parameters that the server accepts are:
The port where "rmiregistry" is
The path where all the databases are
A list of the databases to open separated by comas
Some of the code:



I think that everything is OK with the server,
Comments please (not only to the server, but to everything).
Thanks,
Miguel
Raffe Paffe
Ranch Hand

Joined: Feb 24, 2003
Posts: 92
Hi,
What is the relationship between RemoteDatabase and RemoteDataImplementation ?
Thanks


Free software is a matter of liberty, not price.
Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hi Raffe.
RemoteDataImplementation is the Data class in the server side.
RemoteDatabase has a instance of the RemoteDataImplementation and LockManager and a instance of RemoteDatabase is created for each database that the server opens.
Miguel
Raffe Paffe
Ranch Hand

Joined: Feb 24, 2003
Posts: 92
Thanks Miguel!
So, the RemoteDatabase class is in the suncerify.server package?
When doing loc/unlock in the RemoteDataImplementation class it just calls the LockManager? Must that method be syncroinzed?
I think I am starting to understand your design now. Very nice work!
Raffe
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Miguel,
Very nice job, just a few minor things:

suncertify.db.table
public class DataTableModel

I don't think that suncertify.db is the right package for DataTableModel. The fact that you put your table model class into the database package tells me that you might have some dependency between the table model and the database (there should be none). The table model doesn't even have to import the database classes.

LocalDatabaseImplementation

"LocalDatabaseImpl" is a more or less standard abbreviation.

a toolbar on the top with 4 buttons (search, reserve, help and exit).

I wouldn't put the "exit" button on the toolbar, -- "exit" is not a tool.

public class FBNAsksNumberOfSeatsToReserve extends JDialog

Class name is too long and is a verb, should be a combination of nouns/adjectives. How about "NumberOfSeatsDialog.java"?

public class NoSeatsAvailableException extends Exception
public class NotEnoughSeatsAvailableException extends Exception

Well, NoSeatsAvailableException is just a special case of NotEnoughSeatsAvailableException, so I would use just the latter one for simplicity.

The only that accepts command line parameters is the server that wants the database location.

My understanding of the requirements was that the database location needs to be specified for local mode only, and therefore when you start the server, you don't need to provide this info. But I may be wrong here.
Eugene.
Raffe Paffe
Ranch Hand

Joined: Feb 24, 2003
Posts: 92
Miguel, you wrote:
For the FBNServer i've used a RMI Factory so that any client that connects to the server gets a new RemoteDataImplementation. With this, I will have the clientID that's needed in order to lock and unlock the records.

Does that mean that you use RemoteDataImplementation.hashcode() as client id?
Thanks
Ralf
Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hi Eugene.
I've made some changes since i've put this post.
First, I don't throw 2 exceptions when the reservation fails. Only one exception with different messages depending on the problem.
Regarding the server accepting parameters, what would be the point for doesn't accept parameters if the server can open multiple databases? I could force the server to open the db.db database in a hardcoded directory, but I belive that it's better to supply parameters with the directory where the database file is/are. Besides the databases directory, we can have a directory with several databases but we only want the server to open one database and for this reason I have one parameter with the name of the databases to open separated by comas.
One final note, I've decided to remove the toolbar. I don't see a use for it in this assignment.
Thanks,
Miguel
Burk Hufnagel
Ranch Hand

Joined: Oct 01, 2001
Posts: 814
    
    3
You might want to re-think removing the toolbar.
I seem to recall a fairly recent post indicating that it is expected. Search for comments by Kathy Sierra... someone failed & got a zero for the GUI. Kathy posted some info on what the graders are probably looking for.


SCJP, SCJD, SCEA 5 "Any sufficiently analyzed magic is indistinguishable from science!" Agatha Heterodyne (Girl Genius)
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

Regarding the server accepting parameters, what would be the point for doesn't accept parameters if the server can open multiple databases?

One approach is to start the server with the database names as parameters. Another approach is to start the server without any parameters and let the client request a particular database. The latter approach doesn't preclude the server from serving multiple database files.
Eugene.
Raffe Paffe
Ranch Hand

Joined: Feb 24, 2003
Posts: 92
One approach is to start the server with the database names as parameters. Another approach is to start the server without any parameters and let the client request a particular database. The latter approach doesn't preclude the server from serving multiple database files.

So what you mean is
network
java client.jar www.server.com 1234 c:\tmp\db.db
local
java client.jar c:\tmp\db.db
You must supplie the directory when using network mode. That is not so good, is it?
Thanks
Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hello.

So what you mean is
network
java client.jar www.server.com 1234 c:\tmp\db.db
local
java client.jar c:\tmp\db.db

I think that what Eugene means is:
Network
java -jar client.jar db.db
Local
java -jar client.jar c:\tmp\db.db
In server mode, the server knows where to look for the database file (i.e. the server knows the directory where the database files are) and when a client requests to open one database, the server looks to see if the database as already been opened or not. If opened, it returns a instance to the remote Data and if not opened, the server opens the database and returns the instance of the database to the client.
Am I right Eugene?
Thanks,
Miguel
Raffe Paffe
Ranch Hand

Joined: Feb 24, 2003
Posts: 92
Could you please explain a little more about your gui? Thanks
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

I think that what Eugene means is:
Network
java -jar client.jar db.db
Local
java -jar client.jar c:\tmp\db.db
In server mode, the server knows where to look for the database file (i.e. the server knows the directory where the database files are) and when a client requests to open one database, the server looks to see if the database as already been opened or not. If opened, it returns a instance to the remote Data and if not opened, the server opens the database and returns the instance of the database to the client.
Am I right Eugene?

Yes, you got it. But again, this is just one alternative. I actually chose a different approach:
java -jar client.jar (in both local and networked modes)
Once the client starts, the user can select File|Connect To Database and indicate the connection mode and provide the required parameters.
Eugene.
Raffe Paffe
Ranch Hand

Joined: Feb 24, 2003
Posts: 92
In server mode, the server knows where to look for the database file (i.e. the server knows the directory where the database files are) and when a client requests to open one database, the server looks to see if the database as already been opened or not.

How does it know what direcory to look in? Can you assume one or send one as a parameter to the server?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Review please.
 
Similar Threads
general design review
Server design
Design Review part III
Final review - PLEASE READ
Final comments