|
32 | 32 | @SuppressWarnings("WeakerAccess") |
33 | 33 | public class FileDownloadMessageStation { |
34 | 34 |
|
35 | | - private final Executor blockCompletedPool = FileDownloadExecutors. |
| 35 | + private static final Executor BLOCK_COMPLETED_POOL = FileDownloadExecutors. |
36 | 36 | newDefaultThreadPool(5, "BlockCompleted"); |
37 | 37 |
|
38 | 38 | private final Handler handler; |
@@ -63,13 +63,7 @@ void requestEnqueue(final IFileDownloadMessenger messenger, |
63 | 63 | return; |
64 | 64 | } |
65 | 65 |
|
66 | | - if (messenger.isBlockingCompleted()) { |
67 | | - blockCompletedPool.execute(new Runnable() { |
68 | | - @Override |
69 | | - public void run() { |
70 | | - messenger.handoverMessage(); |
71 | | - } |
72 | | - }); |
| 66 | + if (interceptBlockCompleteMessage(messenger)) { |
73 | 67 | return; |
74 | 68 | } |
75 | 69 |
|
@@ -102,6 +96,25 @@ private void handoverInUIThread(IFileDownloadMessenger messenger) { |
102 | 96 | handler.sendMessage(handler.obtainMessage(HANDOVER_A_MESSENGER, messenger)); |
103 | 97 | } |
104 | 98 |
|
| 99 | + /** |
| 100 | + * @param messenger {@link com.liulishuo.filedownloader.IFileDownloadMessenger} |
| 101 | + * @return true if the messenger is a block complete messenger and handle it through |
| 102 | + * {@linkplain FileDownloadMessageStation#BLOCK_COMPLETED_POOL} in the meantime. |
| 103 | + */ |
| 104 | + private static boolean interceptBlockCompleteMessage(final IFileDownloadMessenger messenger) { |
| 105 | + if (messenger.isBlockingCompleted()) { |
| 106 | + BLOCK_COMPLETED_POOL.execute(new Runnable() { |
| 107 | + @Override |
| 108 | + public void run() { |
| 109 | + messenger.handoverMessage(); |
| 110 | + } |
| 111 | + }); |
| 112 | + return true; |
| 113 | + } else { |
| 114 | + return false; |
| 115 | + } |
| 116 | + } |
| 117 | + |
105 | 118 | private final Object queueLock = new Object(); |
106 | 119 |
|
107 | 120 | private void enqueue(final IFileDownloadMessenger messenger) { |
@@ -166,6 +179,9 @@ public boolean handleMessage(Message msg) { |
166 | 179 | private void dispose(final ArrayList<IFileDownloadMessenger> disposingList) { |
167 | 180 | // dispose Sub-package-size each time. |
168 | 181 | for (IFileDownloadMessenger iFileDownloadMessenger : disposingList) { |
| 182 | + if (interceptBlockCompleteMessage(iFileDownloadMessenger)) { |
| 183 | + continue; |
| 184 | + } |
169 | 185 | iFileDownloadMessenger.handoverMessage(); |
170 | 186 | } |
171 | 187 |
|
|
0 commit comments