add block interceptor

v4
laoyuyu 2 years ago
parent 80212ad810
commit 61d8989afd
  1. 9
      Http/src/main/java/com/arialyy/aria/http/download/HttpDTaskAdapter.kt
  2. 40
      HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGSubTaskInterceptor.kt
  3. 92
      HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGTaskManager.kt
  4. 22
      HttpGroup/src/main/java/com/arialyy/dua/group/HttpDGroupAdapter.kt
  5. 2
      PublicComponent/src/main/java/com/arialyy/aria/orm/DuaDb.kt

@ -26,6 +26,7 @@ import com.arialyy.aria.exception.AriaException
import com.arialyy.aria.http.HttpTaskOption
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber
/**
* @Author laoyuyu
@ -53,12 +54,20 @@ internal class HttpDTaskAdapter : AbsTaskAdapter() {
}
override fun cancel() {
if (getTaskManager().isCanceled()) {
Timber.w("task already canceled, taskId: ${getTask().taskId}")
return
}
DuaContext.duaScope.launch(Dispatchers.IO) {
ThreadTaskManager2.stopThreadTask(getTask().taskId, true)
}
}
override fun stop() {
if (getTaskManager().isStopped()) {
Timber.w("task already stopped, taskId: ${getTask().taskId}")
return
}
DuaContext.duaScope.launch(Dispatchers.IO) {
ThreadTaskManager2.stopThreadTask(getTask().taskId)
}

@ -0,0 +1,40 @@
/*
* 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.dua.group
import com.arialyy.aria.core.DuaContext
import com.arialyy.aria.core.task.ITaskInterceptor
import com.arialyy.aria.core.task.TaskChain
import com.arialyy.aria.core.task.TaskResp
/**
* @Author laoyuyu
* @Description
* @Date 7:27 PM 2023/3/8
**/
internal class HttpDGSubTaskInterceptor : ITaskInterceptor {
private val dgDao by lazy {
DuaContext.getServiceManager().getDbService().getDuaDb().getDGEntityDao()
}
override suspend fun interceptor(chain: TaskChain): TaskResp {
}
private suspend fun checkRecord() {
// dgDao.
}
}

@ -0,0 +1,92 @@
/*
* 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.dua.group
import android.os.Handler
import android.os.Looper
import com.arialyy.aria.core.inf.ITaskManager
import com.arialyy.aria.http.HttpTaskOption
/**
* @Author laoyuyu
* @Description
* @Date 7:43 PM 2023/3/7
**/
internal class HttpDGTaskManager : ITaskManager {
private lateinit var looper: Looper
private lateinit var handler: Handler
private val callback = Handler.Callback { msg ->
when (msg.what) {
ITaskManager.STATE_STOP -> {
}
ITaskManager.STATE_CANCEL -> {
}
ITaskManager.STATE_FAIL -> {
}
ITaskManager.STATE_COMPLETE -> {
}
ITaskManager.STATE_RUNNING -> {
}
ITaskManager.STATE_UPDATE_PROGRESS -> {
}
}
false
}
fun start(taskOption: HttpTaskOption) {
taskOption.getOptionAdapter(HttpDGOptionAdapter::class.java).subUrl
}
override fun setLooper() {
if (Looper.myLooper() == Looper.getMainLooper()) {
throw IllegalThreadStateException("io operations cannot be in the main thread")
}
looper = Looper.myLooper()!!
handler = Handler(looper, callback)
}
override fun stop() {
}
override fun isCompleted(): Boolean {
TODO("Not yet implemented")
}
override fun getCurrentProgress(): Long {
TODO("Not yet implemented")
}
override fun isStopped(): Boolean {
TODO("Not yet implemented")
}
override fun isCanceled(): Boolean {
TODO("Not yet implemented")
}
override fun isRunning(): Boolean {
TODO("Not yet implemented")
}
override fun getHandler(): Handler {
return handler
}
override fun hasFailedTask(): Boolean {
TODO("Not yet implemented")
}
}

@ -28,6 +28,7 @@ import com.arialyy.aria.http.download.HttpDCheckInterceptor
import com.arialyy.aria.http.download.TimerInterceptor
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import timber.log.Timber
/**
* @Author laoyuyu
@ -35,6 +36,9 @@ import kotlinx.coroutines.launch
* @Date 21:58 2023/2/20
**/
internal class HttpDGroupAdapter : AbsTaskAdapter() {
private val taskManager by lazy {
HttpDGTaskManager()
}
init {
getTask().getTaskOption(HttpTaskOption::class.java).eventListener =
@ -42,19 +46,25 @@ internal class HttpDGroupAdapter : AbsTaskAdapter() {
}
override fun getTaskManager(): ITaskManager {
TODO("Not yet implemented")
return taskManager
}
override fun isRunning(): Boolean {
TODO("Not yet implemented")
return taskManager.isRunning()
}
override fun cancel() {
TODO("Not yet implemented")
if (getTaskManager().isCanceled()) {
Timber.w("task already canceled, taskId: ${getTask().taskId}")
return
}
}
override fun stop() {
TODO("Not yet implemented")
if (getTaskManager().isStopped()) {
Timber.w("task already stopped, taskId: ${getTask().taskId}")
return
}
}
override fun start() {
@ -65,7 +75,7 @@ internal class HttpDGroupAdapter : AbsTaskAdapter() {
}
DuaContext.duaScope.launch(Dispatchers.IO) {
Looper.prepare()
blockManager?.setLooper()
taskManager.setLooper()
addCoreInterceptor(HttpDCheckInterceptor())
addCoreInterceptor(TimerInterceptor())
addCoreInterceptor(HttpBlockThreadInterceptor())
@ -75,7 +85,7 @@ internal class HttpDGroupAdapter : AbsTaskAdapter() {
false,
AriaException("start task fail, task interrupt, code: ${resp?.code ?: TaskResp.CODE_INTERRUPT}")
)
blockManager?.stop()
taskManager.stop()
return@launch
}
Looper.loop()

@ -30,7 +30,7 @@ import com.arialyy.aria.orm.entity.TaskRecord
import com.arialyy.aria.orm.entity.UEntity
@Database(
entities = [DbEntity::class, UEntity::class, DGEntity::class, MEntity::class, MKeyInfo::class, TaskRecord::class, BlockRecord::class],
entities = [UEntity::class, DGEntity::class, MEntity::class, MKeyInfo::class, TaskRecord::class, BlockRecord::class],
version = 1
)
abstract class DuaDb : RoomDatabase() {

Loading…
Cancel
Save