|
IBM WebSphereTM eXtreme Scale, Release 8.6 API Specification |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Session
This interface represents a session container for ObjectMap
s. A thread must get its own Session
object to interact with ObjectGrid. You can think of this interface as a session that can only be used by a single
thread at a time. A Session itself is shareable across threads so long as only one thread uses it at a time. However,
if a J2EE connection/transaction infrastructure is being used, that won't be shareable across threads and will
prevent the Session object from being shared across threads. A good analogy for this object is a JDBC connection to a
database.
For best performance, use the close()
method to close the session once it is no longer required.
ObjectGrid.getSession()
,
ObjectGrid.getSession(Subject)
,
ObjectGrid.getSession(CredentialGenerator)
Nested Class Summary | |
---|---|
static class |
Session.TxCommitProtocol
The commit protocols that can be used to commit the Session's transaction |
Field Summary | |
---|---|
static long |
DEFAULT_RETRY_TIMEOUT
|
static int |
TRANSACTION_NO_TIMEOUT
A special value for the timeout parameter of the setTransactionTimeout(int) method. |
static int |
TRANSACTION_READ_COMMITTED
A transaction isolation level constant indicating that dirty reads are prevented; non-repeatable reads and phantom reads can occur. |
static int |
TRANSACTION_READ_UNCOMMITTED
A transaction isolation level constant indicating that dirty reads, non-repeatable reads and phantom reads can occur. |
static int |
TRANSACTION_REPEATABLE_READ
A transaction isolation level constant indicating that dirty reads and non-repeatable reads are prevented; phantom reads can occur. |
static String |
TRANSACTION_TYPE_DEFAULT
A string indicating the default transaction type |
Method Summary | |
---|---|
void |
begin()
Begins a new transaction. |
void |
beginNoWriteThrough()
Starts a new transaction that does not write changes through to a Loader or ObjectGrid server. |
void |
close()
Closes this session, freeing all resources that are held. |
void |
commit()
Commits a transaction. |
ObjectQuery |
createObjectQuery(String qlString)
Creates an instance of an object query for executing a query over the ObjectMaps visible to this session. |
void |
flush()
Forces the current changes in the Session to the Loader or ObjectGrid server. |
EntityManager |
getEntityManager()
Retrieve the EntityManager associated with this Session. |
ObjectMap |
getMap(String cacheName)
Returns the ObjectMap for the specified name. |
ObjectGrid |
getObjectGrid()
Returns the ObjectGrid that owns this session. |
long |
getRequestRetryTimeout()
Retrieves the current request retry timeout for this session. |
SessionHandle |
getSessionHandle()
Retrieves a handle for this session. |
int |
getTransactionIsolation()
Retrieves the current transaction isolation level for this session. |
int |
getTransactionTimeout()
Gets current transaction timeout for this Session. |
String |
getTransactionType()
Retrieves the transaction type that is set with the setTransactionType(String) method. |
Session.TxCommitProtocol |
getTxCommitProtocol()
Retrieve the current commit protocol for this Session. |
TxID |
getTxID()
Gets the TxID transaction identifier, if a transaction is active. |
boolean |
isCommitting()
Returns whether the current session transaction is performing a session commit() operation. |
boolean |
isFlushing()
Returns whether the current session transaction is performing a session flush() operation. |
boolean |
isMarkedRollbackOnly()
Returns whether or not the current active session transaction is marked as being rollback only as a result of a prior call to the markRollbackOnly(Throwable) method on this Session. |
boolean |
isSessionHandleSet()
Determines if a SessionHandle is currently set on this Session. |
boolean |
isTransactionActive()
Determines if a transaction is currently active. |
boolean |
isWriteThroughEnabled()
Returns whether the current session transaction is writing through to the back end Loader or
ObjectGrid server(true ), or if the changes are only applying to the BackingMap (false )
or client respectively. |
void |
markRollbackOnly(Throwable t)
Marks the current transaction as being rollback only. |
void |
processLogSequence(LogSequence logSequence)
Processes a LogSequence . |
void |
rollback()
Rolls back a transaction. |
void |
setRequestRetryTimeout(long requestRetryTimeout)
Set the request retry timeout to indicate how long to retry a request (in milliseconds) when recoverable failures occur, such as fail-over exceptions. |
void |
setSessionHandle(SessionHandle target)
Apply a SessionHandle to this session. |
void |
setTransactionIsolation(int level)
Attempts to change the transaction isolation level for this session. |
void |
setTransactionTimeout(int timeout)
Sets the transaction timeout for the next transaction started by this Session object to a specified number of seconds. |
void |
setTransactionType(String tranType)
Sets the transaction type for future transactions. |
void |
setTxCommitProtocol(Session.TxCommitProtocol protocol)
Set the commit protocol to be used when committing this Session's transaction. |
boolean |
transactionTimedOut()
Determines whether the current session transaction has timed out. |
Field Detail |
---|
static final String TRANSACTION_TYPE_DEFAULT
static final int TRANSACTION_NO_TIMEOUT
setTransactionTimeout(int)
method. This special
value is used to indicate that the next transaction started by this Session is allowed unlimited amount of time.
setTransactionTimeout(int)
,
Constant Field Valuesstatic final long DEFAULT_RETRY_TIMEOUT
static final int TRANSACTION_REPEATABLE_READ
setTransactionIsolation(int)
,
Constant Field Valuesstatic final int TRANSACTION_READ_COMMITTED
setTransactionIsolation(int)
,
Constant Field Valuesstatic final int TRANSACTION_READ_UNCOMMITTED
setTransactionIsolation(int)
,
Constant Field ValuesMethod Detail |
---|
void beginNoWriteThrough() throws TransactionAlreadyActiveException, TransactionException
Loader
or ObjectGrid server.
Changes made by the session transaction started by this method are only applied to the BackingMap
and not given to the Loader
. This method can be used to apply changes made in a peer cache to the
local BackingMap
only. In addition, with a distributed map, this method can be used to start a
session transaction which changes will only be applied to the client BackingMap
, but not the
BackingMap
on the server side.
TransactionAlreadyActiveException
- if there is already an active transaction
TransactionException
- a TransactionCallbackException
occurred or some other error occurred starting a new
transactionObjectMap getMap(String cacheName) throws UndefinedMapException
The ObjectMap is used to retrieve and modify values in the BackingMap. Multiple invocations of this method on the same Session object will always return the same object.
This method can also be used to create a BackingMap and its associated ObjectGrid after ObjectGrid initialization. If cacheName does not match the name of a previously created map, a name comparison will be executed against template maps that have been configured. The ObjectMap and BackingMap will be created if the name matches the regular expression of a template.
Required Client Permission: ObjectGridPermission.DYNAMIC_MAP
(when creating a new map from a template)
cacheName
- name of desired map
UndefinedMapException
- if the map is not defined.ObjectGrid.defineMap(String)
,
ObjectMap
void begin() throws TransactionAlreadyActiveException, TransactionException
TransactionAlreadyActiveException
- if this method is invoked with an active transaction
TransactionException
- a TransactionCallbackException
occurred or some other error occurred starting a new
transactionvoid commit() throws NoActiveTransactionException, TransactionException
NoActiveTransactionException
- if this method is invoked with no active transaction
TransactionException
- if an error occurred during commit processing, see the caused by to determine the root errormarkRollbackOnly(Throwable)
void rollback() throws NoActiveTransactionException, TransactionException
NoActiveTransactionException
- if this method is invoked with no active transaction
TransactionException
- if an error occurred during rollback processing, see the caused by to determine the root errorvoid flush() throws NoActiveTransactionException, TransactionException
Loader
or ObjectGrid server. This method does not
commit the changes, it just applies the changes.
NoActiveTransactionException
- if this method is invoked with no active transaction
TransactionException
- if an error occurred during flush processing, see the caused by to determine the root errorObjectGrid getObjectGrid()
boolean isTransactionActive()
TxID getTxID() throws NoActiveTransactionException
TxID
transaction identifier, if a transaction is active.
NoActiveTransactionException
- if this method is invoked with no active transactionboolean isWriteThroughEnabled()
Loader
or
ObjectGrid server(true
), or if the changes are only applying to the BackingMap
(false
)
or client respectively.
true
, if write through is enabledbegin()
,
beginNoWriteThrough()
void setTransactionType(String tranType)
After this method is called, all future transactions will have the same type until another transaction type is
set. If no transaction type is set, the default transaction type TRANSACTION_TYPE_DEFAULT
will be
used.
Transaction types are used mainly for statistical data tracking purpose. Users can predefine types of transactions that will be executed in an application. The idea is to categorize transactions with the same characteristics to one category (type), so one transaction response time statistics can be used to track each transaction type. This approach is useful when your application has different types of transactions. Some types of transactions, such as update transactions, process longer than others transactions, such as read-only transactions. By using the transaction type, different transactions are tracked by different statistics, so the statistics can be more useful.
tranType
- the transaction type for future transactions.TRANSACTION_TYPE_DEFAULT
String getTransactionType()
void processLogSequence(LogSequence logSequence) throws NoActiveTransactionException, UndefinedMapException, ObjectGridException
LogSequence
.
Each LogElement
within the LogSequence
will be examined and the appropriate
operation (insert, update, invalidate, etc) will be performed against the BackingMap
identified by
the LogSequence
's map name. An ObjectGrid Session must be active before this method is invoked.
The caller is responsible for issuing the appropriate commit or rollback invocation to complete the Session.
Autocommit processing is not available for this method invocation.
The main use of this method is for processing a LogSequence
that was received by a remote JVM. For
example, using the Distributed Commit support, the LogSequence
s associated with a given committed
Session are distributed to other listening ObjectGrid
s in other JVMs. After receiving the
LogSequence
s at the remote JVM, the listener could start a Session using
beginNoWriteThrough()
, invoke this method, and commit the Session transaction.
logSequence
- LogSequence of changes to be applied to an active transaction
NoActiveTransactionException
- if this method is invoked with no active transaction
UndefinedMapException
- if the map referenced by the LogSequence cannot be found
ObjectGridException
- if the LogSequence elements cannot be processedbeginNoWriteThrough()
,
LogSequence
,
ObjectGridEventListener
boolean isFlushing()
flush()
operation. It is
helpful to know if a session flush()
is active (true
), or if only an
ObjectMap.flush()
is in progress (returns false
in this case).
flush()
call.flush()
,
ObjectMap.flush()
boolean isCommitting()
commit()
operation. It is
helpful to know if a session commit is active (true
), or if an ObjectMap.flush()
or session flush()
is in progress (returns false
in these cases).
commit()
call.commit()
,
flush()
,
ObjectMap.flush()
void markRollbackOnly(Throwable t) throws NoActiveTransactionException
Marking a transaction rollback only ensures that even if the commit()
method is called for this
session transaction, the transaction is rolled back. A rollback is typically done when either ObjectGrid itself
or the application knows that data corruption could occur if the commit()
method was allowed to
commit the transaction. Once this method is called, the Throwable object that is passed to it is chained to the
TransactionException
that is thrown if the commit method is ever called. Any subsequent calls to
this method for the current active transaction is ignored (e.g. only the first call that passes a non null
Throwable reference is used). Once the transaction is completed, the rollback only mark is removed so that the
next transaction that is started using this session can be committed.
t
- the Throwable that caused this method to be called.
NoActiveTransactionException
- if there is no active transaction for this Session.commit()
,
TransactionException
boolean isMarkedRollbackOnly()
markRollbackOnly(Throwable)
method on this Session.
markRollbackOnly(Throwable)
void setTransactionTimeout(int timeout)
This method does not affect the transaction timeout of any transactions previously started by this Session. It only affects transactions that are started after this method is called. If this method is never called, the ObjectGrid configured transaction timeout value is used.
timeout
- is the transaction timeout value in seconds. Use the special value TRANSACTION_NO_TIMEOUT
if transaction is allowed unlimited amount of time and no transaction timeout should occur.TRANSACTION_NO_TIMEOUT
,
ObjectGrid.setTxTimeout(int)
,
TransactionTimeoutException
int getTransactionTimeout()
The transaction timeout value returned is the value that was configured for the ObjectGrid
using
ObjectGrid.setTxTimeout(int)
or the value passed to setTransactionTimeout(int)
to
override the value configured on ObjectGrid
. The return value is in seconds.
setTransactionTimeout(int)
,
ObjectGrid.setTxTimeout(int)
int getTransactionIsolation()
TRANSACTION_READ_UNCOMMITTED
, TRANSACTION_READ_COMMITTED
or TRANSACTION_REPEATABLE_READ
boolean transactionTimedOut()
setTransactionTimeout(int)
ObjectQuery createObjectQuery(String qlString) throws ObjectQueryException
When ObjectGrid security is enabled, this method requires an com.ibm.websphere.objectgrid.security.ObjectGridPermission with action "query".
Required Client Permission: ObjectGridPermission.QUERY
qlString
- a query string
ObjectQueryException
- if an error occurs creating the object query.EntityManager getEntityManager()
void setTransactionIsolation(int level)
This method should normally be invoked prior to beginning a transaction. Invoking after a transaction has started may result in an exception.
level
- one of the following Session constants:
TRANSACTION_READ_UNCOMMITTED
, TRANSACTION_READ_COMMITTED
or TRANSACTION_REPEATABLE_READ
SessionHandle getSessionHandle()
A SessionHandle contains partition information for the current session and can be re-applied to a new session
using the setSessionHandle(SessionHandle)
method. A SessionHandle is
only applicable for ObjectGrids using per-container partition placement.
If setSessionHandle(SessionHandle)
is not called before invoking this
method, a Session Handle is selected using the properties configured in the
ClientProperties
. If there are no per-container partition placement mapsets
or more than one in the ObjectGrid, an IllegalStateException
is thrown.
IllegalStateException
- if this method is called in an invalid environment.void setSessionHandle(SessionHandle target) throws TargetNotAvailableException
target
- the SessionHandle to apply or null to disassociate a SessionHandle from
this session.
TargetNotAvailableException
- when the target is no longer available.
IllegalStateException
- if the Session has modified some maps already and the SessionHandle has already been set
or if this method is called in an invalidate environment.void setRequestRetryTimeout(long requestRetryTimeout)
A value of 0 indicates that all requests should fail immediately and avoid any retry logic. Exceptions that cannot succeed even if tried again such as DuplicateKeyException exceptions will be thrown immediately.
A value of -1 indicates that the request retry timeout is not set, meaning that the request duration is governed by the request retry timeout set on the ClientProperties. If the ClientProperties is also set to -1, then the request retry timeout is governed by the transaction timeout.
requestRetryTimeout
- the duration in milliseconds retry a client request, 0 if the request should
fail immediately or -1 if the request timeout is not set.ClientProperties.setRequestRetryTimeout(long)
,
setTransactionTimeout(int)
long getRequestRetryTimeout()
boolean isSessionHandleSet()
void close()
ObjectGrid.getSession()
methods to retrieve a new session.
If the session has an active transaction, the transaction will be rolled
back and the session resources are not freed.
ObjectGridRuntimeException
- thrown if there is a problem releasing resources held by this
session.void setTxCommitProtocol(Session.TxCommitProtocol protocol)
This method should normally be invoked prior to beginning a transaction. Invoking after a transaction has started will result in an exception.
protocol
- one of the following constants TxCommitProtocol.ONEPHASE or TxCommitProtocol.TWOPHASESession.TxCommitProtocol getTxCommitProtocol()
|
IBM WebSphereTM eXtreme Scale, Release 8.6 API Specification |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |