com.sage.accpac.sm
Class GUIDMap

java.lang.Object
  extended by com.sage.accpac.sm.GUIDMap
All Implemented Interfaces:
java.lang.Runnable

@ThreadSafe
public final class GUIDMap
extends java.lang.Object
implements java.lang.Runnable

A map between object references and GUIDS to support stateful Internet operation.
An object of this class holds a map between object references and GUIDS for those object references. This is to support stateful operation in Internet operation. Typically a class will use a single static GUIDMap for its objects. However I am in the process of changing this to the GUIDMap class holding the singleton.
When a Reference is registered a corresponding textual GUID is returned, which can be passed around the Internet for example as a cookie or using URL rewriting. That textual GUID can later be converted back to a Java reference to the object. Unlike typical Bean-based concepts this technique assumes that the Java object is to remain in memory; there is no desire to serialise the object itself nor persist it in a database etc. since typically the object is large and heavily linked into other objects.
The GUIDs used are reasonably random, based on Marc A. Mnich's RandomGUID. This reduces the risks of spoofing and other attacks.
The caller provides a Java reference to an Object and requests a GUID for it; see getGUID(java.lang.Object).
At a later time a caller provides the GUID and requests the original object; see getOfGUID(java.lang.String).
From time to time the map will scan itself and will discard any references that have not been recently requested. This is automatic. To support different access frequencies getGUID(java.lang.Object) can be given a non-default timeout.
The caller may explicitly remove an entry from the map using removeGUID(java.lang.String).

Thread safety
Thread-safe

Method Summary
 java.lang.String getGUID(java.lang.Object o)
          Register the object and return a corresponding GUID.
static GUIDMap getInstance()
          Get a reference to the singleton map.
 java.lang.Object getOfGUID(java.lang.String g)
          Get back the object reference of the given GUID.
 void removeGUID(java.lang.String g)
          Remove the given GUID from the map.
 void run()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

run

public final void run()
Specified by:
run in interface java.lang.Runnable

getGUID

public java.lang.String getGUID(java.lang.Object o)
Register the object and return a corresponding GUID. The given object is registered and a GUID is returned. If the object has been previously registered the behaviour is undefined. The returned GUID (i.e. any string containing the same text) can be passed to getOfGUID(java.lang.String) at a later time to get back the same reference.

Parameters:
o - The reference to the object to be remembered.
Returns:
A string containing the GUID that may be passed to getOfGUID(java.lang.String).

getInstance

public static GUIDMap getInstance()
Get a reference to the singleton map.


getOfGUID

public java.lang.Object getOfGUID(java.lang.String g)
Get back the object reference of the given GUID. This method returns the object reference corresponding to the GUID previously returned by getGUID(java.lang.Object).

Parameters:
g - The guid returned previously
Returns:
The reference to the object, as previously provided to getGUID(java.lang.Object), or a null reference if the guid does not refer to an object. This may be because the GUID was not as returned, or because the object has been unregistered due to it not being accessed recently, or for various other reasons.

removeGUID

public void removeGUID(java.lang.String g)
Remove the given GUID from the map.

Parameters:
g - The guid returned previously


Copyright © 2011 Sage Software, Inc. All rights reserved.