Package com.tangosol.coherence.rest
Class CacheResource
java.lang.Object
com.tangosol.coherence.rest.CacheResource
RESTful wrapper around a Coherence
NamedCache.- Author:
- as 2011.06.03
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AggregatorRegistryAggregator registry that is used to map the given aggregator name to an EntryAggregator instance.protected NamedCacheNamedCache wrapped by this resource.protected ClassKey class for the entries stored in the wrapped cache.protected ClassValue class for the entries stored in the wrapped cache.protected intSize of the result set this resource is allowed to return.protected KeyConverterKey converter.protected MarshallerRegistryMarshaller registry to obtain marshallers from.protected ProcessorRegistrya processor registry that is used to map the given processor name to an EntryProcessor instance.protected QueryConfigQuery configuration for this resource.protected QueryEngineRegistryQuery engine registry to obtain query engines from.protected org.glassfish.hk2.api.ServiceLocatorThe ServiceLocator for this resource. -
Constructor Summary
ConstructorsConstructorDescriptionCacheResource(NamedCache cache, Class clzKey, Class clzValue, KeyConverter keyConverter, QueryConfig queryConfig, int cMaxResults) Construct a new CacheResource. -
Method Summary
Modifier and TypeMethodDescriptionorg.glassfish.jersey.media.sse.EventOutputaddListener(boolean fLite, String sQuery) Register SSE event listener for this cache.jakarta.ws.rs.core.ResponsePerform an aggregating operation against the entries that satisfy the specified criteria.protected CollectionexecuteQuery(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.jakarta.ws.rs.core.ResponsegetEntries(int nStart, int cResults, String sSort, PropertySet propertySet, String sQuery) Return the cache entries that satisfy the given query criteria.Return a REST sub-resource representing either a configured named query or a single cache entry.getEntrySetResource(String sKeys) Return a REST sub-resource representing a set of cache entries.jakarta.ws.rs.core.ResponseReturn the keys of cache entries that satisfy the given query criteria.jakarta.ws.rs.core.ResponsegetValues(int nStart, int cResults, String sSort, PropertySet propertySet, String sQuery) Return the cache values (or a subset of their properties) that satisfy the specified criteria.protected EntryResourceinstantiateEntryResource(NamedCache cache, Object oKey, Class clzValue) Create an instance ofEntryResourcefor the specified resource configuration.protected EntrySetResourceinstantiateEntrySetResource(NamedCache cache, Set setKeys, Class clzValue) Create an instance ofEntrySetResourcefor the specified resource configuration.instantiateNamedQueryResource(NamedCache cache, NamedQuery query, int cMaxResults) Create an instance ofNamedQueryResourcefor the specified resource configuration.protected SetReturns a set of keys that satisfy the criteria expressed by the query.jakarta.ws.rs.core.ResponseInvoke the specified processor against the entries that satisfy the specified criteria.
-
Field Details
-
m_cache
NamedCache wrapped by this resource. -
m_clzKey
Key class for the entries stored in the wrapped cache. -
m_clzValue
Value class for the entries stored in the wrapped cache. -
m_keyConverter
Key converter. -
m_cMaxResults
protected int m_cMaxResultsSize of the result set this resource is allowed to return. -
m_marshallerRegistry
Marshaller registry to obtain marshallers from. -
m_queryConfig
Query configuration for this resource. -
m_queryEngineRegistry
Query engine registry to obtain query engines from. -
m_aggregatorRegistry
Aggregator registry that is used to map the given aggregator name to an EntryAggregator instance. -
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_serviceLocatorThe 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 forclzKey- key class of the cached entriesclzValue- value class of the cached entrieskeyConverter- key converter to usequeryConfig- query configuration for this resourcecMaxResults- 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 returnedcResults- size of result set to be returned (page size)sSort- a string expression that represents orderingpropertySet- 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 returnedcResults- size of result set to be returned (page size)sSort- a string expression that represents orderingpropertySet- 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 aggregatorsQuery- 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 processorsQuery- 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 eventssQuery- an optional CohQL filter to register listener on- Returns:
- the EventOutput that will be used to send events to the client
-
getEntryOrQueryResource
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 setnStart- the starting index of result set to be returnedcResults- 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
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
Create an instance ofEntryResourcefor the specified resource configuration.- Parameters:
cache- cache in which referenced entry is storedoKey- referenced entry's keyclzValue- 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 ofEntrySetResourcefor the specified resource configuration.- Parameters:
cache- cache that stores the referenced entriessetKeys- keys of the referenced entriesclzValue- class of the referenced entries' values- Returns:
- an entry set resource
-
instantiateNamedQueryResource
public NamedQueryResource instantiateNamedQueryResource(NamedCache cache, NamedQuery query, int cMaxResults) Create an instance ofNamedQueryResourcefor the specified resource configuration.- Parameters:
cache- cache to create a resource forquery- query filtering the cache entriescMaxResults- max size of result set for this resource- Returns:
- a named query resource
-