Skip navigation links

Overview | Package | Class | Tree | Index | Help
| Oracle® Coherence Java API Reference Release 3.6.0.0 E15725-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.tangosol.run.jca
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 at `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.

Since:
  Coherence 1.2
Author:
  gg 2002.04.14

Nested Class Summary
`static class` | `CacheAdapter.CacheConnectionSpec` CacheConnectionSpec is an implementation of `ConnectionSpec` interface used to pass the connection info to the adapter.

Field Summary
`static int` | `CONCUR_EXTERNAL` Same as `TransactionMap.CONCUR_EXTERNAL`
`static int` | `CONCUR_OPTIMISTIC` Same as `TransactionMap.CONCUR_OPTIMISTIC`
`static int` | `CONCUR_PESSIMISTIC` Same as `TransactionMap.CONCUR_PESSIMISTIC`
`static int` | `TRANSACTION_GET_COMMITTED` Same as `TransactionMap.TRANSACTION_GET_COMMITTED`
`static int` | `TRANSACTION_REPEATABLE_GET` Same as `TransactionMap.TRANSACTION_REPEATABLE_GET`
`static int` | `TRANSACTION_SERIALIZABLE` Same as `TransactionMap.TRANSACTION_SERIALIZABLE`

Constructor Summary
`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
`void` | `close()` Close the connection assosiated 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. use `getNamedCache(java.lang.String, java.lang.ClassLoader)` instead.
`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. use `getNamedCache(java.lang.String, java.lang.ClassLoader)` instead.
`protected boolean` | `isConnected()` Return the connection status.
`String` | `toString()` Return a human readable description of the CacheAdapter.

Field Detail

### TRANSACTION_GET_COMMITTED

    public static final int TRANSACTION_GET_COMMITTED

  Same as `TransactionMap.TRANSACTION_GET_COMMITTED`
  See Also:
    Constant Field Values

### TRANSACTION_REPEATABLE_GET

    public static final int TRANSACTION_REPEATABLE_GET

  Same as `TransactionMap.TRANSACTION_REPEATABLE_GET`
  See Also:
    Constant Field Values

### TRANSACTION_SERIALIZABLE

    public static final int TRANSACTION_SERIALIZABLE

  Same as `TransactionMap.TRANSACTION_SERIALIZABLE`
  See Also:
    Constant Field Values

### CONCUR_PESSIMISTIC

    public static final int CONCUR_PESSIMISTIC

  Same as `TransactionMap.CONCUR_PESSIMISTIC`
  See Also:
    Constant Field Values

### CONCUR_OPTIMISTIC

    public static final int CONCUR_OPTIMISTIC

  Same as `TransactionMap.CONCUR_OPTIMISTIC`
  See Also:
    Constant Field Values

### CONCUR_EXTERNAL

    public static final int CONCUR_EXTERNAL

  Same as `TransactionMap.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 used
    `sJndiName` - the JNDI name of the Coherence resource adapter; if null, the default name ("tangosol.coherenceTx") is used
    `nConcur` - the default concurrency value
    `nIsolation` - the default transaction isolation value
    `nTimeout` - the default transaction timeout value (in seconds)

Method Detail

### getReplicatedCache

    public NamedCache getReplicatedCache(String sName,
                                         ClassLoader loader)

  Deprecated. use `getNamedCache(java.lang.String, java.lang.ClassLoader)` instead.
  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 context
    `loader` - 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. use `getNamedCache(java.lang.String, java.lang.ClassLoader)` instead.
  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 context
    `loader` - 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 running
    `IllegalStateException` - 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 found
    `IllegalStateException` - 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 using `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.

  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 context
    `loader` - 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 using `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.

  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 context
    `loader` - ClassLoader that should be used to deserialize objects inserted in the map by other members of the cluster
    `validator` - the Validator object to be used to enlist and validate transactional resources; this parameter is only used within transactional context and only for optimistic concurrency
    `fImmutable` - 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 assosiated 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.
  Returns:
    a String representation of the CacheAdapter

### finalize

    protected void finalize()

  Perform cleanup during garbage collection.

Skip navigation links

Overview | Package | Class | Tree | Index | Help
| Oracle® Coherence Java API Reference Release 3.6.0.0 E15725-01
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.