parent
e0c9b0c373
commit
344cbd2d99
@ -0,0 +1,25 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.arialyy.aria.http |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author laoyuyu |
||||||
|
* @Description |
||||||
|
* @Date 21:14 PM 2023/3/13 |
||||||
|
**/ |
||||||
|
data class SubState( |
||||||
|
val subId: Int |
||||||
|
) |
@ -0,0 +1,57 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package com.arialyy.aria.http.download |
||||||
|
|
||||||
|
import com.arialyy.aria.core.task.DBlockManager |
||||||
|
import com.arialyy.aria.core.task.ITask |
||||||
|
import com.arialyy.aria.http.HttpTaskOption |
||||||
|
import kotlinx.coroutines.launch |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author laoyuyu |
||||||
|
* @Description |
||||||
|
* @Date 21:45 2023/3/13 |
||||||
|
**/ |
||||||
|
class HttpDBlockManager(task: ITask) : DBlockManager(task) { |
||||||
|
private val optionAdapter = |
||||||
|
task.getTaskOption(HttpTaskOption::class.java).getOptionAdapter(HttpDOptionAdapter::class.java) |
||||||
|
|
||||||
|
override fun start() { |
||||||
|
optionAdapter.threadList.forEach { tt -> |
||||||
|
scope.launch(dispatcher) { |
||||||
|
tt.run() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun stop() { |
||||||
|
optionAdapter.threadList.forEach { |
||||||
|
it.stop() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun cancel() { |
||||||
|
optionAdapter.threadList.forEach { |
||||||
|
it.cancel() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun quitLooper() { |
||||||
|
super.quitLooper() |
||||||
|
optionAdapter.threadList.clear() |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,81 +1,81 @@ |
|||||||
/* |
///* |
||||||
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) |
// * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) |
||||||
* |
// * |
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
// * Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
* you may not use this file except in compliance with the License. |
// * you may not use this file except in compliance with the License. |
||||||
* You may obtain a copy of the License at |
// * You may obtain a copy of the License at |
||||||
* |
// * |
||||||
* http://www.apache.org/licenses/LICENSE-2.0 |
// * http://www.apache.org/licenses/LICENSE-2.0 |
||||||
* |
// * |
||||||
* Unless required by applicable law or agreed to in writing, software |
// * Unless required by applicable law or agreed to in writing, software |
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
// * distributed under the License is distributed on an "AS IS" BASIS, |
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
* See the License for the specific language governing permissions and |
// * See the License for the specific language governing permissions and |
||||||
* limitations under the License. |
// * limitations under the License. |
||||||
*/ |
// */ |
||||||
package com.arialyy.aria.http.upload |
//package com.arialyy.aria.http.upload |
||||||
|
// |
||||||
import android.os.Looper |
//import android.os.Looper |
||||||
import com.arialyy.aria.core.DuaContext |
//import com.arialyy.aria.core.DuaContext |
||||||
import com.arialyy.aria.core.inf.ITaskManager |
//import com.arialyy.aria.core.inf.ITaskManager |
||||||
import com.arialyy.aria.core.task.AbsTaskAdapter |
//import com.arialyy.aria.core.task.AbsTaskAdapter |
||||||
import com.arialyy.aria.core.task.DBlockManager |
//import com.arialyy.aria.core.task.DBlockManager |
||||||
import com.arialyy.aria.core.task.TaskResp |
//import com.arialyy.aria.core.task.TaskResp |
||||||
import com.arialyy.aria.exception.AriaException |
//import com.arialyy.aria.exception.AriaException |
||||||
import com.arialyy.aria.http.HttpTaskOption |
//import com.arialyy.aria.http.HttpTaskOption |
||||||
import com.arialyy.aria.http.download.HttpBlockThreadInterceptor |
//import com.arialyy.aria.http.download.HttpBlockThreadInterceptor |
||||||
import com.arialyy.aria.http.download.TimerInterceptor |
//import com.arialyy.aria.http.download.TimerInterceptor |
||||||
import kotlinx.coroutines.Dispatchers |
//import kotlinx.coroutines.Dispatchers |
||||||
import kotlinx.coroutines.launch |
//import kotlinx.coroutines.launch |
||||||
|
// |
||||||
/** |
///** |
||||||
* @Author laoyuyu |
// * @Author laoyuyu |
||||||
* @Description |
// * @Description |
||||||
* @Date 9:21 PM 2023/2/21 |
// * @Date 9:21 PM 2023/2/21 |
||||||
**/ |
// **/ |
||||||
class HttpUTaskAdapter : AbsTaskAdapter() { |
//class HttpUTaskAdapter : AbsTaskAdapter() { |
||||||
private var blockManager: DBlockManager? = null |
// private var blockManager: DBlockManager? = null |
||||||
|
// |
||||||
override fun getBlockManager(): ITaskManager { |
// override fun getBlockManager(): ITaskManager { |
||||||
if (blockManager == null) { |
// if (blockManager == null) { |
||||||
blockManager = DBlockManager(getTask()) |
// blockManager = DBlockManager(getTask()) |
||||||
} |
// } |
||||||
return blockManager!! |
// return blockManager!! |
||||||
} |
// } |
||||||
|
// |
||||||
override fun isRunning(): Boolean { |
// override fun isRunning(): Boolean { |
||||||
return blockManager?.isRunning ?: false |
// return blockManager?.isRunning ?: false |
||||||
} |
// } |
||||||
|
// |
||||||
override fun cancel() { |
// override fun cancel() { |
||||||
TODO("Not yet implemented") |
// TODO("Not yet implemented") |
||||||
} |
// } |
||||||
|
// |
||||||
override fun stop() { |
// override fun stop() { |
||||||
TODO("Not yet implemented") |
// TODO("Not yet implemented") |
||||||
} |
// } |
||||||
|
// |
||||||
override fun start() { |
// override fun start() { |
||||||
getTask().getTaskOption(HttpTaskOption::class.java).taskInterceptor.let { |
// getTask().getTaskOption(HttpTaskOption::class.java).taskInterceptor.let { |
||||||
if (it.isNotEmpty()) { |
// if (it.isNotEmpty()) { |
||||||
addInterceptors(it) |
// addInterceptors(it) |
||||||
} |
// } |
||||||
} |
// } |
||||||
DuaContext.duaScope.launch(Dispatchers.IO) { |
// DuaContext.duaScope.launch(Dispatchers.IO) { |
||||||
Looper.prepare() |
// Looper.prepare() |
||||||
addCoreInterceptor(TimerInterceptor()) |
// addCoreInterceptor(TimerInterceptor()) |
||||||
addCoreInterceptor(HttpUBlockInterceptor()) |
// addCoreInterceptor(HttpUBlockInterceptor()) |
||||||
addCoreInterceptor(HttpBlockThreadInterceptor()) |
// addCoreInterceptor(HttpBlockThreadInterceptor()) |
||||||
val resp = interceptor() |
// val resp = interceptor() |
||||||
if (resp == null || resp.code != TaskResp.CODE_SUCCESS) { |
// if (resp == null || resp.code != TaskResp.CODE_SUCCESS) { |
||||||
getTask().getTaskOption(HttpTaskOption::class.java).eventListener.onFail( |
// getTask().getTaskOption(HttpTaskOption::class.java).eventListener.onFail( |
||||||
false, |
// false, |
||||||
AriaException("start task fail, task interrupt, code: ${resp?.code ?: TaskResp.CODE_INTERRUPT}") |
// AriaException("start task fail, task interrupt, code: ${resp?.code ?: TaskResp.CODE_INTERRUPT}") |
||||||
) |
// ) |
||||||
blockManager?.stop() |
// blockManager?.stop() |
||||||
return@launch |
// return@launch |
||||||
} |
// } |
||||||
Looper.loop() |
// Looper.loop() |
||||||
} |
// } |
||||||
} |
// } |
||||||
} |
//} |
Loading…
Reference in new issue