wood burning stoves*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Three questions ablout instructions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Three questions ablout instructions" Watch "Three questions ablout instructions" New topic
Author

Three questions ablout instructions

Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
1>
The aim is to ensure that if two customers attempt to book a seat on the same flight concurrently, then the number of available seats is definitely reduced by two, unless there was only one seat, in which case, one customer will be advised at booking time that no more seats are available.

Does that means if there are three seats available,
I should let three clients book at the same time or I should let them one by one?
2>
The integer argument indicates the record to be locked. If the method is called with an argument of -1, the entire database should be locked.

What does the INTEGER ARGUMENT mean?
Is it the seats the client wants to book?
3>Could I copy and paste the codes from Data.java to the implemention class in the RemoteAccess.java and not use Data.java?Or must I
use it in the both local and remote?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Ray,

Does that means if there are three seats available,
I should let three clients book at the same time or I should let them one by one?

You should even allow 30 clients to attempt to book a flight with only 1 seat available. Who gets the seat depends on many factors. To control this chaos you implement locking. Only the "one" client that owns the lock should be allowed to modify the record.

What does the INTEGER ARGUMENT mean?
Is it the seats the client wants to book?

It's the record number.

Could I copy and paste the codes from Data.java to the implemention class in the RemoteAccess.java and not use Data.java?Or must I
use it in the both local and remote?

You could, but I would strongly urge you not to. Remember from the instructions that the whole basis for this project is the fact that Fly By Night had these classes developed by a student and wants to now use it as a full fledged production application.
Hope this helps,
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
It's the record number.

Sorry,I still wonder what is the record number?
About 3rd question.
In server,I have three classes(RemoteAccess,FactoryConnection,DBServer).
DBServer use the Naming.rebind("Factory",f) and f is the object of the FactoryConnection(extends UnicastRemoteObject) which returns the object of the RemoteAccess(extends UnicastRemoteObject).

Is <1> or <2> right?
<1>In the RemoteAccess I have an object of Data.class and invoke the method of the Data .
like:
<2>In the RemoteAccess I have all the methods of
the data and implement all in detail not like that <1>.
And how about yours?
thanks
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Ray,

Sorry,I still wonder what is the record number?

It is the physical location of the record in the database. If you want record number 10, by calling data.gerRecord(10), the data object does a seek on the RandomAccessFile, which represents the persistant state of the database, to the tenth record in the db and returns a new DataInfo. From the returned DataInfo, you can call dataInfo.getRecordNumber() to get the record number.

Is <1> or <2> right?

<1>. Why reinvent the wheel? Just keep a reference to the Data object and pass the calls from the client on to it. As has already been pointed out, you don't even have to synchronize the methods in RemoteAccess since the Data methods are already synchronized. According to how you handle locking/unlocking you may or may not need to synchronize those methods (or the underlying data structure) to ensure thread safety.
Hope this helps,
Michael Morris
Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
hi Michael,
Thank you for reply and i've got your meaning,but one question:
To connect with your server, you should create a client program. This implementation should include a class that implements the same public methods as the suncertify.db.Data class, although it will need different constructors to allow it to support the network configuration.

what does it mean?
thanks
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Ray,
You should create an inteface that exposes all of the public methods of the Data class (which I'm sure you have already done) and you should have a class that implements that interface. Actually you will probably have two classes that implement that interface, one for local access and one for remote.
Hope this helps,
Michael Morris
[ August 25, 2002: Message edited by: Michael Morris ]
Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
Hi Michael,
That's what I've done.I just confuse that in some other topics they'll make the Data implement the
interface.But i prefer to have a reference to the Data in the RemoteAccess(extends interface) and invoke the methods of the Data like something above.Am I right?
thanks
Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
That is how I did it (RemoteData has a ref to Data -- Data does not implement an interface) and would recommend doing it because I am familiar with that approach. But there have been other ways that are really good too. Just be sure that you understand your approach and can defend it when it comes time to take your essay exam.
[ August 25, 2002: Message edited by: Nate Johnson ]

scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
hi,
I don't think I should leave the lock/unlock/criterFind in the Data.Could I remove them and where should they be?
How about yours?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Ray,
I didn't implement them in Data either, but don't take lock and unlock out of Data, just leave them as no-ops. criteriaFind is not in Data so don't put it there if you're not going to implement it in Data. You can implement them all in your implementation classes, the ones that implement the public Data interface.
Hope this helps,
Michael Morris
Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
You can implement them all in your implementation classes, the ones that implement the public Data interface.

How about the LockManager.class like others?
I think it's a good idea.
And do I have to deal with the dead client?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Ray,

How about the LockManager.class like others?
I think it's a good idea.

Just create an instance of the lock manager and provide a reference to it in your remote implementation class and when a call to lock or unlock is made call the appropriate methods on the lock manager. In your local implementation class you can leave lock and unlock as no-ops.

And do I have to deal with the dead client?

You don't have to, but it is so simple that you may as well. Just have your remote implementation class implement the Unreferenced interface and in the unreferenced() method call unlock on all the locks held by the client. You'll have to keep a Collection (probably a Set) of currently held locks. Just add the record to the Collection in the lock method before calling lock on the lock manager and remove in unlock.
Hope this helps,
Michael Morris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Three questions ablout instructions