de.scheisseichfindemalkeinen.queue
Class QueueData

java.lang.Object
  extended by de.scheisseichfindemalkeinen.queue.QueueData
All Implemented Interfaces:
ISettingsListener

public class QueueData
extends java.lang.Object
implements ISettingsListener

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.

See Also:
QueueCounter, Restriction

Method Summary
 void addCounter(QueueCounter counter)
          Adds a counter If there is already a counter for a domain, the counter is not added.
 void addDLSlotListener(IDownloadListener l)
          Requests a download slot
 void addQueueDataListener(IQueueDataListener l)
          Adds a listener
 void addRestriction(Restriction restriction)
          Adds a restriction If there is already a restriction for a domain the restriction is not added.
 int getConnectionCount()
          Returns the maximum connection count
 int getOpenDownloadSlots()
          Returns the open download slots
 int getQueueSize()
          Returns the count of listeners which requested a download slot
 long getSessionDownloadedBytes()
          Returns the downloaded bytes since application started
 int getSessionDownloadedFiles()
          Returns the downloaded files since application started
 void increaseSessionDownloadedBytes(long downloadedBytes)
          Increases the downloaded bytes since application started by downloadedBytes So QueueData will take the actual value and add downloadedBytes.
 void increaseSessionDownloadedFiles()
          Increases the downloaded files since application started by 1 This method will fire the sessionDownloadedFilesChanged-Method on all listeners.
static QueueData instance()
          Returns the singleton
 boolean isDLSlotListenerRegistered(IDownloadListener l)
          Returns if the listener is already registered
 boolean isDownloading()
          Returns if downloads are running or not
 void manageDLSlots()
          This method allows a Pic to start the download It checks the restrictions an counters and all needed things.
 void removeDLSlotListener(IDownloadListener l)
          Gives the download-slot back to the queue This method must be used if the Pic has not the status Pic.WAITING.
 void removeDLSlotListenerStopping(IDownloadListener l)
          Gives the download-slot back to the queue This method is only for a Pic with the status of Pic.WAITING.
 void removeQueueDataListener(IQueueDataListener l)
          Removes a listener
 void removeRestriction(Restriction restriction)
          Removes a restriction
 void setConnectionCount(int count)
          Sets the maximum connection count
 void settingsChanged()
          This method is fired when settings had changed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

instance

public static QueueData instance()
Returns the singleton

Returns:
Instance

setConnectionCount

public void setConnectionCount(int count)
Sets the maximum connection count

Parameters:
count - Maximmum connection count

getConnectionCount

public int getConnectionCount()
Returns the maximum connection count

Returns:
Maximmum connection count

getOpenDownloadSlots

public int getOpenDownloadSlots()
Returns the open download slots

Returns:
Open download slots

getQueueSize

public int getQueueSize()
Returns the count of listeners which requested a download slot

Returns:
Queue size

addQueueDataListener

public void addQueueDataListener(IQueueDataListener l)
Adds a listener

Parameters:
l - Listener

removeQueueDataListener

public void removeQueueDataListener(IQueueDataListener l)
Removes a listener

Parameters:
l - Listener

manageDLSlots

public void manageDLSlots()
This method allows a Pic to start the download It checks the restrictions an counters and all needed things. This method is fired always when a download slot was give back to the queue and when a download slot is requested and the queue was empty before.


addDLSlotListener

public void addDLSlotListener(IDownloadListener l)
Requests a download slot

Parameters:
l - Listener

removeDLSlotListener

public void removeDLSlotListener(IDownloadListener l)
Gives the download-slot back to the queue This method must be used if the Pic has not the status Pic.WAITING. This method fires queueChanged on all listeners

Parameters:
l - Listener

removeDLSlotListenerStopping

public void removeDLSlotListenerStopping(IDownloadListener l)
Gives the download-slot back to the queue This method is only for a Pic with the status of Pic.WAITING. Because there is no download slot for a waiting pic, so the things done in removeDLSlotListener-Method are not needed in this case.

Parameters:
l - Listener

isDLSlotListenerRegistered

public boolean isDLSlotListenerRegistered(IDownloadListener l)
Returns if the listener is already registered

Parameters:
l - Listener
Returns:
True if the listener is already registered

isDownloading

public boolean isDownloading()
Returns if downloads are running or not

Returns:
True if downloads are running

settingsChanged

public void settingsChanged()
Description copied from interface: ISettingsListener
This method is fired when settings had changed

Specified by:
settingsChanged in interface ISettingsListener

getSessionDownloadedFiles

public int getSessionDownloadedFiles()
Returns the downloaded files since application started

Returns:
Downloaded files

getSessionDownloadedBytes

public long getSessionDownloadedBytes()
Returns the downloaded bytes since application started

Returns:
Downloaded bytes

increaseSessionDownloadedFiles

public void increaseSessionDownloadedFiles()
Increases the downloaded files since application started by 1 This method will fire the sessionDownloadedFilesChanged-Method on all listeners.


increaseSessionDownloadedBytes

public void increaseSessionDownloadedBytes(long downloadedBytes)
Increases the downloaded bytes since application started by downloadedBytes So QueueData will take the actual value and add downloadedBytes. This method will fire the sessionDownloadedBytesChanged-Method on all listeners.

Parameters:
downloadedBytes - Downloaded bytes

addRestriction

public void addRestriction(Restriction restriction)
Adds a restriction If there is already a restriction for a domain the restriction is not added. But the value of maximum simultanious downloads from the restriction to add is taken and set to the existing restriction. So this method can be used to update a restriction

Parameters:
restriction - Restriction

removeRestriction

public void removeRestriction(Restriction restriction)
Removes a restriction

Parameters:
restriction - Restriction

addCounter

public void addCounter(QueueCounter counter)
Adds a counter If there is already a counter for a domain, the counter is not added.

Parameters:
counter - QueueCounter