Skip to content

[네트워크 모듈 개선 v2] 네트워크 쓰레드 제어 #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c436d5b
feat: gitignore 정리
sieunju Nov 22, 2023
64757b4
refactor: Network V2 리펙토링
sieunju Nov 22, 2023
374a682
refactor: Network V2 리펙토링
sieunju Nov 22, 2023
da6462f
refactor: Network V2 리펙토링
sieunju Nov 22, 2023
8b7102d
refactor: Network V2 리펙토링
sieunju Nov 23, 2023
f9edf4e
refactor: Network V2 리펙토링
sieunju Nov 23, 2023
535fc77
refactor: Network V2 리펙토링
sieunju Nov 23, 2023
b5aa6e1
refactor: Network V2 리펙토링
sieunju Nov 23, 2023
6418988
refactor: Network V2 리펙토링
sieunju Nov 23, 2023
f8b11ee
refactor: Network V2 리펙토링
sieunju Nov 24, 2023
5ab224b
refactor: Network V2 리펙토링
sieunju Nov 24, 2023
e9a850e
refactor: Network V2 리펙토링
sieunju Nov 25, 2023
65c33e3
refactor: Network V2 리펙토링
sieunju Nov 26, 2023
a01ed27
refactor: Network V2 리펙토링
sieunju Nov 26, 2023
84080f9
refactor: Network V2 리펙토링
sieunju Nov 27, 2023
4762424
refactor: Network V2 리펙토링
sieunju Nov 27, 2023
4936872
fix: 테스트 모듈에 network-v2 모듈 추가
sieunju Nov 28, 2023
f422c84
chore: 네트워크 테스트 코드 추가
sieunju Nov 30, 2023
5e3156b
chore: 쓰레드 제어 클래스 로직 정리 및 오타 수정
sieunju Nov 30, 2023
5b16175
chore: 쓰레드 제어 클래스 로직 정리 및 오타 수정
sieunju Nov 30, 2023
03125bb
docs: 앱 모듈화 그래프 이미지 업데이트
sieunju Nov 30, 2023
68dfc95
feat: 테스트용 API 추가
sieunju Nov 30, 2023
b8fa8d7
refactor: HTTP 통신 쓰레드 제어 모듈화 처리
sieunju Nov 30, 2023
fb6a08c
test: 테스트 예제 추가
sieunju Nov 30, 2023
ecacd29
chore: 네트워크 모듈 수정
sieunju Dec 2, 2023
fd22e89
chore: 성능 테스트를 위한 코드 수정
sieunju Dec 2, 2023
f21e298
chore: 성능 테스트를 위한 코드 수정
sieunju Dec 2, 2023
bad75f6
chore: 네트워크 JWT 토큰 개선
sieunju Dec 2, 2023
df56276
chore: 네트워크 개선 v2
sieunju Dec 3, 2023
accf676
feat: 네트워크 개선 v2
sieunju Dec 3, 2023
710643e
chore: ktlint style 적용
sieunju Dec 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 59 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,61 @@
# Built application files
*.apk
*.ap_

# Files for the Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# User-specific configurations
.idea/
.idea/libraries/
.idea/workspace.xml
.idea/tasks.xml
.idea/.name
.idea/compiler.xml
.idea/copyright/profiles_settings.xml
.idea/encodings.xml
.idea/misc.xml
.idea/modules.xml
.idea/scopes/scope_settings.xml
.idea/vcs.xml
.idea/caches/
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml

# OS-specific files
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
/.idea
/.gradle
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

app/release/output.json

detekt/detekt.**
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17.0.8
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ dependencies {
implementation(project(":features:base-mvvm"))
implementation(project(":features:async_migrate"))
implementation(project(":features:async_migrate_bridge"))
implementation(project(":features:network_v2"))
implementation(project(":features:network_v2-bridge"))

/**
* Network
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/hmju/til/MainApplication.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.hmju.til

import android.app.Application
import com.http.tracking.TrackingManager
import dagger.hilt.android.HiltAndroidApp
import hmju.http.tracking.HttpTracking
import io.reactivex.rxjava3.exceptions.UndeliverableException
import io.reactivex.rxjava3.plugins.RxJavaPlugins
import timber.log.Timber
Expand Down Expand Up @@ -85,9 +85,10 @@ open class MainApplication : Application() {
}

private fun initTracking() {
TrackingManager.getInstance()
HttpTracking.Builder()
.setBuildType(true)
.setWifiShare(true)
.setLogMaxSize(10_000)
.build(this)
}
}
14 changes: 8 additions & 6 deletions appRelease/release_note.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Build Date 2023년 07월 12일 수요일 13:53:38
Version Name: 0.0.5
Branch: develop
Build Date 2023년 12월 03일 일요일 10:13:10
Version Name: 0.0.6
Branch: feature/refactor_network

Message: commit ff91368b76f29aa698d7c74f5242f2fb3748af84
Update generate-release-note.yml
Message: commit df562762cd1ce4b2d4bcb7664c9979f139174ee3
chore: 네트워크 개선 v2
- 테스트 했던 Delay 들 줄임

Author: Sieun Ju

Author: sieunju
Binary file added assets/okhttp_struct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/projectGraph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed buildSrc/build/classes/kotlin/main/AndroidX.class
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/Apps.class
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/Co.class
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/Glide.class
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/Hilt.class
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/HttpTracking.class
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/Javax.class
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/Kotlin.class
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/KotlinX.class
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/Log.class
Binary file not shown.
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/Retrofit.class
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/Rx.class
Binary file not shown.
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/UnitTest$Hilt.class
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/UnitTest.class
Binary file not shown.
Binary file removed buildSrc/build/classes/kotlin/main/Versions.class
Binary file not shown.
1 change: 0 additions & 1 deletion buildSrc/build/kotlin/buildSrcjar-classes.txt

This file was deleted.

Binary file removed buildSrc/build/kotlin/compileKotlin/build-history.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed buildSrc/build/kotlin/compileKotlin/last-build.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed buildSrc/build/libs/buildSrc.jar
Binary file not shown.

This file was deleted.

8 changes: 0 additions & 8 deletions buildSrc/build/source-roots/buildSrc/source-roots.txt

This file was deleted.

2 changes: 0 additions & 2 deletions buildSrc/build/tmp/jar/MANIFEST.MF

This file was deleted.

4 changes: 2 additions & 2 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ object Log {
}

object HttpTracking {
const val interceptor = "com.github.sieunju.httptracking:interceptor:1.2.3"
const val ui = "com.github.sieunju.httptracking:ui:1.2.3"
const val interceptor = "com.github.sieunju.httptracking:interceptor:1.3.2"
const val ui = "com.github.sieunju.httptracking:ui:1.3.2"
}

object UnitTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.reactivex.rxjava3.core.Single
interface LoginManager {
fun setToken(token: String)
fun getToken(): String
fun isLogin() : Boolean
fun rxIsLogin() : Single<Boolean>
fun isLogin(): Boolean
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

fun rxIsLogin(): Single<Boolean>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

fun getTokenExpiredMs(): Long
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

}
48 changes: 30 additions & 18 deletions core/src/main/java/com/hmju/core/login_manager/LoginManagerImpl.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.hmju.core.login_manager

import android.content.Context
import android.content.SharedPreferences
import android.util.Base64
import androidx.core.content.edit
import com.hmju.core.pref.PreferenceManager
import com.hmju.core.rxbus.LoginEvent
import com.hmju.core.rxbus.RxBus
import dagger.hilt.android.qualifiers.ApplicationContext
import io.reactivex.rxjava3.core.Single
import org.json.JSONObject
import javax.inject.Inject
import kotlin.random.Random

Expand All @@ -15,33 +16,40 @@ import kotlin.random.Random
* Created by juhongmin on 2022/01/12
*/
class LoginManagerImpl @Inject constructor(
@ApplicationContext private val context: Context
private val prefManager: PreferenceManager
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

) : LoginManager {

private val pref: SharedPreferences =
context.getSharedPreferences("til_pref", Context.MODE_PRIVATE)
private var expiredMs: Long = 0
private var userToken: String = ""

companion object {
const val KEY_TOKEN = "user_token"
const val KEY_NICK_NAME = "user_nick_name"
private fun getTokenExpiredMs(token: String): Long {
return try {
val startIdx = token.indexOf(".")
val endIdx = token.lastIndexOf(".")
val bytes = Base64.decode(token.substring(startIdx, endIdx), Base64.DEFAULT)
val json = JSONObject(String(bytes, Charsets.UTF_8))
json.getLong("exp") * 1000
} catch (ex: Exception) {
System.currentTimeMillis()
}
}

private var userToken: String = ""

@Synchronized
override fun setToken(token: String) {
with(pref.edit()) {
putString(KEY_TOKEN, token)
apply()
// Test
RxBus.publish(LoginEvent(Random.nextBoolean(), token))
// 토큰 전처리 가공
prefManager.getPref().edit {
expiredMs = getTokenExpiredMs(token)
userToken = token
putLong(PreferenceManager.KEY_TOKEN_EXPIRED_MS, expiredMs)
putString(PreferenceManager.KEY_TOKEN, userToken)
}

userToken = token
RxBus.publish(LoginEvent(Random.nextBoolean(), token))
}

override fun getToken(): String {
if (userToken.isEmpty()) {
userToken = pref.getString(KEY_TOKEN, "") ?: ""
userToken = prefManager.getString(PreferenceManager.KEY_TOKEN)
}
return userToken
}
Expand All @@ -53,4 +61,8 @@ class LoginManagerImpl @Inject constructor(
override fun rxIsLogin(): Single<Boolean> {
return Single.just(getToken().isNotEmpty())
}

override fun getTokenExpiredMs(): Long {
return expiredMs
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.hmju.core.login_manager.di

import com.hmju.core.login_manager.LoginManager
import com.hmju.core.login_manager.LoginManagerImpl
import com.hmju.core.pref.di.PreferenceManagerModule
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -14,9 +15,9 @@ import javax.inject.Singleton
* Created by juhongmin on 2022/01/12
*/
@InstallIn(SingletonComponent::class)
@Module
@Module(includes = [PreferenceManagerModule::class])
internal abstract class LoginManagerModule {
@Singleton
@Binds
abstract fun bindLoginManager(loginManager: LoginManagerImpl): LoginManager
abstract fun bindLoginManager(impl: LoginManagerImpl): LoginManager
}
23 changes: 4 additions & 19 deletions core/src/main/java/com/hmju/core/model/base/ApiResponse.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.hmju.core.model.base

import okhttp3.ResponseBody
import com.hmju.core.model.error.JSendException

/**
* Description : Coroutines Network Base Response
Expand All @@ -9,29 +9,14 @@ import okhttp3.ResponseBody
*/
sealed class ApiResponse<out T> {

enum class FailType {
NETWORK, HTTP, UN_KNOWN
}

/**
* Network Success Response Data
*/
data class Success<out T>(val data: T) : ApiResponse<T>()

/**
* Network Fail Data Model
* @see FailType.HTTP HTTP Error
* @see FailType.NETWORK Network Config Error
* @see FailType.UN_KNOWN UN KNOWN
*
* @param type FailType
* @param msg Error Message
* @param errBody when [FailType.HTTP] Error Body
* Network Fail
* @param err Error
*/
data class Fail(
val type: FailType,
val msg: CharSequence,
val err: Throwable? = null,
val errBody: ResponseBody? = null
) : ApiResponse<Nothing>()
data class Fail(val err: JSendException) : ApiResponse<Nothing>()
}
2 changes: 2 additions & 0 deletions core/src/main/java/com/hmju/core/model/base/BaseJSend.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ open class BaseJSend {

@SerialName("message")
val message: String? = null

open val isValid : Boolean = false
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶
Unexpected spacing before ":"

}
16 changes: 14 additions & 2 deletions core/src/main/java/com/hmju/core/model/base/JSendList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ package com.hmju.core.model.base
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-consecutive-blank-lines reported by reviewdog 🐶
Needless blank line(s)

/**
* Description : JSend JSON
* {
* "status" : true or false,
* "message" : String (에러인경우 사용자에게 표시하는 에러 메시지),
* "data" : {
* "payload" : []
* }
* }
*
* Created by juhongmin on 09/01/22
*/
@Serializable
data class JSendList<T : Any>(
@SerialName("data")
Expand All @@ -14,8 +27,7 @@ data class JSendList<T : Any>(
val list: List<T> = listOf()
)

val isValid: Boolean
get() = depthData != null
override val isValid: Boolean get() = depthData != null

val payload: List<T>
get() = depthData?.list ?: listOf()
Expand Down
15 changes: 12 additions & 3 deletions core/src/main/java/com/hmju/core/model/base/JSendListWithMeta.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Description : 한 데이터 모델 한에 실제 데이터를 받기 위한 데이터 모델
* Description : JSend JSON
* {
* "status" : true or false,
* "message" : String (에러인경우 사용자에게 표시하는 에러 메시지),
* "data" : {
* "payload" : [],
* "meta" : {
* "pageSize" : Integer
* }
* }
* }
*
* Created by juhongmin on 2022/05/15
*/
Expand All @@ -21,8 +31,7 @@ data class JSendListWithMeta<T : Any, M : MetaEntity>(
val meta: M? = null
)

val isValid: Boolean
get() = depthData != null
override val isValid: Boolean get() = depthData != null

val payload: List<T>
get() = depthData?.list ?: listOf()
Expand Down
Loading