Package net.toddm.comm
Class CommManager
- java.lang.Object
-
- net.toddm.comm.CommManager
-
public final class CommManager extends Object
This is the main work horse of the communications framework. Instances of this class are used to submit work and provide priority queue management, result caching, failure and response based retry, and much more.- Author:
- Todd S. Murchison
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCommManager.BuilderThis is a factory class used for configuring and then creating instances ofCommManager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel(int workId, boolean interruptAllowed)Cancels work with the given ID if found, otherwise no-op.WorkenqueueWork(URI uri, Request.RequestMethod method, byte[] postData, Map<String,String> headers, boolean isIdempotent, Priority.StartingPriority requestPriority, net.toddm.cache.CachePriority cachingPriority, CacheBehavior cachingBehavior)Enters a request into the communications framework for processing.WorkenqueueWork(SubmittableWork work)Enters a request into the communications framework for processing.SubmittableWorkgetWork(URI uri, Request.RequestMethod method, byte[] postData, Map<String,String> headers, boolean isIdempotent, Priority.StartingPriority requestPriority, net.toddm.cache.CachePriority cachingPriority, CacheBehavior cachingBehavior)Creates and returns aWorkinstance representing the request described by the provided data.voidinvalidateCache(int workId)If a cache entry exists for the given work ID it's TTL is updated to 0 making the entry stale.voidpurgeCache()Deletes ALL response cache entries.voidpurgeCache(int workId)If a cache entry exists for the given work ID it is deleted.
-
-
-
Method Detail
-
getWork
public SubmittableWork getWork(URI uri, Request.RequestMethod method, byte[] postData, Map<String,String> headers, boolean isIdempotent, Priority.StartingPriority requestPriority, net.toddm.cache.CachePriority cachingPriority, CacheBehavior cachingBehavior)
Creates and returns aWorkinstance representing the request described by the provided data. The Work instance returned has not been submitted for processing and no work will be done for it. To start processing the Work instance, submit it to- Parameters:
uri- The URI of the request to work on.method- The HTTP method of the request to work on.postData- [OPTIONAL] Can be NULL. The POST data of the request to work on.headers- [OPTIONAL] Can be NULL. The request headers of the request to work on.isIdempotent- A flag indicating if this request is considered to be an idempotent request. Retry policy provider implementations will often not want to retry non-idempotent requests on error.requestPriority- The priority of this request work relative to other request work.cachingPriority- A hint to the caching provider (if there is one) of the relative priority of the cache entry generated for this response.cachingBehavior- Indicates what caching behavior should be used for the results of the enqueued work.
-
enqueueWork
public Work enqueueWork(URI uri, Request.RequestMethod method, byte[] postData, Map<String,String> headers, boolean isIdempotent, Priority.StartingPriority requestPriority, net.toddm.cache.CachePriority cachingPriority, CacheBehavior cachingBehavior)
Enters a request into the communications framework for processing. TheWorkinstance returned can be used to wait on the request, manage the request, get results, etc.- Parameters:
uri- The URI of the request to work on.method- The HTTP method of the request to work on.postData- [OPTIONAL] Can be NULL. The POST data of the request to work on.headers- [OPTIONAL] Can be NULL. The request headers of the request to work on.isIdempotent- A flag indicating if this request is considered to be an idempotent request. Retry policy provider implementations will often not want to retry non-idempotent requests on error.requestPriority- The priority of this request work relative to other request work.cachingPriority- A hint to the caching provider (if there is one) of the relative priority of the cache entry generated for this response.cachingBehavior- Indicates what caching behavior should be used for the results of the enqueued work.
-
enqueueWork
public Work enqueueWork(SubmittableWork work)
Enters a request into the communications framework for processing. The returned instance ofWorkcan be used to wait on the request, manage the request, get results, etc.- Parameters:
work- TheSubmittableWorkinstance describing the request to process.
-
cancel
public void cancel(int workId, boolean interruptAllowed)Cancels work with the given ID if found, otherwise no-op.- Parameters:
workId- The ID of the work to cancel (seeSubmittableWork.getId()andRequest.getId()).interruptAllowed- A flag indicating if thread interrupts are allowed while attempting to cancel work.
-
invalidateCache
public void invalidateCache(int workId)
If a cache entry exists for the given work ID it's TTL is updated to 0 making the entry stale.
-
purgeCache
public void purgeCache(int workId)
If a cache entry exists for the given work ID it is deleted.
-
purgeCache
public void purgeCache()
Deletes ALL response cache entries. Use carefully and wisely.
-
-