br.shob
Interface SharedReference

All Known Implementing Classes:
DefaultSharedReference

public interface SharedReference

This class represents a reference to shared object. References are retrieved from a global space through the Shared Space instance.

  SharedReference ref = shob.get("myObject_global_name");
  if (ref instanceof List) {
      List l = (List) ref;
      readList(l);
  }

SharedReferences should not be shared among different threads for correctness. Synchronization and mutual exclusion should be left to the shared space. In fact, if you use shared references in multi-thread contexts, you should consider using ThreadLocal variables, each one initialized with it's own reference.

When creating shared references to your own-developed classes, you should use the configurator tool included in the SharedObjects package.

Version:
$Revision: 1.8 $
Author:
crolmos, dukejeffrie
Created:
August 30, 2002

Field Summary
static long defaultLeaseTime
          This is the default lease time, set to 20 (twenty) seconds.
 
Method Summary
 void srBeginTrans()
          Initiates a transaction for this object.
 Object srCallMethod(String name, Class[] argTypes, Object[] args)
          This method calls a method from the shared object.
 void srCommit()
          Commits a transaction.
 String srGetGlobalName()
          Acessor for the global name.
 boolean srIsUpdated()
          Checks if the corresponding object is updated (i.e., if his lease is expired)
 void srRollback()
          Rolls back a transaction.
 void srUnshare()
          Unshares this object from the global space.
 void srValidate()
          Validates this object.
 

Field Detail

defaultLeaseTime

public static final long defaultLeaseTime
This is the default lease time, set to 20 (twenty) seconds.

See Also:
Constant Field Values
Method Detail

srBeginTrans

public void srBeginTrans()
                  throws ShobException,
                         AlreadyLockedException
Initiates a transaction for this object.

Throws:
ShobException - If a low-level error occurs
AlreadyLockedException - If the object is already locked by this reference.

srCallMethod

public Object srCallMethod(String name,
                           Class[] argTypes,
                           Object[] args)
                    throws InvocationException,
                           InvocationTargetException,
                           ShobException
This method calls a method from the shared object.
If the lease has expired it validates the object before the call is made.

Parameters:
name - the name of the method.
argTypes - the types of the arguments.
args - the arguments.
Returns:
the value returned by the method
Throws:
InvocationException - if the method does not exist, is not public or the argument is invalid (thrown with real cause chained)
InvocationTargetException - if the underlying method throws an exception.
ShobException - If a low-level error occurs

srCommit

public void srCommit()
              throws ShobException,
                     NotLockedException
Commits a transaction.

Throws:
ShobException - If a low-level error occurs
NotLockedException - if the object is not inside a transaction

srGetGlobalName

public String srGetGlobalName()
Acessor for the global name.

Returns:
the global name of the shared object.

srIsUpdated

public boolean srIsUpdated()
Checks if the corresponding object is updated (i.e., if his lease is expired)

Returns:
true if the local cache is up to date

srRollback

public void srRollback()
                throws ShobException,
                       NotLockedException
Rolls back a transaction.

Throws:
ShobException - If a low-level error occurs
NotLockedException - if the object is not inside a transaction

srUnshare

public void srUnshare()
               throws ShobException
Unshares this object from the global space.

Throws:
ShobException - If a low-level error occurs

srValidate

public void srValidate()
                throws ShobException
Validates this object.

Throws:
ShobException - If a low-level error occurs