|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.sgs.impl.service.data.DataServiceImpl
public final class DataServiceImpl
Provides an implementation of DataService based on DataStoreImpl.
The constructor requires the
com.sun.sgs.app.name property, and supports both these
public configuration
properties and the following additional properties:
"com.sun.sgs.impl.service.data.DataServiceImpl.data.store.class"
com.sun.sgs.impl.service.data.store.net.DataStoreClient
unless the com.sun.sgs.node.type property is singleNode,
which defaults to
com.sun.sgs.impl.service.data.store.DataStoreImpl
DataStore. The class should be public, not abstract, and should
provide a public constructor with Properties, ComponentRegistry, and TransactionProxy parameters.
"com.sun.sgs.impl.service.data.DataServiceImpl.detect.modifications"
true
true,
then applications need to call DataManager.markForUpdate or ManagedReference.getForUpdate for any modified objects to make sure
that the modifications are recorded by the
DataService.
"com.sun.sgs.impl.service.data.DataServiceImpl.debug.check.interval"
Integer.MAX_VALUE
DataService
operations to skip between checks of the consistency of the managed
references table. Note that the number of operations is measured
separately for each transaction. This property is intended for use in
debugging.
"com.sun.sgs.impl.service.data.DataServiceImpl.optimistic.write.locks"
false
false, which is the default, the service
acquires write locks as soon as it knows that an object is being
modified. If true, the service delays obtaining write
locks until commit time, which may improve performance in some cases,
typically when there is low contention. Note that setting this flag to
true does not delay write locks when removing objects.
"com.sun.sgs.impl.service.data.DataServiceImpl.track.stale.objects"
false
true, the DataService keeps
track of persistent or removed objects from completed transactions and
throws TransactionNotActiveException if the application refers
to those objects from another transaction.
The constructor also passes the properties to the DataStoreImpl
constructor, which supports additional properties.
This class uses the Logger named
com.sun.sgs.impl.service.data.DataServiceImpl to log
information at the following logging levels:
SEVERE - Initialization failures
CONFIG - Constructor properties, data service
headers
FINE - Task scheduling operations, managed reference
table checks
FINER - Transaction operations
FINEST - Name, object, and reference operations
It also uses an additional Logger named com.sun.sgs.impl.service.data.DataServiceImpl.detect.modifications to log
information about managed objects that are found to be modified but were not
marked for update. Note that this logging output will only be performed if
the com.sun.sgs.impl.service.data.DataServiceImpl.detect.modifications property
is true.
FINEST - Modified object was not marked for update
In addition, operations that throw a TransactionAbortedException
will log the failure to the Logger named com.sun.sgs.impl.service.data.DataServiceImpl.abort, to make it easier to
debug concurrency conflicts by just logging aborts.
| Nested Class Summary | |
|---|---|
(package private) static class |
DataServiceImpl.State
The possible states of this instance. |
| Field Summary | |
|---|---|
static String |
DATA_STORE_CLASS_PROPERTY
The property that specifies the name of the class that implements DataStore. |
static String |
DEBUG_CHECK_INTERVAL_PROPERTY
The property that specifies the number of operations to skip between checks of the consistency of the managed references table. |
static String |
DETECT_MODIFICATIONS_PROPERTY
The property that specifies whether to automatically detect modifications to objects. |
(package private) static LoggerWrapper |
logger
The logger for this class. |
static String |
OPTIMISTIC_WRITE_LOCKS
The property that specifies to use optimistic write locking. |
(package private) boolean |
optimisticWriteLocks
Whether to delay obtaining write locks. |
static String |
TRACK_STALE_OBJECTS_PROPERTY
The property that specifies whether to track stale objects. |
| Constructor Summary | |
|---|---|
DataServiceImpl(Properties properties,
ComponentRegistry systemRegistry,
TransactionProxy txnProxy)
Creates an instance of this class configured with the specified properties and services. |
|
| Method Summary | ||
|---|---|---|
(package private) static void |
checkContext(Context context)
Checks that the specified context is currently active. |
|
(package private) void |
checkState()
Checks that the current state is RUNNING or SHUTTING_DOWN. |
|
|
createReference(T object)
Creates a managed reference to an object, storing the object in the data manager if it is transient. |
|
ManagedReference<?> |
createReferenceForId(BigInteger id)
Creates a managed reference for the object with the specified identifier, which should have been obtained from a call to ManagedReference.getId. |
|
ManagedObject |
getBinding(String name)
Obtains the object bound to a name. |
|
ManagedObject |
getBindingForUpdate(String name)
Obtains the object bound to a name, and notifies the system that the object is going to be modified. |
|
(package private) static Context |
getContextNoJoin()
Obtains the currently active context, throwing TransactionNotActiveException if none is active. |
|
(package private) static LoggerWrapper |
getExceptionLogger(RuntimeException exception)
Returns the logger that should be used to log the specified exception. |
|
long |
getLocalNodeId()
Returns the node ID for the local node. |
|
String |
getName()
Returns the name used to identify this service. |
|
BigInteger |
getObjectId(Object object)
Returns a unique identifier for the object, storing the object in the data manager if it is transient. |
|
ManagedObject |
getServiceBinding(String name)
Obtains the object associated with the service binding of a name. |
|
ManagedObject |
getServiceBindingForUpdate(String name)
Obtains the object associated with the service binding of a name, and notifies the system that the object is going to be modified. |
|
void |
markForUpdate(Object object)
Notifies the system that an object is going to be modified, doing nothing if the object is transient. |
|
String |
nextBoundName(String name)
Returns the next name after the specified name that has a binding, or null if there are no more bound names. |
|
BigInteger |
nextObjectId(BigInteger objectId)
Returns a unique identifier for the next object after the object with the specified identifier, or null if there are no more objects. |
|
String |
nextServiceBoundName(String name)
Returns the next name after the specified name that has a service binding, or null if there are no more bound names. |
|
void |
ready()
Notifies this Service that the application is fully
configured and ready to start running. |
|
void |
removeBinding(String name)
Removes the binding for a name. |
|
void |
removeObject(Object object)
Removes an object from the DataManager, if the object is persistent. |
|
void |
removeServiceBinding(String name)
Removes the service binding for a name. |
|
void |
setBinding(String name,
Object object)
Binds an object to a name, replacing any previous binding, and storing the object in the data manager if it is transient. |
|
void |
setDebugCheckInterval(int debugCheckInterval)
Specifies the number of operations to skip between checks of the consistency of the managed references table. |
|
void |
setDetectModifications(boolean detectModifications)
Specifies whether to automatically detect modifications to objects. |
|
void |
setServiceBinding(String name,
Object object)
Specifies an object for the service binding of a name, replacing any previous binding. |
|
void |
shutdown()
Shuts down this service. |
|
String |
toString()
Returns a string representation of this instance. |
|
(package private) static String |
typeName(Object object)
Returns the type name of the object. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String DEBUG_CHECK_INTERVAL_PROPERTY
public static final String DETECT_MODIFICATIONS_PROPERTY
public static final String DATA_STORE_CLASS_PROPERTY
DataStore.
public static final String OPTIMISTIC_WRITE_LOCKS
public static final String TRACK_STALE_OBJECTS_PROPERTY
static final LoggerWrapper logger
final boolean optimisticWriteLocks
| Constructor Detail |
|---|
public DataServiceImpl(Properties properties,
ComponentRegistry systemRegistry,
TransactionProxy txnProxy)
throws Exception
class
documentation for the list of supported properties.
properties - the properties for configuring this servicesystemRegistry - the registry of available system componentstxnProxy - the transaction proxy
IllegalArgumentException - if the com.sun.sgs.app.name
property is not specified, if the value of the
com.sun.sgs.impl.service.data.DataServiceImpl.debug.check.interval
property is not a valid integer, or if the data store
constructor detects an illegal property value
Exception - if a problem occurs creating the service| Method Detail |
|---|
public String getName()
getName in interface Service
public void ready()
throws Exception
Service that the application is fully
configured and ready to start running. This means that all other Services associated with this application have been successfully
created. If the method throws an exception, then the application will be
shutdown.
ready in interface ServiceException - if an error occurspublic ManagedObject getBinding(String name)
markForUpdate or ManagedReference.getForUpdate before modifying the returned object or
any of the non-managed objects it refers to.
getBinding in interface DataManagername - the name
markForUpdate,
ManagedReference.getForUpdate,
getBindingForUpdatepublic ManagedObject getBindingForUpdate(String name)
getBindingForUpdate in interface DataManagername - the name
public void setBinding(String name,
Object object)
ManagedObject, and both the object and any objects it refers to must
implement Serializable. Note that this method will throw IllegalArgumentException if object does not implement
Serializable, but is not guaranteed to check that all
referred to objects implement Serializable. Any instances
of ManagedObject that object refers to directly, or
indirectly through non-managed objects, need to be referred to through
instances of ManagedReference.
setBinding in interface DataManagername - the nameobject - the objectpublic void removeBinding(String name)
removeObject method.
removeBinding in interface DataManagername - the nameremoveObjectpublic String nextBoundName(String name)
null if there are no more bound names. If
name is null, then the search starts at the
beginning.
The order of the names corresponds to the ordering of the UTF-8 encoding
of the names. To provide flexibility to the implementation, the UTF-8
encoding used can be either standard UTF-8, as defined by the
IETF in RFC 3629, or
modified UTF-8, as used by serialization and defined by the
DataInput interface.
nextBoundName in interface DataManagername - the name to search after, or null to start at
the beginning
name, or
null if there are no more bound namespublic void removeObject(Object object)
DataManager, if the object is persistent. The system will make an effort to
flag subsequent references to the removed object through getBinding or ManagedReference by throwing ObjectNotFoundException, although this behavior is not guaranteed.
If object implements ManagedObjectRemoval, even if it is
transient, then this method first calls the
ManagedObjectRemoval.removingObject method on the object, to notify it
that it is being removed. If the call to removingObject throws
a RuntimeException, then this method will throw that exception
without removing the object. A call to removingObject that
causes removeObject to be called recursively on the same object
will result in an IllegalStateException being thrown.
removeObject in interface DataManagerobject - the objectManagedObjectRemovalpublic void markForUpdate(Object object)
markForUpdate in interface DataManagerobject - the objectManagedReference.getForUpdatepublic <T> ManagedReference<T> createReference(T object)
createReference in interface DataManagerT - the type of the objectobject - the object
public BigInteger getObjectId(Object object)
ManagedReference.getId on a
managed reference associated with the object produced by createReference.
getObjectId in interface DataManagerobject - the object
public long getLocalNodeId()
WatchdogService.getNode to obtain the Node object for the local
node. This method may be invoked any time after this service is initialized, whether or not the calling context is inside or outside of a transaction.
getLocalNodeId in interface DataServicepublic ManagedObject getServiceBinding(String name)
markForUpdate or ManagedReference.getForUpdate before making the modifications.
getServiceBinding in interface DataServicename - the name
getServiceBindingForUpdatepublic ManagedObject getServiceBindingForUpdate(String name)
getServiceBindingForUpdate in interface DataServicename - the name
public void setServiceBinding(String name,
Object object)
ManagedObject, and
both the object and any objects it refers to must implement Serializable. Note that this method will throw IllegalArgumentException if object does not implement
Serializable, but is not guaranteed to check that all
referred to objects implement Serializable. Any instances
of ManagedObject that object refers to directly, or
indirectly through non-managed objects, need to be referred to through
instances of ManagedReference.
setServiceBinding in interface DataServicename - the nameobject - the object associated with the service binding of the
namepublic void removeServiceBinding(String name)
removeObject method.
removeServiceBinding in interface DataServicename - the nameremoveObjectpublic String nextServiceBoundName(String name)
null if there are no more bound names. If
name is null, then the search starts at the
beginning.
The order of the names corresponds to the ordering of the UTF-8 encoding
of the names. To provide flexibility to the implementation, the UTF-8
encoding used can be either standard UTF-8, as defined by the
IETF in RFC 3629, or
modified UTF-8, as used by serialization and defined by the
DataInput interface.
nextServiceBoundName in interface DataServicename - the name to search after, or null to start at
the beginning
name, or null if there are no more
bound namespublic ManagedReference<?> createReferenceForId(BigInteger id)
ManagedReference.getId. Callers should make
sure that the associated object is reachable from an existing name
binding. This method does not check to see whether the associated
object has been removed.
createReferenceForId in interface DataServiceid - the identifier
public BigInteger nextObjectId(BigInteger objectId)
null if there are no more objects.
If objectId is null, then returns the identifier of the
first object. This method will not return identifiers for objects that
have already been removed, and may not include identifiers for newly
created objects. It is not an error for the object associated with
objectId to have already been removed.
The object identifiers accepted and returned by this method are the same
as those returned by the ManagedReference.getId method.
Callers should not assume that objects associated with the identifiers 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 service.
nextObjectId in interface DataServiceobjectId - the identifier of the object to search after, or
null to request the first object
objectId, or null if there are no
more objectspublic String toString()
toString in class Objectpublic void setDebugCheckInterval(int debugCheckInterval)
debugCheckInterval - the number of operations to skip between
checks of the consistency of the managed references tablepublic void setDetectModifications(boolean detectModifications)
detectModifications - whether to detect modificationspublic void shutdown()
This method does not require a transaction, and should not be called from one because this method will typically not succeed if there are outstanding transactions.
When this method returns, it is assumed that the service has been shutdown.
Callers should assume that, in a worst case, this method may block
indefinitely, and so should arrange to take other action (for example,
calling System.exit) if the call fails to complete
successfully in a certain amount of time.
shutdown in interface Servicevoid checkState()
static void checkContext(Context context)
static Context getContextNoJoin()
static String typeName(Object object)
static LoggerWrapper getExceptionLogger(RuntimeException exception)
|
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 | |||||||||