Class CacheResource

java.lang.Object
com.tangosol.coherence.rest.CacheResource

public class CacheResource extends Object
RESTful wrapper around a Coherence NamedCache.
Author:
as 2011.06.03
  • Field Details

    • m_cache

      protected NamedCache m_cache
      NamedCache wrapped by this resource.
    • m_clzKey

      protected Class m_clzKey
      Key class for the entries stored in the wrapped cache.
    • m_clzValue

      protected Class m_clzValue
      Value class for the entries stored in the wrapped cache.
    • m_keyConverter

      protected KeyConverter m_keyConverter
      Key converter.
    • m_cMaxResults

      protected int m_cMaxResults
      Size of the result set this resource is allowed to return.
    • m_marshallerRegistry

      @Inject protected MarshallerRegistry m_marshallerRegistry
      Marshaller registry to obtain marshallers from.
    • m_queryConfig

      protected QueryConfig m_queryConfig
      Query configuration for this resource.
    • m_queryEngineRegistry

      @Inject protected QueryEngineRegistry m_queryEngineRegistry
      Query engine registry to obtain query engines from.
    • m_aggregatorRegistry

      @Inject protected AggregatorRegistry m_aggregatorRegistry
      Aggregator registry that is used to map the given aggregator name to an EntryAggregator instance.
    • m_processorRegistry

      @Inject protected ProcessorRegistry m_processorRegistry
      a processor registry that is used to map the given processor name to an EntryProcessor instance.
    • m_serviceLocator

      @Inject protected org.glassfish.hk2.api.ServiceLocator m_serviceLocator
      The ServiceLocator for this resource.
  • Constructor Details

    • CacheResource

      public CacheResource(NamedCache cache, Class clzKey, Class clzValue, KeyConverter keyConverter, QueryConfig queryConfig, int cMaxResults)
      Construct a new CacheResource.
      Parameters:
      cache - cache to create a resource for
      clzKey - key class of the cached entries
      clzValue - value class of the cached entries
      keyConverter - key converter to use
      queryConfig - query configuration for this resource
      cMaxResults - max size of result set for this resource
  • Method Details

    • getValues

      @GET @Produces({"application/json","application/xml"}) public jakarta.ws.rs.core.Response getValues(@MatrixParam("start") @DefaultValue("0") int nStart, @MatrixParam("count") @DefaultValue("-1") int cResults, @MatrixParam("sort") String sSort, @MatrixParam("p") PropertySet propertySet, @QueryParam("q") String sQuery)
      Return the cache values (or a subset of their properties) that satisfy the specified criteria.
      Parameters:
      nStart - starting index of result set to be returned
      cResults - size of result set to be returned (page size)
      sSort - a string expression that represents ordering
      propertySet - the subset of properties to return for each value (if null, the complete values will be returned)
      sQuery - where predicate of Coherence Query Language to filter cache entries. If null, all cache values will be returned
      Returns:
      the cache values (or a subset of their properties) that satisfy specified criteria
    • getEntries

      @GET @Path("entries") @Produces({"application/json","application/xml","text/plain"}) public jakarta.ws.rs.core.Response getEntries(@MatrixParam("start") @DefaultValue("0") int nStart, @MatrixParam("count") @DefaultValue("-1") int cResults, @MatrixParam("sort") String sSort, @MatrixParam("p") PropertySet propertySet, @QueryParam("q") String sQuery)
      Return the cache entries that satisfy the given query criteria.
      Parameters:
      nStart - starting index of result set to be returned
      cResults - size of result set to be returned (page size)
      sSort - a string expression that represents ordering
      propertySet - the subset of properties to return for each value (if null, the complete values will be returned)
      sQuery - where predicate of Coherence Query Language to filter cache entries. If null, all cache entries will be returned
      Returns:
      the cache entries that satisfy specified criteria
    • getKeys

      @GET @Path("keys") @Produces({"application/json","application/xml","text/plain"}) public jakarta.ws.rs.core.Response getKeys(@QueryParam("q") String sQuery)
      Return the keys of cache entries that satisfy the given query criteria.
      Parameters:
      sQuery - query expression
      Returns:
      the keys of cache entries that satisfy the given query criteria
    • aggregate

      @GET @Path("{aggr: \\s*(\\w(?:\\w|-)*)\\((.*)\\)}") @Produces({"application/json","application/xml","text/plain"}) public jakarta.ws.rs.core.Response aggregate(@PathParam("aggr") String sAggr, @QueryParam("q") String sQuery)
      Perform an aggregating operation against the entries that satisfy the specified criteria. If the query string is empty all cache entries are aggregated.
      Parameters:
      sAggr - name of the aggregator
      sQuery - where predicate of Coherence Query Language to filter cache entries (optional)
      Returns:
      the result of the aggregation
    • process

      @POST @Path("{proc: \\s*(\\w(?:\\w|-)*)\\((.*)\\)}") @Produces({"application/json","application/xml"}) public jakarta.ws.rs.core.Response process(@PathParam("proc") String sProc, @QueryParam("q") String sQuery)
      Invoke the specified processor against the entries that satisfy the specified criteria. If the query string is empty all cache entries are processed.
      Parameters:
      sProc - the name of the processor
      sQuery - where predicate of Coherence Query Language to filter cache entries (optional)
      Returns:
      a Map containing the results of invoking the EntryProcessor against the entries that are selected by the given query
    • addListener

      @GET @Produces("text/event-stream") public org.glassfish.jersey.media.sse.EventOutput addListener(@MatrixParam("lite") boolean fLite, @QueryParam("q") String sQuery)
      Register SSE event listener for this cache.
      Parameters:
      fLite - flag specifying whether to register for lite or full events
      sQuery - an optional CohQL filter to register listener on
      Returns:
      the EventOutput that will be used to send events to the client
    • getEntryOrQueryResource

      @Path("{key: [^/]+}") public Object getEntryOrQueryResource(@PathParam("key") String sKey)
      Return a REST sub-resource representing either a configured named query or a single cache entry.
      Parameters:
      sKey - name of the configured query or referenced entry's key
      Returns:
      REST resource representing either a configured named query or a single cache entry
    • getEntrySetResource

      @Path("{keys: \\([^\\)]+\\)}") public EntrySetResource getEntrySetResource(@PathParam("keys") String sKeys)
      Return a REST sub-resource representing a set of cache entries.
      Parameters:
      sKeys - keys of the referenced entries
      Returns:
      REST sub-resource representing a set of cache entries
    • executeQuery

      protected Collection executeQuery(String sQuery, ValueExtractor<Map.Entry,?> extractor, int nStart, int cResults, String sSort)
      Returns a collection of extracted values for cache entries that satisfy the criteria expressed by the query.
      Parameters:
      sQuery - where predicate of Coherence Query Language to filter cache entries. If null, all cache entries will be returned.
      extractor - the extractor to apply to each entry in the result set
      nStart - the starting index of result set to be returned
      cResults - the size of result set to be returned (page size)
      sSort - a string expression that represents sort order
      Returns:
      a collection of entries that satisfy the specified criteria
    • keys

      protected Set keys(String sQuery)
      Returns a set of keys that satisfy the criteria expressed by the query.
      Parameters:
      sQuery - query used to filter cache entries
      Returns:
      a set of keys for entries that satisfy the specified criteria
    • instantiateEntryResource

      protected EntryResource instantiateEntryResource(NamedCache cache, Object oKey, Class clzValue)
      Create an instance of EntryResource for the specified resource configuration.
      Parameters:
      cache - cache in which referenced entry is stored
      oKey - referenced entry's key
      clzValue - class of the referenced entry's value
      Returns:
      a cache entry resource
    • instantiateEntrySetResource

      protected EntrySetResource instantiateEntrySetResource(NamedCache cache, Set setKeys, Class clzValue)
      Create an instance of EntrySetResource for the specified resource configuration.
      Parameters:
      cache - cache that stores the referenced entries
      setKeys - keys of the referenced entries
      clzValue - class of the referenced entries' values
      Returns:
      an entry set resource
    • instantiateNamedQueryResource

      public NamedQueryResource instantiateNamedQueryResource(NamedCache cache, NamedQuery query, int cMaxResults)
      Create an instance of NamedQueryResource for the specified resource configuration.
      Parameters:
      cache - cache to create a resource for
      query - query filtering the cache entries
      cMaxResults - max size of result set for this resource
      Returns:
      a named query resource