@Managed public 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<?> klass)
Returns the number of instances of the given class.
|
static int |
cardinality(java.lang.Class<?> klass,
QueryScope queryScope)
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 <T> java.lang.Iterable<T> |
extent(java.lang.Class<T> klass,
QueryScope queryScope,
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 byte[] |
getObjectReference(java.lang.Object o)
Return the object reference as a byte array.
|
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.
|
static boolean |
isPartitioned(java.lang.Class<?> klass)
Determines if the given class is partitioned.
|
static java.lang.String |
objectToReference(java.lang.Object operand)
Get a string version of an object reference
|
static java.lang.Object |
referenceToObject(java.lang.String refStr)
Convert a stringified object reference to an Object
|
static void |
setDistributedQuery(com.kabira.platform.DistributedQuery distributedQuery)
Internal method - do not use.
|
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 ); ... }
T
- Managed class.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
,
ManagedClassError
public 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 ); ... }
T
- Managed class.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.Managed
public static <T> java.lang.Iterable<T> extent(java.lang.Class<T> klass, QueryScope queryScope, LockMode objectLock) throws ManagedClassError, java.lang.IllegalArgumentException, ResourceUnavailableException
The klass
parameter must be a Managed class,
and is used to determine the extent to return.
The queryScope
parameter determines the scope
of the search for object instances.
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.
T
- Managed class.klass
- extent class - instances of this type,
and any subtypes that extend from this type, will be returned
in the extent.queryScope
- scope of extent lookup.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.java.lang.IllegalArgumentException
- The queryScope failed audit due to a bad node list.ResourceUnavailableException
- Access to distributed services failed.Managed
,
QueryScope
public static int hashCode(java.lang.Object o) throws ManagedClassError
o
- Managed object to hashManagedClassError
public static boolean equals(java.lang.Object o1, java.lang.Object o2) throws ManagedClassError
o1
- Managed objecto2
- Managed objectManagedClassError
- if o1 or o2 is not Managed.public static boolean isManaged(java.lang.Object o)
o
- Object to check.public static boolean isManagedClass(java.lang.Class<?> klass)
klass
- Class to check.public static boolean isPartitioned(java.lang.Class<?> klass)
klass
- Class to check.ManagedClassError
- if klass not Managed.public static byte[] getObjectReference(java.lang.Object o)
o
- Object to get reference from.public static void delete(java.lang.Object operand) throws ManagedClassError
operand
- Object to delete.ManagedClassError
- if operand is not Managed.public static java.lang.String objectToReference(java.lang.Object operand)
If the object is invalid, an empty string is returned to the caller.
operand
- Object to get reference forManagedClassError
- if operand is not Managed.public static java.lang.Object referenceToObject(java.lang.String refStr)
If the string reference is invalid an empty object is returned to the caller.
refStr
- Object reference stringpublic static int cardinality(java.lang.Class<?> klass) throws ManagedClassError
klass
- extent class - instances of this type,
and any subtypes that extend from this type, will be counted.ManagedClassError
- Thrown if klass
is not marked Managed.public static int cardinality(java.lang.Class<?> klass, QueryScope queryScope) throws ManagedClassError, java.lang.IllegalArgumentException, ResourceUnavailableException
The queryScope
parameter determines the scope
of the search for object instances.
klass
- extent class - instances of this type,
and any subtypes that extend from this type, will be counted.queryScope
- scope of cardinality lookup.ManagedClassError
- Thrown if klass
is not marked Managed.java.lang.IllegalArgumentException
- The queryScope failed audit due to a bad node list.ResourceUnavailableException
- Access to distributed services failed.QueryScope
public static boolean isEmpty(java.lang.Object operand) throws ManagedClassError
operand
- Object to check.ManagedClassError
- if the operand object is not of a Managed
class.public static void setDistributedQuery(com.kabira.platform.DistributedQuery distributedQuery)
distributedQuery
- Distributed query