|
From: Gerry D. <gd...@us...> - 2002-06-17 23:53:22
|
Update of /cvsroot/swapdv/swapdv/Download
In directory usw-pr-cvs1:/tmp/cvs-serv17412/Download
Modified Files:
DownloadCounter.java
Log Message:
Exposed download and throttle controls for entire server.
Aded per-remote device preference in store and added per-device preference
editor.
Allowed download/throttle controls to be adjusted on a per device basis
Index: DownloadCounter.java
===================================================================
RCS file: /cvsroot/swapdv/swapdv/Download/DownloadCounter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DownloadCounter.java 7 Jun 2002 22:12:45 -0000 1.5
+++ DownloadCounter.java 17 Jun 2002 23:53:19 -0000 1.6
@@ -42,8 +42,7 @@
public class DownloadCounter {
private static DownloadCounter counter = null;
- private int maxPerDevice = 2;
- private int maxTotal = 9;
+ private int defaultMaxPerDevice = 2;
private int pendingDownloads = 0;
private Hashtable downloadDevices = new Hashtable();
@@ -57,43 +56,66 @@
public static void setProperties(pStoreNodeI config) {
DownloadCounter theCounter = getCounter();
- theCounter.maxTotal = config.getIntAttribute("maxDownloadsTotal", theCounter.maxTotal);
- theCounter.maxPerDevice = config.getIntAttribute("maxDownloadsPerDevice", theCounter.maxPerDevice);
+ DownloadDevice.setMaxTotalDownloads(config.getIntAttribute("maxDownloadsTotal", 9));
+ theCounter.defaultMaxPerDevice = config.getIntAttribute("defaultMaxDownloadsPerDevice", 2);
}
public static void getProperties(pStoreNodeI config) {
DownloadCounter theCounter = getCounter();
- config.setAttribute("maxDownloadsTotal", theCounter.maxTotal);
- config.setAttribute("maxDownloadsPerDevice", theCounter.maxPerDevice);
+ config.setAttribute("maxDownloadsTotal", DownloadDevice.getMaxTotalDownloads());
+ config.setAttribute("defaultMaxDownloadsPerDevice", theCounter.defaultMaxPerDevice);
}
- public void setPerDeviceDownloadLimit(int newLimit) {
+ /**
+ * Set the default maximim number of downloads for new devices. This is a
+ * default and as soon as the device has been downloaded once, it no longer
+ * affects that unit - only new ones
+ **/
+ public void setDefaultPerDeviceDownloadLimit(int newLimit) {
if (newLimit <= 0) return;
-
- synchronized(downloadDevices) {
- maxPerDevice = newLimit;
-
- Enumeration theDevices = downloadDevices.elements();
- while (theDevices.hasMoreElements()) {
- ((DownloadDevice) theDevices.nextElement()).maxPerDevice = newLimit;
- }
- }
+ defaultMaxPerDevice = newLimit;
}
- public int getPerDeviceDownloadLimit() { return maxPerDevice; }
+ public int getDefaultPerDeviceDownloadLimit() { return defaultMaxPerDevice; }
+
+ /**
+ * Set the maximum number of downloads that SwapDV will allow at any one time
+ **/
public void setTotalDownloadLimit(int newLimit) {
if (newLimit <= 0) return;
+ DownloadDevice.setMaxTotalDownloads(newLimit);
+ }
+ public int getTotalDownloadLimit() { return DownloadDevice.getMaxTotalDownloads(); }
+
+ public void setDownloadLimit(String theDeviceIP, int theLimit) {
+ if (theLimit <= 0) return;
+
+ DownloadDevice ipDevice = null;
- synchronized(downloadDevices) {
- maxTotal = newLimit;
+ synchronized(downloadDevices) {
+ // Get/create download tracker for each device
+ if ((ipDevice = (DownloadDevice) downloadDevices.get(theDeviceIP)) == null) {
+ ipDevice = new DownloadDevice(theDeviceIP, defaultMaxPerDevice);
+ downloadDevices.put(theDeviceIP, ipDevice);
+ }
- Enumeration theDevices = downloadDevices.elements();
- while (theDevices.hasMoreElements()) {
- ((DownloadDevice) theDevices.nextElement()).maxTotal = newLimit;
+ ipDevice.setDownloadLimit(theLimit);
+ }
+ }
+
+ public int getDownloadLimit(String theDeviceIP) {
+ DownloadDevice ipDevice = null;
+
+ synchronized(downloadDevices) {
+ // Get/create download tracker for each device
+ if ((ipDevice = (DownloadDevice) downloadDevices.get(theDeviceIP)) == null) {
+ return defaultMaxPerDevice;
}
+
+ return ipDevice.getDownloadLimit();
}
}
- public int getTotalDownloadLimit() { return maxTotal; }
+
/* returns true if the thread was not interrupted */
public boolean incCount(String IP) {
@@ -102,7 +124,7 @@
synchronized(downloadDevices) {
// Get/create download tracker for each device
if ((ipDevice = (DownloadDevice) downloadDevices.get(IP)) == null) {
- ipDevice = new DownloadDevice(IP, maxPerDevice, maxTotal);
+ ipDevice = new DownloadDevice(IP, defaultMaxPerDevice);
downloadDevices.put(IP, ipDevice);
}
@@ -131,29 +153,46 @@
}
class DownloadDevice {
- public static int totalDownloads = 0;
+ private static int maxTotalDownloads = 0;
+ private static int totalCurrentDownloads = 0;
public String theIP = null;
public int downloadCount = 0;
public Vector curThreads = new Vector();
+ private pStoreNodeI deviceInfo = null;
+ private int maxForDevice = 0;
+
- public int maxPerDevice = 0;
- public int maxTotal = 0;
+ public static void setMaxTotalDownloads(int newLimit) {
+ maxTotalDownloads = newLimit;
+ }
+ public static int getMaxTotalDownloads() { return maxTotalDownloads; }
+
- public DownloadDevice(String newIP, int maxDevice, int maxTotal) {
+ public DownloadDevice(String newIP, int defaultMaxDownloads) {
theIP = newIP;
- this.maxPerDevice = maxDevice;
- this.maxTotal = maxTotal;
+ deviceInfo = swapdv.SwapDV.getSwapDV().getDeviceStore(theIP);
+ maxForDevice = deviceInfo.getIntAttribute("MAX_DOWNLOADS", defaultMaxDownloads);
}
+ public void setDownloadLimit(int newLimit) {
+ if (newLimit <= 0) return;
+ maxForDevice = newLimit;
+ deviceInfo.setAttribute("MAX_DOWNLOADS", maxForDevice);
+ }
+ public int getDownloadLimit() { return maxForDevice; }
+
+ public int getCurrentDownloads() { return downloadCount; }
+
+
// Attempt to increment the download count. If the count is below
// the max OR this downloader is already downloading (duplicate call),
// then TRUE is returned. Otherwise, if there are no slots, FALSE
// is returned.
public boolean incUsage(Thread theThread) {
synchronized(curThreads) {
- // Bomb out if we maxed out this unit
- if (totalDownloads >= maxTotal) return false;
+ // Bomb out if we maxed out
+ if (totalCurrentDownloads >= maxTotalDownloads) return false;
// See if we are already listed
int threadCount = curThreads.size();
@@ -162,11 +201,11 @@
}
// If not, see if there are any open limits
- if (downloadCount >= maxPerDevice) return false;
+ if (downloadCount >= maxForDevice) return false;
// Add us in and we are on our way
downloadCount++;
- totalDownloads++;
+ totalCurrentDownloads++;
curThreads.add(theThread);
return true;
}
@@ -192,8 +231,10 @@
// Remove us and decrement the counter
curThreads.remove(theThread);
downloadCount--;
- totalDownloads--;
+ totalCurrentDownloads--;
return true;
}
}
+
+
}
|