• 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

Implementing Lock/Unlock using Event delegator

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have read the book "java2Certification". The Author of this book suggested use the Event Delegator or the Massage subscription to implement the Lock/Unlock on the server. Is this appraoch is samilar like Michael mentioned the ServerService to do the client registery?
 
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 Jeff,
It can be implemented that way. That puts more work on the server, which is not necessarily a bad thing since that would allow clients to go about their other business while waiting for a lock. I took care of it on the client, creating a new thread for each booking operation (which is the only way that lock and unlock were ever called in my design). Either way when the the lock is acquired (or in my case when the whole booking operation completed) the caller should be notified, either thru a Remote interface if implemented on the server or by using the Observer pattern on the client.
Hope this helps,
Michael Morris
 
Jeff Shen
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael
I have another question regarding the Sercer site ConnectionFactory. I am using RMI. Should the ConnectionFactory just return a reference of the RemoteData or create a new thread for each client.
Regards,
Jeff.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Jeff"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
here.
Thanks! and welcome to the JavaRanch!
Mark
 
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 Jeff,
It should just return a remote connection object. RMI will take care of threading for any RMI (Remote) object. You may (and probably will) have several threads running on your server but those will have nothing to do with RMI itself.
Hope this helps,
Michael Morris
 
Jeff Shen
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael
A question about close() the local database. Since the Data class implements the DataInterface and I prefer do not have the close() method in the DataInterface then how can I close the local database.
Regards,
Junfeng
 
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 Jeff,
Well you can just ungracefully exit. You might want to set whatever object(s) hold(s) a reference to Data to null, which should cause the finalize method in Data to close the connection to the RandomAccessFile, assuming that the gc collects it before exit. Of course if you can set an object to null that holds a reference to Data you could just as easily call data.close() in that object's finalize method.
Hope this helps,
Michael Morris
[ September 04, 2002: Message edited by: Michael Morris ]
 
Jeff Shen
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Michael,
I still have something unclear.
1)What is the advantage to use the LockManager instead Lock/Unlock method in the RemoteData object directly.
2)If I use the the LockManager should my "bookFlight" method from Client directly instantiaed the LockManager and use the lock/unlock method or should the "bookFlight" method call the lock/unlock of the RemoteData and then let lock/unlock method call the LockManager.
Regards,
Jeff
 
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 Jeff,


1)What is the advantage to use the LockManager instead Lock/Unlock method in the RemoteData object directly.


Using a lock manager is a more object oriented approch to locking. You delegate record locking to it which makes more sense than letting Data take care of it, at least from an OO point of view. You don't even need to do anything in Data's lock and unlock methods if you use a lock manager, you can just leave them empty.


2)If I use the the LockManager should my "bookFlight" method from Client directly instantiaed the LockManager and use the lock/unlock method or should the "bookFlight" method call the lock/unlock of the RemoteData and then let lock/unlock method call the LockManager.


Definitely the latter. That way the client is oblivious to the fact that there is even a lock manager involved. As far as it know, it's just calling lock and unlock on Data's public interface. Besides, if you instanitate LockManager on the client, then all clients would have their own different lock manager. How would client A's lock manager know what records were locked in client B's?
Hope this helps,
Michael Morris
 
Jeff Shen
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again all the ansers help me so much.
I can understand and implement the client site ConnectionFactory, however I am not sure what is the server site ConnctionFactory (I am using RMI) and how to implement it.
Regards,
Jeff
 
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 Jeff,


I can understand and implement the client site ConnectionFactory, however I am not sure what is the server site ConnctionFactory (I am using RMI) and how to implement it.


I really don't know why you need a ConnectionFactory on the client since all you need is a single object for local access. On the server the ConnctionFactory creates new remote objects for all requesting clients. It will usually have a method named getConnection(). The ConnctionFactory is bound to the RMI registry so that clients can find it and then get their remote connection. Of course the getConnection() method will return a stub to a remote DataAccess (or whatever you call your public Data interface) implementation.
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