Class CacheAdapter
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.tangosol.run.jca.CacheAdapter
-
public class CacheAdapter extends Base
CacheAdapter encapsulates the operations neccessary to communicate with Coherence™ resource adapter (coherence-tx.rar). The Coherence resource adapter, in turn, is a gateway into the Coherence clustered services, so some methods closely resemble methods atCacheFactory
class.In a simplest form a client code would look like:
Note: the CacheAdapter is intended to be used by one and only one thread at the time and is not thread safe.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(); }
- Since:
- Coherence 1.2
- Author:
- gg 2002.04.14
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CacheAdapter.CacheConnectionSpec
CacheConnectionSpec is an implementation ofConnectionSpec
interface used to pass the connection info to the adapter.-
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
-
Field Summary
Fields Modifier and Type Field Description static int
CONCUR_EXTERNAL
Same asTransactionMap.CONCUR_EXTERNAL
static int
CONCUR_OPTIMISTIC
Same asTransactionMap.CONCUR_OPTIMISTIC
static int
CONCUR_PESSIMISTIC
static int
TRANSACTION_GET_COMMITTED
static int
TRANSACTION_REPEATABLE_GET
static int
TRANSACTION_SERIALIZABLE
-
Constructor Summary
Constructors Constructor 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
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method 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.-
Methods inherited from class com.tangosol.util.Base
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, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, 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
-
-
-
-
Field Detail
-
TRANSACTION_GET_COMMITTED
public static final int TRANSACTION_GET_COMMITTED
- See Also:
- Constant Field Values
-
TRANSACTION_REPEATABLE_GET
public static final int TRANSACTION_REPEATABLE_GET
- See Also:
- Constant Field Values
-
TRANSACTION_SERIALIZABLE
public static final int TRANSACTION_SERIALIZABLE
- See Also:
- Constant Field Values
-
CONCUR_PESSIMISTIC
public static final int CONCUR_PESSIMISTIC
- See Also:
- Constant Field Values
-
CONCUR_OPTIMISTIC
public static final int CONCUR_OPTIMISTIC
Same asTransactionMap.CONCUR_OPTIMISTIC
- See Also:
- Constant Field Values
-
CONCUR_EXTERNAL
public static final int CONCUR_EXTERNAL
Same asTransactionMap.CONCUR_EXTERNAL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CacheAdapter
public CacheAdapter()
Construct the adapter using a default InitialContext, standard JNDI name, "optimistic" concurrency, "committed" isolation level an no timeout.
-
CacheAdapter
public CacheAdapter(Context ctx, String sJndiName, int nConcur, int nIsolation, int nTimeout)
Construct the adapter using the specified Context and JNDI name- Parameters:
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)
-
-
Method Detail
-
getReplicatedCache
public NamedCache getReplicatedCache(String sName, ClassLoader loader)
Deprecated.Obtain an instance of a ReplicatedCache.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.
- Parameters:
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 cluster- Returns:
- NamedCache interface of the ReplicatedCache service
- Throws:
IllegalStateException
- if the adapter is already connected to a different service
-
getDistributedCache
public NamedCache getDistributedCache(String sName, ClassLoader loader)
Deprecated.Obtain an instance of a DistributedCache.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.
- Parameters:
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 cluster- Returns:
- NamedCache interface of the DistributedCache service
- Throws:
IllegalStateException
- if the adapter is already connected to a different service
-
connect
public void connect(String sServiceName, String sUserName, String sPassword)
Connect the adapter to the specified clustered service. The service with the specified name must be running for this call to succeed.- Parameters:
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)- Throws:
IllegalArgumentException
- if the specified service is not runningIllegalStateException
- if the adapter is already connected or
-
connect
public void connect(String sServiceName, String sServiceType, String sUserName, String sPassword)
Connect the adapter to the specified clustered service. If the service with the specified name is not running an attempt will be made to start that service [default configuration]. If the name and type are not specified, a ConfigurableCacheFactory will be used to obtain the NamedCache instances.- Parameters:
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)- Throws:
IllegalArgumentException
- if the specified service cannot be foundIllegalStateException
- if the adapter is already connected
-
getNamedCache
public NamedCache getNamedCache(String sName, ClassLoader loader)
Obtain an instance of a NamedCache. The NamedCache will be retrieved from the current ConfigurableCacheFactory usingCacheFactory.getCache(sName, loader)
unless the adapter is already connected to a specific cache service, in which case the corresponding NamedCache will be retrieved usingservice.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.
- Parameters:
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 cluster- Returns:
- NamedCache object
-
getNamedCache
public NamedCache getNamedCache(String sName, ClassLoader loader, TransactionMap.Validator validator, boolean fImmutable)
Obtain an instance of a NamedCache. The NamedCache will be retrieved from the current ConfigurableCacheFactory usingCacheFactory.getCache(sName, loader)
unless the adapter is already connected to a specific cache service, in which case the corresponding NamedCache will be retrieved usingservice.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.
- Parameters:
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 context- Returns:
- NamedCache object
- Since:
- Coherence 2.3
- See Also:
TransactionMap.setValidator()
,TransactionMap.setValuesImmutable()
-
close
public void close()
Close the connection associated with this adapter.
-
isConnected
protected boolean isConnected()
Return the connection status.- Returns:
- true if the adapter is currently connected; false otherwise.
-
toString
public String toString()
Return a human readable description of the CacheAdapter.
-
-