com.j_spaces.core.client
Class ClientUIDHandler

java.lang.Object
  extended by com.j_spaces.core.client.ClientUIDHandler

public class ClientUIDHandler
extends Object

This Class enables the client to create entry UIDs by rendering a free-string , and to extract the free-string from a UID.


Method Summary
static String createUIDFromName(Object name, String className)
           This method is used to create a UID given a name (i.e. any free string) and the entry (full) classname.
static void createUIDFromName(StringBuilder sb, Object name, String className)
           
static String getNameFromUID(String uid)
          This method is used to extract the name-string from a given UID.
static Object getObjectFromUID(String uid)
          This method is used to extract the Object from a given UID.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createUIDFromName

public static String createUIDFromName(Object name,
                                       String className)
 This method is used to create a UID given a name (i.e. any free string) and the entry (full) classname.
 NOTE - it is the caller's responsibility to create a unique UID by supplying a unique name
 See below example:

 

 import net.jini.core.lease.Lease;
 import net.jini.space.JavaSpace;
 import com.j_spaces.core.IJSpace;
 import com.j_spaces.core.LeaseProxy;
 import com.j_spaces.core.client.EntryInfo;
 import com.j_spaces.core.client.SpaceFinder;
 import com.j_spaces.core.client.ClientUIDHandler ;

 public class MyEntry extends com.j_spaces.core.client.MetaDataEntry
 {
        public String myData;

        public MyEntry()
    {
        }

        public MyEntry(String data)
    {
                this.myData = data;
        }

        public String toString()
        {
     return myData;
    }

   public static void main(String[] args)
    {
                try
       {
                        IJSpace space = (IJSpace) SpaceFinder.find(args[0]);
                        space.clean();

                        //      Setting Entry UID
                        MyEntry myentry = new MyEntry("Data");

                        // ClientUIDHandler allows you to generate Valid UID Entry
                        // you must make sure you provide unique name!
                        String uid1 = ClientUIDHandler.createUIDFromName("MyEntryUID" ,MyEntry.class.getName() );

                        EntryInfo ei1 = new EntryInfo(uid1 , 0);
                        myentry.__setEntryInfo(ei1);

                        //      Write entry to space
                        space.write(myentry, null, Lease.FOREVER);
                        System.out.println("Wrote Object with UID: " + myentry.__getEntryInfo().m_UID );

                        //      Reading Entry using its UID
                        MyEntry template = new MyEntry();

                        String uid2 =  ClientUIDHandler.createUIDFromName("MyEntryUID", MyEntry.class.getName() );
                        EntryInfo ei2 = new EntryInfo(uid2 , 0);
                        template.__setEntryInfo(ei2);
                        MyEntry m = (MyEntry) space.read(template, null, JavaSpace.NO_WAIT);
                        System.out.println("Read Object with UID: " + m.__getEntryInfo().m_UID + " Data: " + m.myData);
                } catch (Exception e)
       {
                        e.printStackTrace();
                }
        }
 }

 

Parameters:
name - any free string;

The following characters are not allowed as part of the entry name: ! @ # $ % ^ & * ( ) _ + = - ? > < , . / " : ; ' | \ } { [ ] ^

className - full class-name string
Returns:
UID string

createUIDFromName

public static void createUIDFromName(StringBuilder sb,
                                     Object name,
                                     String className)

getNameFromUID

public static String getNameFromUID(String uid)
This method is used to extract the name-string from a given UID.

Parameters:
uid - A valid uid string
Returns:
The name part of the uid

getObjectFromUID

public static Object getObjectFromUID(String uid)
This method is used to extract the Object from a given UID.

Parameters:
uid - A valid uid string
Returns:
The object that was used to create the UID if avaliable otherwise the name-string see getNameFromUID(String)