com.sun.sgs.impl.service.data.store
Class DataStoreProfileProducer

java.lang.Object
  extended by com.sun.sgs.impl.service.data.store.DataStoreProfileProducer
All Implemented Interfaces:
DataStore, TransactionParticipant

public class DataStoreProfileProducer
extends Object
implements DataStore, TransactionParticipant

Implements a DataStore that reports profiling information about data store operations under the name "com.sun.sgs.impl.service.data.store.DataStore", implementing DataStore operations and transaction participant methods by delegating them to another data store.


Constructor Summary
DataStoreProfileProducer(DataStore dataStore, ProfileCollector collector)
          Creates an instance that delegates all DataStore and TransactionParticipant methods to dataStore.
 
Method Summary
 void abort(Transaction txn)
          Tells the participant to abort its involvement with the given transaction.
 void commit(Transaction txn)
          Tells the participant to commit its state associated with the given transaction.
 long createObject(Transaction txn)
          Reserves an object ID for a new object.
 long getBinding(Transaction txn, String name)
          Obtains the object ID bound to a name.
 int getClassId(Transaction txn, byte[] classInfo)
          Returns the class ID to represent classes with the specified class information.
 byte[] getClassInfo(Transaction txn, int classId)
          Returns the class information associated with the specified class ID.
 DataStore getDataStore()
          Returns the DataStore that this instance delegates to.
 long getLocalNodeId()
          Returns the node ID for the local node.
 byte[] getObject(Transaction txn, long oid, boolean forUpdate)
          Obtains the data associated with an object ID.
 String getTypeName()
          Returns the fully qualified type name of the participant.
 void markForUpdate(Transaction txn, long oid)
          Notifies the DataStore that an object is going to be modified.
 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.
 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.
 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.
 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.
 void removeObject(Transaction txn, long oid)
          Removes the object with the specified object ID.
 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.
 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.
 void setObjects(Transaction txn, long[] oids, byte[][] dataArray)
          Specifies data to associate with a series of object IDs.
 void shutdown()
          Shuts down this data store.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataStoreProfileProducer

public DataStoreProfileProducer(DataStore dataStore,
                                ProfileCollector collector)
Creates an instance that delegates all DataStore and TransactionParticipant methods to dataStore.

Parameters:
dataStore - the object for delegating operations
collector - the object for collecting profile data
Throws:
IllegalArgumentException - if dataStore does not implement TransactionParticipant
Method Detail

ready

public void ready()
           throws Exception
Notifies the data store that services associated with the application have been successfully created. If the method throws an exception, then the application should be shutdown.

Specified by:
ready in interface DataStore
Throws:
Exception - if an error occurs

getLocalNodeId

public long getLocalNodeId()
Returns the node ID for the local node.

Specified by:
getLocalNodeId in interface DataStore
Returns:
the node ID for the local node

createObject

public long createObject(Transaction txn)
Reserves an object ID for a new object. Note that calling other operations using this ID are not required to find the object until 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.

Specified by:
createObject in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
Returns:
the new object ID

markForUpdate

public void markForUpdate(Transaction txn,
                          long oid)
Notifies the 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.

Specified by:
markForUpdate in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
oid - the object ID

getObject

public byte[] getObject(Transaction txn,
                        long oid,
                        boolean forUpdate)
Obtains the data associated with an object ID. If the 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.

Specified by:
getObject in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
oid - the object ID
forUpdate - whether the caller intends to modify the object
Returns:
the data associated with the object ID

setObject

public void setObject(Transaction txn,
                      long oid,
                      byte[] data)
Specifies data to associate with an object ID.

Specified by:
setObject in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
oid - the object ID
data - the data

setObjects

public void setObjects(Transaction txn,
                       long[] oids,
                       byte[][] dataArray)
Specifies data to associate with a series of object IDs.

Specified by:
setObjects in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
oids - the object IDs
dataArray - the associated data values

removeObject

public void removeObject(Transaction txn,
                         long oid)
Removes the object with the specified object ID. The implementation will make an effort to flag subsequent references to the removed object by throwing 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.

Specified by:
removeObject in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
oid - the object ID

getBinding

public long getBinding(Transaction txn,
                       String name)
Obtains the object ID bound to a name.

Specified by:
getBinding in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
name - the name
Returns:
the object ID

setBinding

public void setBinding(Transaction txn,
                       String name,
                       long oid)
Binds an object ID to a name.

Specified by:
setBinding in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
name - the name
oid - the object ID

removeBinding

public void removeBinding(Transaction txn,
                          String name)
Removes the binding for a name.

Specified by:
removeBinding in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
name - the name

nextBoundName

public 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. If name is null, then the search starts at the beginning.

Specified by:
nextBoundName in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
name - the name to search after, or null to start at the beginning
Returns:
the next name with a binding following name, or null if there are no more bound names

shutdown

public void shutdown()
Shuts down this data store. This method will block until the shutdown is complete.

Specified by:
shutdown in interface DataStore

getClassId

public int getClassId(Transaction txn,
                      byte[] classInfo)
Returns the class ID to represent classes with the specified class information. Obtains an existing ID for the class information if present; otherwise, stores the information and returns the new ID associated with it. Class IDs are always greater than 0. The class information is the serialized form of the ObjectStreamClass instance that serialization uses to represent the class.

Specified by:
getClassId in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
classInfo - the class information
Returns:
the associated class ID

getClassInfo

public byte[] getClassInfo(Transaction txn,
                           int classId)
                    throws ClassInfoNotFoundException
Returns the class information associated with the specified class ID. The class information is the serialized form of the ObjectStreamClass instance that serialization uses to represent the class.

Specified by:
getClassInfo in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
classId - the class ID
Returns:
the associated class information
Throws:
ClassInfoNotFoundException - if the ID is not found

nextObjectId

public 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. 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.

Specified by:
nextObjectId in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
oid - the identifier of the object to search after, or -1 to request the first object
Returns:
the identifier of the next object following the object with identifier oid, or -1 if there are no more objects

setBindingDescription

public void setBindingDescription(Transaction txn,
                                  String name,
                                  Object description)
Associates a description with a bound name, for use in describing name accesses. The description should provide a meaningful toString method.

Specified by:
setBindingDescription in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
name - the name
description - the description
See Also:
AccessReporter.setObjectDescription

setObjectDescription

public void setObjectDescription(Transaction txn,
                                 long oid,
                                 Object description)
Associates a description with an object ID, for use in describing object accesses. The description should provide a meaningful toString method.

Specified by:
setObjectDescription in interface DataStore
Parameters:
txn - the transaction under which the operation should take place
oid - the object ID
description - the description
See Also:
AccessReporter.setObjectDescription

prepare

public boolean prepare(Transaction txn)
                throws Exception
Tells the participant to prepare for commiting its state associated with the given transaction. This method returns a 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.

Specified by:
prepare in interface TransactionParticipant
Parameters:
txn - the Transaction object
Returns:
true if this participant is read-only, false otherwise
Throws:
Exception - if there are any failures in preparing
IllegalStateException - if this participant has already been prepared, committed, or aborted, or if this participant is not participating in the given transaction

commit

public void commit(Transaction txn)
Tells the participant to commit its state associated with the given transaction.

Specified by:
commit in interface TransactionParticipant
Parameters:
txn - the Transaction object

prepareAndCommit

public void prepareAndCommit(Transaction txn)
                      throws Exception
Tells the participant to both prepare and commit its state associated with the given transaction.

Specified by:
prepareAndCommit in interface TransactionParticipant
Parameters:
txn - the Transaction object
Throws:
Exception - if there are any failures in preparing
IllegalStateException - if this participant has already been prepared, committed, or aborted, or if this participant is not participating in the given transaction

abort

public void abort(Transaction txn)
Tells the participant to abort its involvement with the given transaction.

Specified by:
abort in interface TransactionParticipant
Parameters:
txn - the Transaction object

getTypeName

public String getTypeName()
Returns the fully qualified type name of the participant. If this participant is acting as a proxy for a Service, this will typically be the Service's type name.

Specified by:
getTypeName in interface TransactionParticipant
Returns:
the name of the participant

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
a string representation of this object

getDataStore

public DataStore getDataStore()
Returns the DataStore that this instance delegates to.

Returns:
the DataStore that this instance delegates to

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved