• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: Notes on a design that passed 389/400

 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill,
I synchronized on my Contractor cache while iterating over it during search (find) operations.
kktec
SCJP, SCWCD, SCJD
"The journey is the reward."
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't you think you guys are getting too much detail and was taking
advantage of other people? Use your own brain!
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dora,
Try the first link below.
All best,
M
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Swing/AWT is a must? can I use SWT instead of Swing?
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.)
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Grary Stimon
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic