org.apache.geode.cache.client

## Interface ClientCache

- All Superinterfaces:
    java.lang.AutoCloseable, GemFireCache, RegionService

      public interface ClientCache
      extends GemFireCache

  A ClientCache instance controls the life cycle of the local singleton cache in a client.

  A ClientCache is created using `ClientCacheFactory.create()`. See `ClientCacheFactory` for common usage patterns for creating the client cache instance.

  ClientCache provides access to functionality when a member connects as a client to GemFire servers. It provides the following services:

  - Access to existing regions (see `RegionService.getRegion(java.lang.String)` and `RegionService.rootRegions()`).
  - Creation of regions (see `createClientRegionFactory(ClientRegionShortcut)` and `createClientRegionFactory(String)`).
  - Access the query service (see `getQueryService(java.lang.String)` and `getLocalQueryService()`).
  - Access the GemFire logger (see `GemFireCache.getLogger()`).
  - Access the GemFire distributed system (see `GemFireCache.getDistributedSystem()`).
  - Access the GemFire resource manager (see `GemFireCache.getResourceManager()`).
  - Manages local disk stores for this cache instance (see `GemFireCache.createDiskStoreFactory()`).
  - Creation of authenticated cache views that support multiple users (see `createAuthenticatedView(java.util.Properties)`).

  A ClientCache connects to a server using a `Pool`. This pool can be configured in the ClientCacheFactory (by default GemFire tries to create a pool which tries to connect to a server on the localhost on port 40404). This default pool is used by `Region`s (created using `ClientRegionFactory`) to talk to regions on the server.

  More pools can be created using `PoolManager` or by declaring them in cache.xml.

  Since:
    GemFire 6.5

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close(boolean keepalive)` Terminates this object cache and releases all the resources.
    `RegionService` | `createAuthenticatedView(java.util.Properties userSecurityProperties)` Creates an authenticated cache view using the given user security properties on the client cache's default pool.
    `RegionService` | `createAuthenticatedView(java.util.Properties userSecurityProperties, java.lang.String poolName)` Creates an authenticated cache view using the given user security properties using the given pool to connect to servers.
    `<K,V> ClientRegionFactory<K,V>` | `createClientRegionFactory(ClientRegionShortcut shortcut)` Create and return a client region factory that is initialized to create a region using the given predefined region attributes.
    `<K,V> ClientRegionFactory<K,V>` | `createClientRegionFactory(java.lang.String regionAttributesId)` Create and return a client region factory that is initialized to create a region using the given named region attributes.
    `java.util.Set<java.net.InetSocketAddress>` | `getCurrentServers()` Returns a set of the servers to which this client is currently connected.
    `Pool` | `getDefaultPool()` Returns the default server pool.
    `QueryService` | `getLocalQueryService()` Return a QueryService that queries the local state in the client cache.
    `QueryService` | `getQueryService(java.lang.String poolName)` Return the QueryService for the named pool.
    `void` | `readyForEvents()` Notifies the server that this durable client is ready to receive updates.

    - ### Methods inherited from interface org.apache.geode.cache.GemFireCache

      `createDiskStoreFactory, createGatewaySenderFactory, findDiskStore, getCacheTransactionManager, getCopyOnRead, getDistributedSystem, getInitializer, getInitializerProps, getJNDIContext, getLogger, getName, getPdxDiskStore, getPdxIgnoreUnreadFields, getPdxPersistent, getPdxReadSerialized, getPdxSerializer, getRegionAttributes, getResourceManager, getSecurityLogger, listRegionAttributes, loadCacheXml, registerPdxMetaData, setCopyOnRead, setRegionAttributes`

    - ### Methods inherited from interface org.apache.geode.cache.RegionService

      `close, createPdxEnum, createPdxInstanceFactory, getCancelCriterion, getQueryService, getRegion, isClosed, rootRegions`

- - ### Method Detail

    - #### getQueryService

          QueryService getQueryService(java.lang.String poolName)

      Return the QueryService for the named pool. The query operations performed using this QueryService will be executed on the servers that are associated with this pool.

    - #### getLocalQueryService

          QueryService getLocalQueryService()

      Return a QueryService that queries the local state in the client cache. These queries will not be sent to a server.

    - #### close

          void close(boolean keepalive)

      Terminates this object cache and releases all the resources. Calls `Region.close()` on each region in the cache. After this cache is closed, any further method call on this cache or any region object will throw `CacheClosedException`, unless otherwise noted.
      Parameters:
        `keepalive` - whether the server should keep the durable client's queues alive for the timeout period
      Throws:
        `CacheClosedException` - if the cache is already closed.

    - #### createClientRegionFactory

          <K,V> ClientRegionFactory<K,V> createClientRegionFactory(ClientRegionShortcut shortcut)

      Create and return a client region factory that is initialized to create a region using the given predefined region attributes.
      Parameters:
        `shortcut` - the predefined region attributes to initialize the factory with.
      Returns:
        a factory that will produce a client region.

    - #### createClientRegionFactory

          <K,V> ClientRegionFactory<K,V> createClientRegionFactory(java.lang.String regionAttributesId)

      Create and return a client region factory that is initialized to create a region using the given named region attributes.

      Named region attributes are defined in cache.xml by setting the name as the value of the `id` attribute on a `region-attributes` element.

      Parameters:
        `regionAttributesId` - the named region attributes to initialize the factory with.
      Returns:
        a factory that will produce a client region.
      Throws:
        `java.lang.IllegalStateException` - if named region attributes has not been defined.

    - #### readyForEvents

          void readyForEvents()

      Notifies the server that this durable client is ready to receive updates. This method is used by durable clients to notify servers that they are ready to receive updates. As soon as the server receives this message, it will forward updates to this client (if necessary).

      Durable clients must call this method after they are done creating regions and issuing interest registration requests.If it is called before then events will be lost.Any time a new `Pool` is created and regions have been added to it then this method needs to be called again.

      Throws:
        `java.lang.IllegalStateException` - if called by a non-durable client

    - #### createAuthenticatedView

          RegionService createAuthenticatedView(java.util.Properties userSecurityProperties)

      Creates an authenticated cache view using the given user security properties on the client cache's default pool. Multiple views with different user properties can be created on a single client cache. Requires that `multiuser-authentication` to be set to true on the default pool. Applications must use this instance to do operations, when multiuser-authentication is set to true.

      Authenticated cache views are only allows to access `proxy` regions. The `RegionService.getRegion(java.lang.String)` method will throw IllegalStateException if an attempt is made to get a region that has local storage.

      Parameters:
        `userSecurityProperties` - the security properties of a user.
      Returns:
        the `RegionService` instance associated with a user and the given properties.
      Throws:
        `java.lang.UnsupportedOperationException` - when invoked with multiuser-authentication as false.

    - #### createAuthenticatedView

          RegionService createAuthenticatedView(java.util.Properties userSecurityProperties,
                                                java.lang.String poolName)

      Creates an authenticated cache view using the given user security properties using the given pool to connect to servers. Requires that `multiuser-authentication` to be set to true on the given pool.

      See `createAuthenticatedView(Properties)` for more information on the returned cache view.

      Parameters:
        `userSecurityProperties` - the security properties of a user.
        `poolName` - - the pool that the users should be authenticated against.
      Returns:
        the `RegionService` instance associated with a user and the given properties.

    - #### getCurrentServers

          java.util.Set<java.net.InetSocketAddress> getCurrentServers()

      Returns a set of the servers to which this client is currently connected.
      Since:
        GemFire 6.6

    - #### getDefaultPool

          Pool getDefaultPool()

      Returns the default server pool. If one or more non-default pools were configured, this may return null.
      Since:
        GemFire 7.0
      See Also:
        `Pool`