File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Protocol -- help needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Protocol -- help needed" Watch "Protocol -- help needed" New topic

Protocol -- help needed

Charles Dupin
Ranch Hand

Joined: Oct 18, 2002
Posts: 94
Well, the question is on the purchasing of Fly by Night tickets. Which of the 2 protocols is better. If you think they are both poor, please advice.
Protocol 1.
2-check if tickets are available
4-ask client if he still wants tickets
6-buy tickets if still possible
Protocol 2.
2-buy tickets if possible
4-ask client if still ok
6-rollback if client refuses
I dont like protocol 2 because of the possibility of session break after step 3 . I dont like in session 1 the enventuality that ticket may be sold out at step 5 but I think this protocol is better .

Charles.<br />(SCJD2)
Dave Teare
Ranch Hand

Joined: Oct 09, 2002
Posts: 80
My plan is to ask the user if they are sure they want to purchase the tickets before any interactions with the server occur.
1. Select a list of flights from the server.
2. Display results in a JTable
3. User asks for X seats on flight Y
4. Validate that there are X seats available on flight Y by checking the currently displayed flight information. I know this may be stale data, but I feel it is okay.
5. Ask user if they are sure.
6. If yes, call the researveFlight(X,Y) method of the DataFacade.
That's it! The Facade will handle the locking and unlocking, and any other business logic.
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
I'd advise you to keep things simple. This is not a real-world app. You simply have to prove your ability to implement a simple booking. I've heard that people got deductions because they did too much.
Here's what I did (and passed):
A table displays all flights and the available number of seats (at the time of loading the data).
The user double-clicks the flight (or presses a button, which is enabled when a flight is selected, or presses a short-cut for booking), and a small window pops up, containing all of the flight. In addition the window has a widget for entering the number of flights to book. And then the user may click the buttons "ok" or "cancel".
"Ok" called the book() method, and this is what it did:
  • lock the record
  • get the record from the database
  • when enough seats are available, adjust number of available seats, write record back to the database, and asynchronously inform the user that the booking was successful
  • when the number of available seats is less than the booked seats, inform the user that there are not enough seats available (also asynchronously)
  • unlock()

  • The intended group of users is not the general public, but the employees of the travel agency. This means, implementing this kind of "Do you really want to..." popups is overkill.
    [ November 11, 2002: Message edited by: Mag Hoehme ]

    I agree. Here's the link:
    subject: Protocol -- help needed
    It's not a secret anymore!