Package com.tangosol.coherence.rest
Class CacheResource
- java.lang.Object
-
- com.tangosol.coherence.rest.CacheResource
-
public class CacheResource extends Object
RESTful wrapper around a CoherenceNamedCache
.- Author:
- as 2011.06.03
-
-
Field Summary
Fields Modifier and Type Field Description protected AggregatorRegistry
m_aggregatorRegistry
Aggregator registry that is used to map the given aggregator name to an EntryAggregator instance.protected NamedCache
m_cache
NamedCache wrapped by this resource.protected Class
m_clzKey
Key class for the entries stored in the wrapped cache.protected Class
m_clzValue
Value class for the entries stored in the wrapped cache.protected int
m_cMaxResults
Size of the result set this resource is allowed to return.protected KeyConverter
m_keyConverter
Key converter.protected MarshallerRegistry
m_marshallerRegistry
Marshaller registry to obtain marshallers from.protected ProcessorRegistry
m_processorRegistry
a processor registry that is used to map the given processor name to an EntryProcessor instance.protected QueryConfig
m_queryConfig
Query configuration for this resource.protected QueryEngineRegistry
m_queryEngineRegistry
Query engine registry to obtain query engines from.protected org.glassfish.hk2.api.ServiceLocator
m_serviceLocator
The ServiceLocator for this resource.
-
Constructor Summary
Constructors Constructor Description CacheResource(NamedCache cache, Class clzKey, Class clzValue, KeyConverter keyConverter, QueryConfig queryConfig, int cMaxResults)
Construct a new CacheResource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.glassfish.jersey.media.sse.EventOutput
addListener(boolean fLite, String sQuery)
Register SSE event listener for this cache.javax.ws.rs.core.Response
aggregate(String sAggr, String sQuery)
Perform an aggregating operation against the entries that satisfy the specified criteria.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.javax.ws.rs.core.Response
getEntries(int nStart, int cResults, String sSort, PropertySet propertySet, String sQuery)
Return the cache entries that satisfy the given query criteria.Object
getEntryOrQueryResource(String sKey)
Return a REST sub-resource representing either a configured named query or a single cache entry.EntrySetResource
getEntrySetResource(String sKeys)
Return a REST sub-resource representing a set of cache entries.javax.ws.rs.core.Response
getKeys(String sQuery)
Return the keys of cache entries that satisfy the given query criteria.javax.ws.rs.core.Response
getValues(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 EntryResource
instantiateEntryResource(NamedCache cache, Object oKey, Class clzValue)
Create an instance ofEntryResource
for the specified resource configuration.protected EntrySetResource
instantiateEntrySetResource(NamedCache cache, Set setKeys, Class clzValue)
Create an instance ofEntrySetResource
for the specified resource configuration.NamedQueryResource
instantiateNamedQueryResource(NamedCache cache, NamedQuery query, int cMaxResults)
Create an instance ofNamedQueryResource
for the specified resource configuration.protected Set
keys(String sQuery)
Returns a set of keys that satisfy the criteria expressed by the query.javax.ws.rs.core.Response
process(String sProc, String sQuery)
Invoke the specified processor against the entries that satisfy the specified criteria.
-
-
-
Field Detail
-
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 Detail
-
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 Detail
-
getValues
@GET @Produces({"application/json","application/xml"}) public javax.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 javax.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 javax.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 javax.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 javax.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
@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 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
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 ofEntryResource
for 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 ofEntrySetResource
for 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 ofNamedQueryResource
for 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
-
-