aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: Notes on a design that passed 389/400 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: Notes on a design that passed 389/400" Watch "NX: Notes on a design that passed 389/400" New topic
Author

NX: Notes on a design that passed 389/400

Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11503
    
  95

Hi everyone,
A general discussion on Ken's design and alternatives to it is good, but please don't post code in this discussion.
If you want to discuss some aspect of your code, please open a separate thread to do so. Also be aware that in general we allow small sections of code - for example an individual method - but you should not post code for a major section of the assignment. So posting all the code for your locking solution (which is identified in the instructions as a major section of the assignment worth 20% of the marks) is definately not allowed.
Thanks.
Andrew
[ November 21, 2003: Message edited by: Andrew Monkhouse ]

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
Bill,
I synchronized on my Contractor cache while iterating over it during search (find) operations.
kktec
SCJP, SCWCD, SCJD
"The journey is the reward."


kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
Derek Canaan
Ranch Hand

Joined: Nov 05, 2003
Posts: 64
Hi Ken,
Congrats for the great results. May i ask a few more questions?

Locking
======
... I specified a contract in the Javadoc that calls for any potential users of the locking API to invoke lock/process/unlock as a sequence within the context of a single method call which guarantees it will happen within a single thread of execution.

1. Where else do you document this contract apart from the book() method? Is it necessary to document contract in lock(), unlock() and the process methods invoked in between?

Networking
========
... RemoteServicesImpl extends UnicastRemoteObject and implements RemoteServices. It has 2 parts, the implementation of RemoteServices (i.e. the 2 Services methods) and static getServices methods that allow the clients to get a Services instance that is either an RMI server for the Network Server application functionality or its stub for the Network Client application functionality.

2. Can you elaborate on the role differences between the two Services instances: RMI server for the Network Server application functionality and its stub for the Network Client application functionality?

Networking
========
...Since all of the locking occurs in a single method call in the Network Server's JVM, there is no need to worry about the RMI connection dieing in the middle of a locking operation.

3. What if the RMI connection dies in the middle of that single method call, before all the statements in that method are completely executed?
4. How does your application invoke the "alone" mode? Did you have a connector class that allow you to choose "alone" mode and "networked" mode (like in Max's book) by invoking getLocal() and getRemote() respectively?
Thanks in advance,
Derek
Aleh Barysevich
Greenhorn

Joined: Dec 03, 2003
Posts: 6
Hi Ken!
Congrats!!! Impressive score!
I'm a newbie at this forum, so I'd like to ask just one short question:
did you have cookies in your lock()/unlock()/... methods provided by Sun?
Thank you,
Aleh
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
Aleh,
did you have cookies in your lock()/unlock()/... methods provided by Sun?

No. I just needed to associate a Contractor with the calling thread in my Lock class.
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
Bill,
I didn't notice your last post on this thread so I'll take this opportunity to bump it for those who haven't seen it and answer your question
I did not synchronize read/search and I did use a cache of Contractors.
Peter Yunguang Qiu
Ranch Hand

Joined: Nov 22, 2003
Posts: 99
Hi, Ken:
Congratulations! You got a greate high marks.
Could I ask a question:
I used a Contractor class to put an O-O framework around the String arrays that represent the record data.
Is Contractor class neccessary? Is It means good OO design? What is the benifit to use this class? How about just use a string array String[] record to represent the record data and trasmit it through networking? Because string array is serializable, and it is faster and easier to implement. To use Contractor class, you have to convert it to a string array or convert string array to Contractor back and forth sometimes.

Could you explain.
-------------
Or, Can Someone else give me some help and explain it to me?
thanks.
Peter
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
Is Contractor class neccessary?

No.
Is It means good OO design?

It can help.
What is the benifit to use this class?

It makes the use of some of the data easier for most of the application by transforming it into natural data types instead of String.
How about just use a string array String[] record to represent the record data and trasmit it through networking?

You can certainly do that if that is your preference.
Because string array is serializable, and it is faster and easier to implement. To use Contractor class, you have to convert it to a string array or convert string array to Contractor back and forth sometimes.

The Contractor class makes the data easier to work with, especially the comma-separated-value String of specialties that is in my assignment, which is converted to a list of Strings. It might even be faster too depending upon how it is used as the non-String data is only converted once on input and once on output rather than any time it is used.
Peter Yunguang Qiu
Ranch Hand

Joined: Nov 22, 2003
Posts: 99
Thak you very much Ken.
My assignment is URLyBird. I feel Using String[] record is conveniet than using a class Record. But I feel most people using a class Record. I just know class Record is easier to become a java bean but I don't know what other benifit it has. The table model is easier to use a String[].
sun's interface DBAccess's method:
public String[] readRecord(long recNo)
also use a string array as the return type. The data can be transmitted directly from db to table model without converting. I don't know why many peple use a class Record. Anyone has a good explanation?
Peter
police sun
Greenhorn

Joined: Jan 02, 2004
Posts: 1
Don't you think you guys are getting too much detail and was taking
advantage of other people? Use your own brain!
Dora Gal
Greenhorn

Joined: Jan 03, 2004
Posts: 15
Hello Ken,
Have you ever seen any convenient GUI frontend for the logging framework introduced in 1.4? I am looking for something like logFactor5 for log4j.
I would also like to ask you about the exact title of the book that is usually referred to as Max's book?
Thanks a lot in advance,
Dora
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hi Dora,
Try the first link below.
All best,
M


Java Regular Expressions
Louis Tong
Greenhorn

Joined: Sep 28, 2005
Posts: 1
Using Swing/AWT is a must? can I use SWT instead of Swing?
Frans Janssen
Ranch Hand

Joined: Dec 29, 2004
Posts: 357
Originally posted by Louis Tong:
Using Swing/AWT is a must? can I use SWT instead of Swing?

Hi Louis,

Using Swing (but not AWT) is a must. It is not allowed to use SWT or any other third party software.

Frans.


SCJP 1.4, SCJD
rinke hoekstra
Ranch Hand

Joined: Apr 06, 2007
Posts: 152
Sorry for reraising this old thread, but I think it is so interesting, that I choose to follow this design, but I have some questions on it.

Summarized:

I have a RemoteService interface, which extends the Service interface. The Service interface has only two methods, book and search. The RemoteService interface needs nothing more, so it is empty.
The RemoteServiceImpl class is the only implementing class, and it (of course) again has only the book and the search method, which implementations are very simple: they just call ServiceImpl.book and ServiceImpl.search.

As all the methods throw already IOException, I don't need to bother about the obligatory RemoteExceptions, because this is a subtype of IOException.

In the original design by Ken, a lot of singletons are used. Mostly I cannot see why.
If I have it well:
* DataAccess is singleton
* LockManager is singleton
* ServiceImpl is singleton
* RemoteServiceImpl is singleton
\

Now for the first two, I can see the reason. But why do the ServiceImpl and RemoteServiceImpl need to be singleton?

Rinke


_ _ ________________________ _ _ <br /> <br />Just SCJP (but 93%)
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
My Contractor service in B&S is also singleton. The reason is, that it has no instance attributes, so there is no need to have mutltiple instances, because they would be the same. (unless you are using those instances to identify clients in your locking schema)

On the other hand, my Data and LockManager class are not singletons, because if later sombody says: "hey we need to support also customer_table", I just create Data instance for that file.
rinke hoekstra
Ranch Hand

Joined: Apr 06, 2007
Posts: 152
Originally posted by John Stone:
My Contractor service in B&S is also singleton. The reason is, that it has no instance attributes, so there is no need to have mutltiple instances, because they would be the same.


Hi John,

Thanks for your answer. I can see they would be the same, but "having no need to have multiple instances" is not the official reason for implementing a singleton. That would be: "only one is ALLOWED", not "there is no need for more". Isn't the right question: "does it harm to have more than one?"?

Would it harm to have more than one service instance?
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
Yes, it would harm in my case.
In my implementation each contractor service creates Data class (as its data source), and my Data class states, that there should be only one instance of Data class per one db file. As the solution I made service singleton.

From singleton def. on wiki:

and I can interpret that coordination as access to one instance of Data class.
rinke hoekstra
Ranch Hand

Joined: Apr 06, 2007
Posts: 152
Originally posted by John Stone:
Yes, it would harm in my case.
In my implementation each contractor service creates Data class (as its data source), and my Data class states, that there should be only one instance of Data class per one db file. As the solution I made service singleton.

From singleton def. on wiki:

and I can interpret that coordination as access to one instance of Data class.


Hi John,

hmm interesting sollution. So your Data is not singleton, in the sense that it does not enforce only one instance, but because your service is singleton, and because it is the only one having an instance of Data, there will be automatically always one instance of Data.

However, here you make the assumption that it is more likely that the IT Manager would want to extend the Data classes, rather than the Service functionality.
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
Originally posted by rinke hoekstra:


Hi John,

hmm interesting sollution. So your Data is not singleton, in the sense that it does not enforce only one instance, but because your service is singleton, and because it is the only one having an instance of Data, there will be automatically always one instance of Data.

However, here you make the assumption that it is more likely that the IT Manager would want to extend the Data classes, rather than the Service functionality.


I was thinking about some class on top of Data class, which would provide mapping <filename, Data class instance> and will guarantee, that there is always only one Data class one per db file, but.. (perhaps we are hijacking this thread.)
Grary Stimon
Ranch Hand

Joined: Sep 30, 2008
Posts: 42
Hi Ken,

I've found your various writings/references on RMI and B&S very helpful...

Did you return a TableModel or some other type useful to a GUI implementation from your book or search methods?

Thanks,

Grary
Vasya Pupkin
Ranch Hand

Joined: Dec 06, 2006
Posts: 39
Grary Stimon wrote:Hi Ken,

I've found your various writings/references on RMI and B&S very helpful...

Did you return a TableModel or some other type useful to a GUI implementation from your book or search methods?

Thanks,

Grary
originally posted 11/12/2003
Do you really think he cares after more than 5 years?


SCJP, SCJD
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5514
    
  13

Hi Grary,

I don't think it is a good idea to wake up sleeping threads (like Vasya already indicated).

I don't know if it is a good idea to answer your question here, but I'll do it (and hope it helps):
- My search-method is returning a simple java.util.List, because your service could also be used by a web-application (in a web-environment), so a TableModel would be useless then.
- My book-method is returning nothing. When a booking can't succeed because it was already booked for example an exception will be thrown from the service (and is caught at the gui).

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Grary Stimon
Ranch Hand

Joined: Sep 30, 2008
Posts: 42
Thanks Roel.

Yes, the thread is old, but I was following Ken's design closely and saw little harm in inquiring after that small detail if he were happy/available to answer.

Grary
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: Notes on a design that passed 389/400