Class 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
    • 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 a Work instance 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. The Work instance 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 of Work can be used to wait on the request, manage the request, get results, etc.

        Parameters:
        work - The SubmittableWork instance 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 (see SubmittableWork.getId() and Request.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.