Jini : single server with multiple clients

Posted by user200340 on Stack Overflow See other posts from Stack Overflow or by user200340
Published on 2010-04-02T00:18:31Z Indexed on 2010/04/02 0:23 UTC
Read the original article Hit count: 568

Hi all,

I have a question about how to make multiple clients can access a single file located on server side and keep the file consistent. I have a simple PhoneBook server-client Jini program running at the moment, and server only provides some getter functions to clients, such as getName(String number), getNumber(String name) from a PhoneBook class(serializable), phonebook data are stored in a text file (phonebook.txt) at the moment. I have tried to implement some functions allowing to write a new records into the phonebook.txt file. If the writing record (name) is existing, an integer number will be added into the writing record. for example the existing phonebook.txt is

....

John 01-01010101

....

if the writing record is "John 01-12345678",then "John_1 01-12345678" will be writen into phonebook.txt

However, if i start with two clients A and B (on the same machine using localhost), and A tries to write "John 01-11111111", B tries to write "John 01-22222222". The early record will be overwritten later record.

So, there must be something i did complete wrong. My client and server code are just like Jini HelloWorld example.

My server side code is .

  1. LookupDiscovery with parameter new String[]{""};
  2. DiscoveryListener for LookupDiscovery
  3. registrations are saved into a HashTable
  4. for every discovered lookup service, i use registrar to register the ServiceItem, ServiceItem contains a null attributeSets, a null serviceId, and a service.

The client code has:

  1. LookupDiscovery with parameter new String[]{""};
  2. DiscoveryListener for LookupDiscovery
  3. a ServiceTemplate with null attributeSets, a null serviceId and a type, the type is the interface class.
  4. for each found ServiceRegistrar, if it can find the looking for ServiceTemplate, the returned Object is cast into the type of the interface class.

I have tried to google more details, and i found JavaSpace could be the one i missed. But i am still not sure about it (i only start Jini for a very short time). So any help would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about jini

Related posts about distributed