Class QueueManagerBase<T,​R>

  • Type Parameters:
    T - Task Type
    R - Task Return Type

    public abstract class QueueManagerBase<T,​R>
    extends Object
    This class manages the download-slots. It contains also the counters and restrictions for domains. So this class allows a Pic to download or let them wait until a slot is free.
    • Field Detail

      • logger

        protected org.slf4j.Logger logger
        Logger
      • syncObject

        protected final Object syncObject
        Synchronization Object
      • queue

        protected final List<T> queue
        Queue
      • queueTaskFactory

        protected final QueueTaskFactory<T,​R> queueTaskFactory
        Queue Task Factory
      • executingTasks

        protected final List<QueueTask<T,​R>> executingTasks
        Tasks which are currently executing
      • checkScheduleTasks

        protected boolean checkScheduleTasks
        Flag for indicating that it should be checked if any tasks from the queue can be executed
      • schedulerThread

        protected Thread schedulerThread
        Scheduler Thread
      • queueCompletionThread

        protected Thread queueCompletionThread
        Queue Completion Thread
      • maxConnectionCount

        protected int maxConnectionCount
        Maximum connection count
      • maxConnectionCountPerHost

        protected int maxConnectionCountPerHost
        Maximum connection count per host
      • sessionFiles

        protected int sessionFiles
        Files since application started
      • sessionBytes

        protected long sessionBytes
        Bytes since application started
      • openSlots

        protected int openSlots
        Open Slots
      • stop

        protected boolean stop
        Stop Flag
    • Constructor Detail

      • QueueManagerBase

        public QueueManagerBase​(QueueTaskFactory<T,​R> queueTaskFactory,
                                int maxConnectionCount,
                                int maxConnectionCountPerHost)
        Constructor
        Parameters:
        queueTaskFactory - Queue Task Factory
        maxConnectionCount - Max Connection Count
        maxConnectionCountPerHost - Max Connection Count per Host
    • Method Detail

      • init

        public void init()
        Initialize
      • stop

        public void stop()
        Stop
      • cancelTasks

        public void cancelTasks​(boolean cancelAlreadyExecutingTasks)
        Stop tasks. Clears the queue and cancels are executing tasks
        Parameters:
        cancelAlreadyExecutingTasks - Flag if already running tasks should be cancelled
      • getMaxConnectionCount

        public int getMaxConnectionCount()
        Returns the maxConnectionCount
        Returns:
        maxConnectionCount
      • getMaxConnectionCountPerHost

        public int getMaxConnectionCountPerHost()
        Returns the maxConnectionCountPerHost
        Returns:
        maxConnectionCountPerHost
      • setMaxConnectionCount

        public void setMaxConnectionCount​(int maxConnectionCount)
        Sets the maxConnectionCount
        Parameters:
        maxConnectionCount - maxConnectionCount
      • applyMaxConnectionCount

        protected void applyMaxConnectionCount()
        Apply Max Connection Count
      • setMaxConnectionCountPerHost

        public void setMaxConnectionCountPerHost​(int maxConnectionCountPerHost)
        Sets the maxConnectionCountPerHost
        Parameters:
        maxConnectionCountPerHost - maxConnectionCountPerHost
      • getSessionFiles

        public int getSessionFiles()
        Returns the sessionFiles
        Returns:
        sessionFiles
      • increaseSessionFiles

        public void increaseSessionFiles()
        Increases the session files since application started by 1
      • getSessionBytes

        public long getSessionBytes()
        Returns the sessionBytes
        Returns:
        sessionBytes
      • increaseSessionBytes

        public void increaseSessionBytes​(long bytes)
        Increases the bytes since application started
        Parameters:
        bytes - Bytes
      • getQueueSize

        public int getQueueSize()
        Returns:
        Queue size
      • getTaskCount

        public int getTaskCount()
        Returns:
        Count of currently executing tasks
      • isExecutingTasks

        public boolean isExecutingTasks()
        Returns:
        True if tasks are executing, false otherwise
      • updateOpenSlots

        protected void updateOpenSlots​(boolean taskFinished)
        Update Open Slots
        Parameters:
        taskFinished - Flag if slots are updated, because a task was finished
      • getOpenSlots

        public int getOpenSlots()
        Returns:
        Open slots
      • addTaskToQueue

        public void addTaskToQueue​(T task)
        Add task to queue
        Parameters:
        task - Task
      • addTasksToQueue

        public void addTasksToQueue​(List<T> tasks)
        Add tasks to queue
        Parameters:
        tasks - Tasks
      • removedTaskFromQueue

        protected abstract void removedTaskFromQueue​(T task,
                                                     boolean executeFailure)
        Called when a task was removed from the queue, when the queue was stopped or when a task could not be scheduled for execution
        Parameters:
        task - Task
        executeFailure - True if task could not be scheduled for execution, false otherwise
      • addTaskToExecutingTasks

        protected void addTaskToExecutingTasks​(QueueTask<T,​R> task)
        Parameters:
        task - Task
      • cancelTaskCallables

        protected void cancelTaskCallables​(boolean interruptTaskIfRunning)
        Cancel executing tasks
        Parameters:
        interruptTaskIfRunning - True if running tasks should be interrupted, false otherwise
      • removeTaskCallables

        protected void removeTaskCallables()
        Remove Task Callables
      • removeTaskCallable

        protected void removeTaskCallable​(Future<R> future)
        Remove Task Callables
        Parameters:
        future - Future
      • completedTaskCallable

        protected abstract void completedTaskCallable​(QueueTask<T,​R> task)
        Called when a task completed, failed or was cancelled
        Parameters:
        task - Task
      • getRestrictionForTask

        protected abstract Restriction getRestrictionForTask​(T task)
        Restriction for task
        Parameters:
        task - Task
        Returns:
        Restriction for task
      • getRestrictedCount

        protected int getRestrictedCount​(String restrictionKey)
        Parameters:
        restrictionKey - Restriction Key
        Returns:
        Current Restricted Count
      • getMaxConnectionCount

        protected int getMaxConnectionCount​(T task)
        Get maximum connection count for task
        Parameters:
        task - Task
        Returns:
        Maximum connection count for task