1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.transfer;
21
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24
25 import org.apache.log4j.Logger;
26
27 /***
28 * This class acts as data container for {@link Upload} objects.
29 *
30 * <p>The class makes use of the singleton pattern.</p>
31 */
32 public class UploadManager extends AbstractTransferManager
33 implements PropertyChangeListener
34 {
35
36
37
38
39
40 private static UploadManager singleton = new UploadManager();
41
42
43
44 private UploadManager()
45 {
46 logger = Logger.getLogger(UploadManager.class);
47
48 prefs.addPropertyChangeListener("limitUploads", this);
49 prefs.addPropertyChangeListener("maxUploads", this);
50 prefs.addPropertyChangeListener("autoClearTransfers", this);
51 prefs.addPropertyChangeListener("autoClearTransfersInterval", this);
52
53 updateLimit();
54 }
55
56
57
58 public static UploadManager getInstance()
59 {
60 return singleton;
61 }
62
63 public synchronized void add(Upload d)
64 {
65 super.add(d);
66 }
67
68 public void propertyChange(PropertyChangeEvent e)
69 {
70 updateLimit();
71 }
72
73 public synchronized void remove(Upload d)
74 {
75 super.remove(d);
76 }
77
78 private void updateLimit()
79 {
80 getQueue().setMaxSlots(prefs.getLimitUploads()
81 ? prefs.getMaxUploads()
82 : Integer.MAX_VALUE);
83 setAutoClearInterval(prefs.getAutoClearTransfers()
84 ? prefs.getAutoClearTransfersInterval()
85 : -1);
86 }
87
88 }