• 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

Three questions ablout instructions

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ray Cheeny
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ray Cheeny
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic