|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.sgs.impl.service.data.store.AbstractDataStore
public abstract class AbstractDataStore
A skeletal implementation of DataStore that does logging, checks
arguments, reports object accesses, implements the next key locking scheme
for name bindings, and is a transaction participant. Object and name
accesses are logged to AccessReporters whose source name includes
the name of the concrete class.
This class uses a next key locking scheme when reporting accesses to name bindings. This scheme is a way to insure isolation when different transactions are creating, removing, and iterating over name bindings at the same time. The idea is to use the next key after a given key as a proxy for the existence of the given key even when that key does not exist. That way, iterators know when they lock the next key after a particular key that they will prevent others from changing what that next key ought to be. See the individual methods for getting, setting, removing, and iterating over bindings for details of how each operation fits into this scheme.
Note that this class does not perform next key locking for objects, because the way objects are allocated and used makes that unnecessary. Because there is no method at the application level for obtaining objects by object ID, applications can only officially obtain objects that are stored as the value of a name binding, or that are reachable by navigation from a name binding. In addition, object IDs are never reused. The combination of these two factors means that applications cannot ask to see an object that was created simultaneously by another transaction, which is what next key locking is intended to prevent. This lack of consistency enforcement for objects does mean that services, which can access objects by ID, need to make sure not to ask questions about objects that they don't have other reasons to believe exist. In particular, it means that object iteration may return inconsistent results.
| Field Summary | |
|---|---|
protected LoggerWrapper |
abortLogger
The logger for transaction abort exceptions. |
protected LoggerWrapper |
logger
The main logger for this class. |
protected AccessReporter<String> |
nameAccesses
The reporter to notify of bound name accesses. |
protected AccessReporter<Long> |
objectAccesses
The reporter to notify of object accesses. |
| Constructor Summary | |
|---|---|
protected |
AbstractDataStore(ComponentRegistry systemRegistry,
LoggerWrapper logger,
LoggerWrapper abortLogger)
Creates an instance of this class. |
| Method Summary | |
|---|---|
void |
abort(Transaction txn)
Tells the participant to abort its involvement with the given transaction. |
protected abstract void |
abortInternal(Transaction txn)
Performs the actual operation for abort. |
static void |
checkOid(long oid)
Checks that the object ID argument is not negative. |
void |
commit(Transaction txn)
Tells the participant to commit its state associated with the given transaction. |
protected abstract void |
commitInternal(Transaction txn)
Performs the actual operation for commit. |
long |
createObject(Transaction txn)
Reserves an object ID for a new object. |
protected abstract long |
createObjectInternal(Transaction txn)
Performs the actual operation for createObject. |
long |
getBinding(Transaction txn,
String name)
Obtains the object ID bound to a name. |
protected abstract BindingValue |
getBindingInternal(Transaction txn,
String name)
Performs the actual operation for getBinding. |
int |
getClassId(Transaction txn,
byte[] classInfo)
Returns the class ID to represent classes with the specified class information. |
protected abstract int |
getClassIdInternal(Transaction txn,
byte[] classInfo)
Performs the actual operation for getClassId. |
byte[] |
getClassInfo(Transaction txn,
int classId)
Returns the class information associated with the specified class ID. |
protected abstract byte[] |
getClassInfoInternal(Transaction txn,
int classId)
Performs the actual operation for getClassInfo. |
long |
getLocalNodeId()
Returns the node ID for the local node. |
protected abstract long |
getLocalNodeIdInternal()
Performs the actual operation for getLocalNodeId. |
protected static String |
getNameForAccess(String name)
Returns the name to use for reporting access to a name binding. |
byte[] |
getObject(Transaction txn,
long oid,
boolean forUpdate)
Obtains the data associated with an object ID. |
protected abstract byte[] |
getObjectInternal(Transaction txn,
long oid,
boolean forUpdate)
Performs the actual operation for getObject. |
String |
getTypeName()
Returns the fully qualified type name of the participant. |
protected RuntimeException |
handleException(Transaction txn,
Level level,
RuntimeException e,
String operation)
Performs any operations needed when an exception is going to be thrown, as well as allowing the implementation to replace the exception with a different one. |
void |
markForUpdate(Transaction txn,
long oid)
Notifies the DataStore that an object is going to be
modified. |
protected abstract void |
markForUpdateInternal(Transaction txn,
long oid)
Performs the actual operation for markForUpdate. |
String |
nextBoundName(Transaction txn,
String name)
Returns the next name after the specified name that has a binding, or null if there are no more bound names. |
protected abstract String |
nextBoundNameInternal(Transaction txn,
String name)
Performs the actual operation for nextBoundName. |
long |
nextObjectId(Transaction txn,
long oid)
Returns the object ID for the next object after the object with the specified ID, or -1 if there are no more objects. |
protected abstract long |
nextObjectIdInternal(Transaction txn,
long oid)
Performs the actual operation for nextObjectId. |
boolean |
prepare(Transaction txn)
Tells the participant to prepare for commiting its state associated with the given transaction. |
void |
prepareAndCommit(Transaction txn)
Tells the participant to both prepare and commit its state associated with the given transaction. |
protected abstract void |
prepareAndCommitInternal(Transaction txn)
Performs the actual operation for prepareAndCommit. |
protected abstract boolean |
prepareInternal(Transaction txn)
Performs the actual operation for prepare. |
void |
ready()
Notifies the data store that services associated with the application have been successfully created. |
void |
removeBinding(Transaction txn,
String name)
Removes the binding for a name. |
protected abstract BindingValue |
removeBindingInternal(Transaction txn,
String name)
Performs the actual operation for removeBinding. |
void |
removeObject(Transaction txn,
long oid)
Removes the object with the specified object ID. |
protected abstract void |
removeObjectInternal(Transaction txn,
long oid)
Performs the actual operation for removeObject. |
protected void |
reportNameAccess(Transaction txn,
String name,
AccessReporter.AccessType type)
Reports a name access. |
protected void |
reportObjectAccess(Transaction txn,
long oid,
AccessReporter.AccessType type)
Reports an object access. |
void |
setBinding(Transaction txn,
String name,
long oid)
Binds an object ID to a name. |
void |
setBindingDescription(Transaction txn,
String name,
Object description)
Associates a description with a bound name, for use in describing name accesses. |
protected abstract BindingValue |
setBindingInternal(Transaction txn,
String name,
long oid)
Performs the actual operation for setBinding. |
void |
setObject(Transaction txn,
long oid,
byte[] data)
Specifies data to associate with an object ID. |
void |
setObjectDescription(Transaction txn,
long oid,
Object description)
Associates a description with an object ID, for use in describing object accesses. |
protected abstract void |
setObjectInternal(Transaction txn,
long oid,
byte[] data)
Performs the actual operation for setObject. |
void |
setObjects(Transaction txn,
long[] oids,
byte[][] dataArray)
Specifies data to associate with a series of object IDs. |
protected abstract void |
setObjectsInternal(Transaction txn,
long[] oids,
byte[][] dataArray)
Performs the actual operation for setObjects. |
void |
shutdown()
Shuts down this data store. |
protected abstract void |
shutdownInternal()
Performs the actual operation for shutdown. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final LoggerWrapper logger
protected final LoggerWrapper abortLogger
protected final AccessReporter<Long> objectAccesses
protected final AccessReporter<String> nameAccesses
| Constructor Detail |
|---|
protected AbstractDataStore(ComponentRegistry systemRegistry,
LoggerWrapper logger,
LoggerWrapper abortLogger)
systemRegistry - the registry of available system componentslogger - the main logger for this classabortLogger - the logger for transaction abort exceptions| Method Detail |
|---|
public void ready()
throws Exception
This implementation does nothing.
ready in interface DataStoreException - if an error occurspublic long getLocalNodeId()
This implementation does logging and calls getLocalNodeIdInternal() to perform the actual operation.
getLocalNodeId in interface DataStoreprotected abstract long getLocalNodeIdInternal()
getLocalNodeId.
public long createObject(Transaction txn)
setObject or setObjects is
called. Aborting a transaction is also not required to unassign the ID
so long as other operations treat it as a non-existent object.
This implementation does logging and calls createObjectInternal to perform the actual operation.
createObject in interface DataStoretxn - the transaction under which the operation should take place
protected abstract long createObjectInternal(Transaction txn)
createObject.
txn - the transaction under which the operation should take place
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
TransactionNotActiveException - if the transaction is not active
IllegalStateException - if the operation failed because of a
problem with the current transaction
public void markForUpdate(Transaction txn,
long oid)
DataStore that an object is going to be
modified. The implementation can use this information to obtain an
exclusive lock on the object in order to avoid contention when the
object is modified. This method does nothing if the object does not
exist.
This implementation does logging, checks that oid is valid,
reports object accesses, and calls markForUpdateInternal to perform the actual operation.
markForUpdate in interface DataStoretxn - the transaction under which the operation should take placeoid - the object ID
protected abstract void markForUpdateInternal(Transaction txn,
long oid)
markForUpdate.
txn - the transaction under which the operation should take placeoid - the object ID
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
TransactionNotActiveException - if the transaction is not active
IllegalStateException - if the operation failed because of a
problem with the current transaction
public byte[] getObject(Transaction txn,
long oid,
boolean forUpdate)
forUpdate parameter is true, the caller is
stating its intention to modify the object. The implementation can use
that information to obtain an exclusive lock on the object in order
avoid contention when the object is modified.
This implementation does logging, checks that oid is valid,
reports object accesses, and calls getObjectInternal to perform the actual operation.
getObject in interface DataStoretxn - the transaction under which the operation should take placeoid - the object IDforUpdate - whether the caller intends to modify the object
protected abstract byte[] getObjectInternal(Transaction txn,
long oid,
boolean forUpdate)
getObject.
txn - the transaction under which the operation should take placeoid - the object IDforUpdate - whether the caller intends to modify the object
ObjectNotFoundException - if the object is not found
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
TransactionNotActiveException - if the transaction is not active
IllegalStateException - if the operation failed because of a
problem with the current transaction
public void setObject(Transaction txn,
long oid,
byte[] data)
This implementation does logging, checks that oid is valid and
data is not null, reports object accesses, and calls
setObjectInternal to perform the actual
operation.
setObject in interface DataStoretxn - the transaction under which the operation should take placeoid - the object IDdata - the data
protected abstract void setObjectInternal(Transaction txn,
long oid,
byte[] data)
setObject.
txn - the transaction under which the operation should take placeoid - the object IDdata - the data
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
TransactionNotActiveException - if the transaction is not active
IllegalStateException - if the operation failed because of a
problem with the current transaction
public void setObjects(Transaction txn,
long[] oids,
byte[][] dataArray)
This implementation does logging, checks that oids is not null and its elements are valid, that dataArray and its
elements are not null, and that oids and dataArray have the same length, reports object accesses, and calls
setObjectsInternal to perform the actual
operation.
setObjects in interface DataStoretxn - the transaction under which the operation should take placeoids - the object IDsdataArray - the associated data values
protected abstract void setObjectsInternal(Transaction txn,
long[] oids,
byte[][] dataArray)
setObjects.
txn - the transaction under which the operation should take placeoids - the object IDsdataArray - the associated data values
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
TransactionNotActiveException - if the transaction is not active
IllegalStateException - if the operation failed because of a
problem with the current transaction
public void removeObject(Transaction txn,
long oid)
ObjectNotFoundException, although this behavior is
not guaranteed. The implementation is not required to check that the
object is an externally visible object rather than one used internally
by the implementation.
This implementation does logging, checks that oid is valid and
data is not null, reports object accesses, and calls
removeObjectInternal to perform the actual
operation.
removeObject in interface DataStoretxn - the transaction under which the operation should take placeoid - the object ID
protected abstract void removeObjectInternal(Transaction txn,
long oid)
removeObject.
txn - the transaction under which the operation should take placeoid - the object ID
ObjectNotFoundException - if the object is not found
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
TransactionNotActiveException - if the transaction is not active
IllegalStateException - if the operation failed because of a
problem with the current transaction
public long getBinding(Transaction txn,
String name)
This implementation does logging, checks that name is not null, reports name accesses, and calls getBindingInternal to perform the actual operation.
getBinding in interface DataStoretxn - the transaction under which the operation should take placename - the name
protected abstract BindingValue getBindingInternal(Transaction txn,
String name)
getBinding. If
the name is bound, the return value contains the object ID that the name
is bound to and a next name of null. If the name is not bound,
the return value contains an object ID of -1 and the next name
found, which may be null.
txn - the transaction under which the operation should take placename - the name
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
TransactionNotActiveException - if the transaction is not active
IllegalStateException - if the operation failed because of a
problem with the current transaction
public void setBinding(Transaction txn,
String name,
long oid)
This implementation does logging, checks that name is not null and that oid is valid, reports name accesses, and calls
setBindingInternal to perform the actual
operation.
setBinding in interface DataStoretxn - the transaction under which the operation should take placename - the nameoid - the object ID
protected abstract BindingValue setBindingInternal(Transaction txn,
String name,
long oid)
setBinding. If
the name is bound, the return value contains an arbitrary non-negative
object ID and a next name of null. If the name is not bound,
the return value contains an object ID of -1 and the next name
found, which may be null.
txn - the transaction under which the operation should take placename - the nameoid - the object ID
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
TransactionNotActiveException - if the transaction is not active
IllegalStateException - if the operation failed because of a
problem with the current transaction
public void removeBinding(Transaction txn,
String name)
This implementation does logging, checks that name is not null, reports name accesses, and calls removeBindingInternal to perform the actual operation.
removeBinding in interface DataStoretxn - the transaction under which the operation should take placename - the name
protected abstract BindingValue removeBindingInternal(Transaction txn,
String name)
removeBinding.
If the name is bound, the return value contains an arbitrary
non-negative object ID, otherwise it contains -1. In all cases,
the return value contains the next name found, which may be null.
txn - the transaction under which the operation should take placename - the name
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
TransactionNotActiveException - if the transaction is not active
IllegalStateException - if the operation failed because of a
problem with the current transaction
public String nextBoundName(Transaction txn,
String name)
null if there are no more bound names. If
name is null, then the search starts at the
beginning.
This implementation does logging, reports name accesses, and calls
nextBoundNameInternal to perform the
actual operation.
nextBoundName in interface DataStoretxn - the transaction under which the operation should take placename - the name to search after, or null to start
at the beginning
name, or
null if there are no more bound names
protected abstract String nextBoundNameInternal(Transaction txn,
String name)
nextBoundName.
txn - the transaction under which the operation should take placename - the name to search after, or null to start
at the beginning
name, or
null if there are no more bound names
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
TransactionNotActiveException - if the transaction is not active
IllegalStateException - if the operation failed because of a
problem with the current transactionpublic void shutdown()
This implementation does logging and calls shutdownInternal to perform the actual operation.
shutdown in interface DataStoreprotected abstract void shutdownInternal()
shutdown.
public int getClassId(Transaction txn,
byte[] classInfo)
0. The
class information is the serialized form of the ObjectStreamClass instance that serialization uses to represent the
class.
This implementation does logging, checks that classInfo is not
null, and calls getClassIdInternal
to perform the actual operation.
getClassId in interface DataStoretxn - the transaction under which the operation should take placeclassInfo - the class information
protected abstract int getClassIdInternal(Transaction txn,
byte[] classInfo)
getClassId.
txn - the transaction under which the operation should take placeclassInfo - the class information
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
TransactionNotActiveException - if the transaction is not active
IllegalStateException - if the operation failed because of a
problem with the current transaction
public byte[] getClassInfo(Transaction txn,
int classId)
throws ClassInfoNotFoundException
ObjectStreamClass instance that serialization uses to represent the
class.
This implementation does logging, checks that classId is valid,
and calls getClassInfoInternal to perform
the actual operation.
getClassInfo in interface DataStoretxn - the transaction under which the operation should take placeclassId - the class ID
ClassInfoNotFoundException - if the ID is not found
protected abstract byte[] getClassInfoInternal(Transaction txn,
int classId)
throws ClassInfoNotFoundException
getClassInfo.
txn - the transaction under which the operation should take placeclassId - the class ID
ClassInfoNotFoundException - if the ID is not found
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
IllegalStateException - if the operation failed because of a
problem with the transaction
public long nextObjectId(Transaction txn,
long oid)
-1 if there are no more objects. If objectId is -1, then returns the ID of the first object. The
IDs returned by this method will not include ones for objects that have
already been removed, and may not include identifiers for objects
created after an iteration has begun. It is not an error for the object
associated with the specified identifier to have already been
removed. Applications should not assume that objects associated with the IDs returned by this method, but which cannot be reached by traversing object field references starting with an object associated with a name binding, will continue to be retained by the data store.
This implementation does logging, checks that oid is valid,
reports object accesses, and calls nextObjectIdInternal to perform the actual operation.
nextObjectId in interface DataStoretxn - the transaction under which the operation should take placeoid - the identifier of the object to search after, or
-1 to request the first object
oid, or -1 if there are no more
objects
protected abstract long nextObjectIdInternal(Transaction txn,
long oid)
nextObjectId.
txn - the transaction under which the operation should take placeoid - the identifier of the object to search after, or
-1 to request the first object
oid, or -1 if there are no more
objects
TransactionAbortedException - if the transaction was aborted due
to a lock conflict or timeout
IllegalStateException - if the operation failed because of a
problem with the current transaction
public void setObjectDescription(Transaction txn,
long oid,
Object description)
description should provide a meaningful toString method.
setObjectDescription in interface DataStoretxn - the transaction under which the operation should take placeoid - the object IDdescription - the descriptionAccessReporter.setObjectDescription
public void setBindingDescription(Transaction txn,
String name,
Object description)
description should provide a meaningful toString method.
setBindingDescription in interface DataStoretxn - the transaction under which the operation should take placename - the namedescription - the descriptionAccessReporter.setObjectDescriptionpublic boolean prepare(Transaction txn)
boolean
flag stating whether the prepared state is read-only, meaning that no
external state is modified by this participant. If this method
returns true, then neither commit nor abort
will be called.
If this method throws an exception, then the preparation failed, and the transaction will be aborted. If this method completes successfully, then the participant is required to be able to commit the transaction without failure.
This implementation does logging and calls prepareInternal to perform the actual operation.
prepare in interface TransactionParticipanttxn - the Transaction object
protected abstract boolean prepareInternal(Transaction txn)
prepare.
txn - the transaction
true if this participant is read-only, otherwise false
IllegalStateException - if this participant has already been
prepared, committed, or aborted, or if this participant is not
participating in the given transactionpublic void commit(Transaction txn)
This implementation does logging and calls commitInternal to perform the actual operation.
commit in interface TransactionParticipanttxn - the Transaction objectprotected abstract void commitInternal(Transaction txn)
commit.
txn - the transaction
IllegalStateException - if this participant was not previously
prepared, or if this participant has already committed or
aborted, or if this participant is not participating in the
given transactionpublic void prepareAndCommit(Transaction txn)
This implementation does logging and calls prepareAndCommitInternal to perform the
actual operation.
prepareAndCommit in interface TransactionParticipanttxn - the Transaction objectprotected abstract void prepareAndCommitInternal(Transaction txn)
prepareAndCommit.
txn - the transaction
IllegalStateException - if this participant has already been
prepared, committed, or aborted, or if this participant is not
participating in the given transactionpublic void abort(Transaction txn)
This implementation does logging and calls abortInternal to perform the actual operation.
abort in interface TransactionParticipanttxn - the Transaction objectprotected abstract void abortInternal(Transaction txn)
abort.
txn - the transaction
IllegalStateException - if this participant has already been
aborted or committed, or if this participant is not
participating in the given transactionpublic String getTypeName()
Service, this
will typically be the Service's type name.
getTypeName in interface TransactionParticipant
protected RuntimeException handleException(Transaction txn,
Level level,
RuntimeException e,
String operation)
This implementation does logging, and aborts the transaction if it is
not null and the exception is a TransactionAbortedException.
txn - the transaction or nulllevel - the logging levele - the exceptionoperation - a description of the operation being performed
protected void reportObjectAccess(Transaction txn,
long oid,
AccessReporter.AccessType type)
txn - the transactionoid - the object IDtype - the type of access
IllegalArgumentException - if oid is negative
protected void reportNameAccess(Transaction txn,
String name,
AccessReporter.AccessType type)
txn - the transactionname - the nametype - the type of accessprotected static String getNameForAccess(String name)
null to represent a name beyond the
last known name. Add the prefix "z" to any name whose first character
is "z". Note that this scheme does not preserve order, but access
reporting does not require that.
name - the name or null
public static void checkOid(long oid)
oid - the object ID
IllegalArgumentException - if oid is negative
|
RedDwarf, Version 0.10.1 2010-03-14 10:56:12 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||