Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question regarding Design

 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I have just finished my last undergraduate examinations and now i can now fully face my developer exams!And now i would like to ask some questions that would enable start actually writing code and move from the design phase!
I was going through Max's book last night and i stumbled upon something(i missed it totally)! On page 126 and 127 where He was deciding on "Discussion point: How will the DVDDatabase be used"! He chose having multiple instances of the Dvd Database rather than have one instance of the Dvd Database and he tracks all of the several instances via a 'private static Vector' to keep track of locked records! I was wondering if i could follow the same procedure(and of course document why i chose this)! I intend to have a private static HashMap of locked records and an ArrayList of Contractor Objects! Having a private static HashMap, i would be able to keep track of the various locked Objects and also freely have multiple instances of Data.java!

I would like to add an Adapter class to carter for the defiency of the provided Interface!This means the client doesnt call for example lock() delete() unlock() itself but via a method of an interface i would have to create!My question is: Does this violate anything at all, or it is standard practise! I apologise if i sound confused, i am still learning!
Your prompt advice would be highly appreciated as usual! Have a nice day!
[ November 21, 2005: Message edited by: Saheed Adepoju ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saheed,

There are several concepts you have mentioned that are commonly implemented by other forum members.

Having multiple Data objects which act as keys or values in a Map of locked records is very common. As is creating an Adapter class to provide business logic.

I am not sure what purpose the ArrayList of Contractor Objects serves, would you care to expand on that idea?

Regards, Andrew
 
santosh kulkarni
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saheed and others,

I am close to completing my SCJD assignment.
IMHO there is no requirement that we have to support multiple instances of Data class.

In fact my assignment clearly says the following

You may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple concurrent clients of your server.

I took the simple approach of Server having a member object of type Data.

I'd appreciate any comments, corrections
Santosh
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Santosh,

You are correct - there is no requirement for you to have more than a single instance of the Data class. In fact implementation is completely up to the programmer - you could have a single instance of Data, or define Data as a singleton, a multiton, or have as many instances as you like - there are no restrictions.

Having one instance of the Data class per connected client is one popular way of handling those interfaces where the lock method does not return a cookie.

Regards, Andrew
 
santosh kulkarni
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
you wrote:
Having one instance of the Data class per connected client is one popular way of handling those interfaces where the lock method does not return a cookie.

If I only instantiate one instance of my class called Server (and bind it to the rmi registry), which has Data as a member variable, there is one Data object period not per instance.
Also, I didn't get why you qualified your statement with 'where lock method does not return a cookie'.

Could you please elaborate?
Thanks,
Santosh
 
Lara McCarver
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some interfaces pass cookies around, e.g. the lock() method returns a cookie or the unlock() and update() methods takes a cookie as one of their parameters, something like that. (I don't have that assignment so I am not sure exactly how it works.) Cookies are one way of ensuring that only the client that locked a record is allowed to unlock it, or to update it while it is locked.

If, like me, you have an interface where you are not passing around cookies, it is still desirable to make sure that only the client that called lock() on a record is allowed to unlock() it. So even for this interface, the server would ideally keep track of which records are locked by which client.

If you use multiple RMI servers, one per client, as they do in the SCJD book, then the different RMI servers can ultimately become a way to keep track of which client is calling a method, so that lock & unlock can be matched up. For example, each RMI server can create a separate Data object which lasts throughout the RMI session, and the uniqueness of the each Data object can be used to distinguish the clients. There are lots of variations... each Data object can create a token, or be passed a token, or create an Object.

Lara
 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day all
Thanks Andrew for responding! I intend to use a Value-Object design pattern for the various data in the file provided by creating objects out of them! Basically having a cache of the records and updating it accordingly!
I have a problem right now(a little one: I would love a little push )
When i write the code for say find(), i would need to catch the IOException, do i wrap it unto say RecordNotFoundException(Given Exception)? Is this appropriate? Thanks for your anticipated response!Have a lovely day!
 
santosh kulkarni
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I have the assignment(B&S) that asks us to pass the cookie around. So in that case it should be perfectly acceptable even desirable to have a single Data object inside of a single RMI server. Oh I see, now Andrew's comment makes sense. I feel better now, I was questioning my design since everybody was talking about multiple RMI servers and Singleton pattern for Data etc.
Thanks all
Santosh
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saheed,
When i write the code for say find(), i would need to catch the IOException, do i wrap it unto say RecordNotFoundException(Given Exception)? Is this appropriate?
I think your question is a little too generic at present - we do not know what caused the IOException, so it is a little hard to decide what is appropriate.

If the IOException was caused by you reaching the end of the file without finding the desired record, what does this mean to you?

Alternatively, if the IOException was caused by data corruption, what should you do?

Regards, Andrew
 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Andrew for your reply and here are my thoughts:

First of all my instructions says:
Any methods that throw RecordNotFoundException should do so if a specified record doesnt exist or is marked as deleted in the database file
Now, does this mean that if say example i get to the end of a file and dont get to see the record i could wrap IOException unto RecordNotFoundException? Or do i do a check for the type of exception thrown(say using e instanceOf IOException and then wrap it unto RNF?

Also i have a little confusion with the specs:
In my specs it says:
... therefore your locking system only needs to be concerned with multiple concurrent clients...
I perfectly understand this, but since i am using an Adapter class and RMI, when a client requests for Local Mode/Non-Networking, the clients gets and instance of the Adapter class; and since the Adapter class contain business methods that call lock() say update() and then unlock()(Max's concepts); doesnt it mean that there is still an element of locking in non-network mode ? As usual your prompt responses and advice will highly appreciated!Have a lovely day
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saheed,
First of all my instructions says:
Any methods that throw RecordNotFoundException should do so if a specified record doesnt exist or is marked as deleted in the database file
Now, does this mean that if say example i get to the end of a file and dont get to see the record i could wrap IOException unto RecordNotFoundException? Or do i do a check for the type of exception thrown(say using e instanceOf IOException and then wrap it unto RNF?
Interesting. In my assignment, the find() method does not throw RecordNotFoundException although the read(), update(), delete(), lock() and unlock() methods all throw it. This to me seems logical (but then again, Sun have indicated that some parts of some versions of the assignment have been deliberately written to imitate specifications written by clueless users ).

Since your find method is defined in your instructions as throwing RecordNotFoundException then you should throw it if there is no match for the given criteria. However I would not use it to wrap any other exception - I don't think there is a need:

In my mind the find() method should never see an EndOfFileException - you know how big the file is, so there is no reason why you should ever go beyond the end of file. If you do go beyond the end of the file when you already know it's size then it probably means that your file is corrupt. So in this case if you received an EndOfFileException you would throw some other Exception (DatabaseCorruptException extends RuntimeException?) that you can use to tell the server that the database is corrupt (and therefore stop accepting requests from clients, log information, shut down...) and possibly also send a message to the client to warn them that there was a problem.

Simarly with any other IOException while reading the file - it probably indicates that the file is corrupt, and should be handled appropriately.

If your find() method is calling the read() method (which throws RecordNotFoundException itself) instead of reading the file directly then I think your find() method should log that a deleted record was read and move on. The end user is not interested in this.

In my specs it says:
... therefore your locking system only needs to be concerned with multiple concurrent clients...
I perfectly understand this, but since i am using an Adapter class and RMI, when a client requests for Local Mode/Non-Networking, the clients gets and instance of the Adapter class; and since the Adapter class contain business methods that call lock() say update() and then unlock()(Max's concepts); doesnt it mean that there is still an element of locking in non-network mode ?
Why not? It won't hurt to have this in single user mode (and performance is not likely to be affected when there is only one user ). And the bigger advantage is that you have one set of code that is always run no matter whether you are in single user mode or multi user mode. There is less chance of something working in single user mode but failing in multi user mode with only one connected user. In my opinion using the locking code in both instances is an advantage!

As usual your prompt responses and advice will highly appreciated!
Just some friendly advice - sometimes a comment like that can have the wrong effect. You might want to look at "ease up" for information on why.

Regards, Andrew
 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot Andrew!
Well i guess i didnt formulate my post very well, but my find() doesnt throw a RecordNotFoundException, when i re-read through my post i realised it had meanings that my find() method throws a RecordNotFoundException! But your reply gave me an insight into my question! So basically if my
read() method(which throws RecordNotFoundException) threw an IOException, it is safe to assume that i could warp the exception unto a RecordNotFoundException?
And also thanks for the "Ease Up" note, it is absolutely noted!

One more thing i have been a bit confused about:
Which method is used when we are about to book for a particular record? I am assuming it is the Update() which would allow a user to write to the field of owner of the datafile! Is this so?
[ November 24, 2005: Message edited by: Saheed Adepoju ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saheed,
So basically if my read() method(which throws RecordNotFoundException) threw an IOException, it is safe to assume that i could warp the exception unto a RecordNotFoundException?

The same logic applies as per my discussion on handling IOException within the find() method. You need to ask yourself: under what circumstances could an IOException be thrown, and what is the logical method of handling it?

Which method is used when we are about to book for a particular record? I am assuming it is the Update() which would allow a user to write to the field of owner of the datafile! Is this so?
Well the update() method will have to be called in order to save the customer number to file. But you will probably have to call some of the other methods before and after the update. Hint: How can you be absolutely sure that no other user has already booked the record you are about to update?

Regards, Andrew
 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Thanks for alot for your insight,i will think it through concerning the IOException thrown and think of a logical time it should be wrapped around a RecordNotFoundException! Thanks also for the book() business function, i know the step involved would be to lock() then update() and then finally unlock() the record so that it would be available for use by other waiting threads!And now i have another question(Hope it aint getting too much, i need to burn my design unto my brains before i start writing code )
First question: What is a property file(suncertify.properties) and how is one created?In my specs, It says Such configuration must be stored in a persistent between runs of the program. Such configuration information must be stored in a file called suncertify.properties...

How do i implement the flag mode: alone and server; is this linked to this properties file, if so how do i go by implementing one? Thanks. Have a lovely day!
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saheed,
Thanks also for the book() business function, i know the step involved would be to lock() then update() and then finally unlock() the record
You would probably want something else in that book() business function as well - something to check that the record has not yet been booked?

What is a property file(suncertify.properties) and how is one created?In my specs, It says Such configuration must be stored in a persistent between runs of the program. Such configuration information must be stored in a file called suncertify.properties...
Take a look at the java.util.Properties class. Sun have a "Using Properties to Manage Program Attributes" tutorial on this.

How do i implement the flag mode: alone and server; is this linked to this properties file, if so how do i go by implementing one?
It is not really linked to the properties file (although both modes will use the properties file, and they might have some different properties for the different modes. But the key thing here is that your program will be using the properties file - it is not the properties file that determines the mode.

When you start any Java program, it must start in the method with the signature public void main(String[] args). You will have to look at those arguments to determine what mode you should start.

It can be useful to remember that the main() method is just like any other method, and can be called by any other class. So you could start by creating an application that only works as a server like so:And then later create a utility class that can look at your flag and call the appropriate other application:

Another tip for you - in trying to get people to read (and respond to) your questions, it can help to Use A Meaningful Subject Line. So instead of a subject line of "Question regarding Design", you could create several separate posts, each with a more meaningful subject line. For example you could have created a topic just asking about how to handle the properties file. You are then more likely to get others answering the question with tips and comments on issues they had (if any), plus the next person who wants to know about the properties file will be able to see that there is already a topic with a subject line that looks interesting.

Regards, Andrew
 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot Andrew for your insights and also the links provided! I will also make sure i start new threads for new questions! Have a nice day!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic