@Managed public abstract class ManagedObject extends java.lang.Object
@Managed annotation.
Example:
@Managed
public class Account {
public Account(String userName) {
super();
m_userName = userName;
}
public Account(String userName, Account referrer) {
this(userName);
allocateMailbox();
addToFriendList(referrer);
}
public void addToFriendList(Account friendlyAccount) {
...
}
private void allocateMailbox() {
...
}
private String m_userName;
private Account[] m_friendList;
}
Some example usage of the above type:
//
// create a new account in shared memory:
//
Account newCustomer = new Account("Fred Rogers", referrer);
System.out.println("Added " + newCustomer.toString());
//
// delete all expired accounts from shared memory.
// Note extent access, and use of the delete() method
// to delete the shared memory instance.
//
for (Account acc : ManagedObject.extent(Account.class)) {
if (acc.expireDate < today) {
ManagedObject.delete(acc);
}
}
Managed,
Transaction| Constructor and Description |
|---|
ManagedObject() |
| Modifier and Type | Method and Description |
|---|---|
static int |
cardinality(java.lang.Class<?> operand)
Returns the number of instances of the given class.
|
static void |
delete(java.lang.Object operand)
Deletes a Managed object.
|
static boolean |
equals(java.lang.Object o1,
java.lang.Object o2)
Returns true if both references are proxies to the same
shared memory object.
|
static <T> java.lang.Iterable<T> |
extent(java.lang.Class<T> klass)
Returns all shared memory instances of a Managed type.
|
static <T> java.lang.Iterable<T> |
extent(java.lang.Class<T> klass,
LockMode objectLock)
Returns all shared memory instances of a Managed type,
with an explicit transaction lock taken on each instance
as it is iterated.
|
static int |
hashCode(java.lang.Object o)
Returns a hash code based on the
underlying shared memory object.
|
static boolean |
isEmpty(java.lang.Object operand)
Determines if the backing shared memory object has been deleted.
|
static boolean |
isManaged(java.lang.Object o)
Determines if the given object is an instance of a Managed class.
|
static boolean |
isManagedClass(java.lang.Class<?> klass)
Determines if the given class is Managed.
|
public ManagedObject()
public static <T> java.lang.Iterable<T> extent(java.lang.Class<T> klass) throws ManagedClassError
The klass parameter must be a Managed
class, and is used to determine the extent to return.
A Managed class is either annotated @Managed, or
extends a class that is so annotated.
Consider the following example. It returns all instances of
MyType (including instances of its subtypes)
with no locks held on the objects:
//
// Iterate instances of MyType.class, returning all objects in the extent
//
for (MyType instance : ManagedObject.extent(MyType.class)) {
assert ( Transaction.hasReadLock(instance) == false );
assert ( Transaction.hasWriteLock(instance) == false );
...
}klass - extent class - instances of this type,
and any subtypes that extend from this type, will be returned in
the extent.Iterable that will traverse all instances
located in shared memory.ManagedClassError - Thrown if klass
is not Managed (or exactly ManagedObject).Managed,
ManagedClassErrorpublic static <T> java.lang.Iterable<T> extent(java.lang.Class<T> klass, LockMode objectLock) throws ManagedClassError
The klass parameter must be a Managed class,
and is used to determine the extent to return.
The objectLock parameter is used to specify the
transaction lock to take on objects returned during extent
iteration. The objects are locked as they are returned from the
java.util.Iterator, not when this method
returns.
Consider the following example. It returns all instances of
MyType (including instances of its subtypes)
with a READLOCK held on each instance:
//
// Iterate the ManagedObjectSet taking read locks on the objects
//
for (MyType mt : ManagedObject.extent( MyType.class, LockMode.READLOCK)) {
assert ( Transaction.hasReadLock(mt) == true );
...
}klass - extent class - instances of this type,
and any subtypes that extend from this type, will be returned
in the extent.objectLock - object lock - all object instances
returned during extent iteration will have this transaction lock.Iterable containing references to
all instances located in shared memory.ManagedClassError - Thrown if klass
is not marked Managed, or is exactly ManagedObject.Managedpublic static int hashCode(java.lang.Object o)
public static boolean equals(java.lang.Object o1, java.lang.Object o2) throws ManagedClassError
ManagedClassError - if o1 or o2 is not Managed.public static boolean isManaged(java.lang.Object o)
public static boolean isManagedClass(java.lang.Class<?> klass)
public static void delete(java.lang.Object operand) throws ManagedClassError
ManagedClassError - if operand is not Managed.public static int cardinality(java.lang.Class<?> operand) throws ManagedClassError
ManagedClassError - if klass is not Managed.public static boolean isEmpty(java.lang.Object operand) throws ManagedClassError
ManagedClassError - if the operand object is not of a Managed
class.