public class CacheAdapter extends Base
CacheFactory
class.
In a simplest form a client code would look like:
Context ctx = new InitialContext();
CacheAdapter adapter = new CacheAdapter(ctx, "tangosol.coherenceTx",
CacheAdapter.CONCUR_OPTIMISTIC, CacheAdapter.TRANSACTION_REPEATABLE_GET, 0);
try
{
NamedCache map = adapter.getNamedCache("MyCache", getClass().getClassLoader(),
new SimpleValidator(), false);
// perform operations on the map
}
finally
{
adapter.close();
}
Note: the CacheAdapter is intended to be used by one and only one thread
at the time and is not thread safe.Modifier and Type | Class and Description |
---|---|
static class |
CacheAdapter.CacheConnectionSpec
CacheConnectionSpec is an implementation of
ConnectionSpec
interface used to pass the connection info to the adapter. |
Base.LoggingWriter, Base.StackFrame
Modifier and Type | Field and Description |
---|---|
static int |
CONCUR_EXTERNAL
Same as
TransactionMap.CONCUR_EXTERNAL |
static int |
CONCUR_OPTIMISTIC
Same as
TransactionMap.CONCUR_OPTIMISTIC |
static int |
CONCUR_PESSIMISTIC
|
static int |
TRANSACTION_GET_COMMITTED
|
static int |
TRANSACTION_REPEATABLE_GET
|
static int |
TRANSACTION_SERIALIZABLE
|
Constructor and Description |
---|
CacheAdapter()
Construct the adapter using a default InitialContext,
standard JNDI name, "optimistic" concurrency, "committed" isolation
level an no timeout.
|
CacheAdapter(Context ctx,
String sJndiName,
int nConcur,
int nIsolation,
int nTimeout)
Construct the adapter using the specified Context and JNDI name
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the connection associated with this adapter.
|
void |
connect(String sServiceName,
String sUserName,
String sPassword)
Connect the adapter to the specified clustered service.
|
void |
connect(String sServiceName,
String sServiceType,
String sUserName,
String sPassword)
Connect the adapter to the specified clustered service.
|
protected void |
finalize()
Perform cleanup during garbage collection.
|
NamedCache |
getDistributedCache(String sName,
ClassLoader loader)
Deprecated.
|
NamedCache |
getNamedCache(String sName,
ClassLoader loader)
Obtain an instance of a NamedCache.
|
NamedCache |
getNamedCache(String sName,
ClassLoader loader,
TransactionMap.Validator validator,
boolean fImmutable)
Obtain an instance of a NamedCache.
|
NamedCache |
getReplicatedCache(String sName,
ClassLoader loader)
Deprecated.
|
protected boolean |
isConnected()
Return the connection status.
|
String |
toString()
Return a human readable description of the CacheAdapter.
|
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
public static final int TRANSACTION_GET_COMMITTED
public static final int TRANSACTION_REPEATABLE_GET
public static final int TRANSACTION_SERIALIZABLE
public static final int CONCUR_PESSIMISTIC
public static final int CONCUR_OPTIMISTIC
TransactionMap.CONCUR_OPTIMISTIC
public static final int CONCUR_EXTERNAL
TransactionMap.CONCUR_EXTERNAL
public CacheAdapter()
public CacheAdapter(Context ctx, String sJndiName, int nConcur, int nIsolation, int nTimeout)
ctx
- the Context object to use for lookup operation;
if null, the default InitialiContext is usedsJndiName
- the JNDI name of the Coherence resource adapter;
if null, the default name ("tangosol.coherenceTx")
is usednConcur
- the default concurrency valuenIsolation
- the default transaction isolation valuenTimeout
- the default transaction timeout value (in seconds)public NamedCache getReplicatedCache(String sName, ClassLoader loader)
getNamedCache(java.lang.String, java.lang.ClassLoader)
instead.When called within a transaction, the returned cache will be transactional, controlled by the container's transaction coordinator. When called outside of a transaction, the returned cache will be non-transactional, which is equivalent to obtaining the instance directly from CacheFactory.
sName
- cache name (unique across the cluster). If the NamedCache
with the specified name already exists, a reference to
the same object will be returned in the same transactional
contextloader
- ClassLoader that should be used to deserialize objects
inserted in the map by other members of the clusterIllegalStateException
- if the adapter is already connected to a
different servicepublic NamedCache getDistributedCache(String sName, ClassLoader loader)
getNamedCache(java.lang.String, java.lang.ClassLoader)
instead.When called within a transaction, the returned cache will be transactional, controlled by the container's transaction coordinator. When called outside of a transaction, the returned cache will be non-transactional, which is equivalent to obtaining the instance directly from CacheFactory.
sName
- cache name (unique across the cluster). If the NamedCache
with the specified name already exists, a reference to
the same object will be returned in the same transactional
contextloader
- ClassLoader that should be used to deserialize objects
inserted in the map by other members of the clusterIllegalStateException
- if the adapter is already connected to a
different servicepublic void connect(String sServiceName, String sUserName, String sPassword)
sServiceName
- service name (unique across the cluster)sUserName
- name of the user establishing a connection (optional)sPassword
- password for the user establishing a connection (optional)IllegalArgumentException
- if the specified service is not runningIllegalStateException
- if the adapter is already connected orpublic void connect(String sServiceName, String sServiceType, String sUserName, String sPassword)
sServiceName
- service name (unique across the cluster)sServiceType
- service type (i.e. CacheService.TYPE_REPLICATED or
CacheService.TYPE_DISTRIBUTED)sUserName
- name of the user establishing a connection (optional)sPassword
- password for the user establishing a connection (optional)IllegalArgumentException
- if the specified service cannot be foundIllegalStateException
- if the adapter is already connectedpublic NamedCache getNamedCache(String sName, ClassLoader loader)
CacheFactory.getCache(sName, loader)
unless the adapter is already
connected to a specific cache service, in which case the
corresponding NamedCache will be retrieved using
service.ensureCache(sName, loader)
.
When called within a transaction, the returned cache will be transactional, controlled by the container's transaction coordinator. When called outside of a transaction, the returned cache will be non-transactional, which is equivalent to obtaining the instance directly from CacheFactory.
sName
- cache name (unique across the cluster).
If the NamedCache with the specified name already
exists, a reference to the same object will be
returned in the same transactional contextloader
- ClassLoader that should be used to deserialize objects
inserted in the map by other members of the clusterpublic NamedCache getNamedCache(String sName, ClassLoader loader, TransactionMap.Validator validator, boolean fImmutable)
CacheFactory.getCache(sName, loader)
unless the adapter is already
connected to a specific cache service, in which case the
corresponding NamedCache will be retrieved using
service.ensureCache(sName, loader)
.
When called within a transaction, the returned cache will be transactional, controlled by the container's transaction coordinator. When called outside of a transaction, the returned cache will be non-transactional, which is equivalent to obtaining the instance directly from CacheFactory.
sName
- cache name (unique across the cluster).
If the NamedCache with the specified name already
exists, a reference to the same object will be
returned in the same transactional contextloader
- ClassLoader that should be used to deserialize objects
inserted in the map by other members of the clustervalidator
- the Validator object to be used to enlist and validate
transactional resources; this parameter is only used
within transactional context and only for optimistic
concurrencyfImmutable
- specifies whether or not the values kept in this cache
are known to be immutable; this parameter is only used
within transactional contextTransactionMap.setValidator()
,
TransactionMap.setValuesImmutable()
public void close()
protected boolean isConnected()
public String toString()