Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

why is it necessary for unLock() to check clientID?

 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Raffe Paffe:

Max, could you provide the example you were talking about?
Puh! This subject got me nervous! :-)



Sure. A word of explanation. There are three important classes here: the rest are interfaces, and self explanatory.
  • A FactorypImpl that creates a generic factory, used by all clients, to get a remoteData object.
  • RemoteDataIampl that provides the functionality of a remote object. It offers two methods, doStuff and undoStuff, that might look familiar.
  • ClientDriver that creates 20 separate threads. Each thread creates gets a remoteData object by using the Factory. The then doStuff, wait a bit, then undoStuff.
  • to run the example, type in the following


  • One of the important things to notice here is that this design, the RemoteDataImpl classes uses the client itself as a key. Thus, you get free releasing of locks if a client dies. If you want more on this, read about weakHashMaps, which are a great little gem.
    FactoryImpl

    RemoteDataImpl

    ClientDriver

    Factory


    HTH
    M, author
    The Sun Certified Java Developer Exam with J2SE 1.4
     
    Ranch Hand
    Posts: 92
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ok, thanks I will have a look. But at first glance your locking is done in your RemoteDataImp.My RemoteDataImp has Data as a member and I must implement locking in Data and Data doesnt know "bindingName". I have done almost as you except that i have modev my locking to a lockmanager class that is a member of RemoteDataImp. What I am trying to understand is how can i do what you do in RemoteDataImp in Data. How can I get "bindingName" into data? Or maybe I shouldnt? That is the thing i dont get. Are you confused, or am I ? :-)
     
    Ranch Hand
    Posts: 55
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Max,
    Can you tell me what is different between
    1.Registry.rebind(StringName, RemoteObj)
    2.Naming.rebind(StringName, RemoteObj).
    I am testing my rmi and locking part. I checked some past posts, people had the same problem as I had: getting ConnectionException, port already in use,connection refused. So I have to restart my computer, because I think I started several servers at same time and all of them using port 1099. Anyway, changing Naming to Registry is a solution, but I just don't know why. Maybe the cause is different, please clarify.
    BTW, Max and Mark, if you guys think this question need to be in a new thread, I will do so.
    Thanks
    Kevin
     
    Max Habibi
    town drunk
    ( and author)
    Posts: 4118
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Kevin,
    I'll follow up on your question later today: I'm swamped right now. But yes, it might be a good idea to start a new thread, so people can take advantage of the question.
    Thanks,
    M
     
    When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
    reply
      Bookmark Topic Watch Topic
    • New Topic