• 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

Trouble understanding the Data.java logic

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I`m having trouble with the whole logic of the file. I have implement the following class


now my problem, to for instance update a record i have to provide a cookie.
but i can only get a cookie if i execute lock(recno). so should i create another class, implement the exact same methods and then have something like the following code??



would this be right, or should i have the lock/unlock in my main data class. They way i`m doing it will work, but i does`nt look right.
using sun`s provided interface class then i create my own Data.java class
that implements that class, and now i`m creating a third class that looks they same as the sun interface class to actually lock,update,unlock.

Thanks
Derick
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Derick,

OK... what you are describing is creating a proxy class on the server which has the same methods as Data but without the lock/unlock method - in other words you are hiding the need to lock/unlock from clients.

I know from reading other threads that people have passed the exam by following this strategy, although I personaly do not like it. My problems with it are twofold. First off, by hiding the lock/unlock from clients you are enforcing a locking strategy. This may be OK for the scenario we are given but who knows what locking strategy future clients will want/need to enforce? Secondly, I may be wrong but if Sun felt it important enough to include the cookies in the method signature, this says to me that they too important to hide at the first opportunity.

Your alternative is to pass the resposibilty for the locking through to the client, who must of course follow the (documented) need to follow the lock/update/unlock procedure.

These are just my thoughts on it, although I would say that you should go with whichever method you would be most comfortable justifying/defending.

Cheers,

Jon
 
Author
Posts: 65
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The option of passing the locking responsibility to the client brings a lot of complexivity to the application. Once you follow that strategy, you should track inactive/disconnected clients, in other words, make your server stateful.
On the other hand, by using a proxy or a facade you make the locked operations atomic, which release you from the need of mantainig conversation state with the client, makes your life easier, the application simplier, and once you'll want to change the locking strategy, you can switch the facade, or get rid of it totally.
 
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 Derrick,

I think you have missed the value of the lock methods: specifically they are there to stop two clients from booking the same record.

Consider the following scenario:
  • Client A requests a list of all records
  • Client B requests a list of all records
  • Client A can see that record 5 is not yet booked
  • Client B can see that record 5 is not yet booked
  • Client A updates record 5 to book it
  • Client B updates record 5 to book it


  • In this case, there was nothing to stop the two clients booking the same record.

    So how are you going to stop this? I am leaving this as an exercise for you - we will eventually get to a solution where locking works for you .

    By the way, could you please remove those ll's from your displayed name to meet the JavaRanch Official Policy On Displayed Names, which requires your displayed name to be a real name. You can change it here.

    Thanks and regards, Andrew
     
    reply
      Bookmark Topic Watch Topic
    • New Topic