Skip to content

Commit

Permalink
lifting the request executor to its own file in the network package
Browse files Browse the repository at this point in the history
- also creates a dedicated RequestModule instead of providing the executor via the pushers module
  • Loading branch information
ouchadam committed Oct 1, 2021
1 parent 2693a34 commit e82de2b
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2021 The Matrix.org Foundation C.I.C.
*
* 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 org.matrix.android.sdk.internal.network
import org.matrix.android.sdk.internal.network.executeRequest as internalExecuteRequest

internal interface RequestExecutor {
suspend fun <DATA> executeRequest(globalErrorReceiver: GlobalErrorReceiver?,
canRetry: Boolean = false,
maxDelayBeforeRetry: Long = 32_000L,
maxRetriesCount: Int = 4,
requestBlock: suspend () -> DATA): DATA
}

internal object DefaultRequestExecutor : RequestExecutor {
override suspend fun <DATA> executeRequest(globalErrorReceiver: GlobalErrorReceiver?,
canRetry: Boolean,
maxDelayBeforeRetry: Long,
maxRetriesCount: Int,
requestBlock: suspend () -> DATA): DATA {
return internalExecuteRequest(globalErrorReceiver, canRetry, maxDelayBeforeRetry, maxRetriesCount, requestBlock)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2021 The Matrix.org Foundation C.I.C.
*
* 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 org.matrix.android.sdk.internal.network

import dagger.Module
import dagger.Provides

@Module
internal object RequestModule {

@Provides
fun providesRequestExecutor(): RequestExecutor {
return DefaultRequestExecutor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.matrix.android.sdk.internal.crypto.verification.SendVerificationMessa
import org.matrix.android.sdk.internal.di.MatrixComponent
import org.matrix.android.sdk.internal.federation.FederationModule
import org.matrix.android.sdk.internal.network.NetworkConnectivityChecker
import org.matrix.android.sdk.internal.network.RequestModule
import org.matrix.android.sdk.internal.session.account.AccountModule
import org.matrix.android.sdk.internal.session.cache.CacheModule
import org.matrix.android.sdk.internal.session.call.CallModule
Expand Down Expand Up @@ -95,7 +96,8 @@ import org.matrix.android.sdk.internal.util.system.SystemModule
CallModule::class,
SearchModule::class,
ThirdPartyModule::class,
SpaceModule::class
SpaceModule::class,
RequestModule::class
]
)
@SessionScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.matrix.android.sdk.internal.database.model.PusherEntity
import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.network.RequestExecutor
import org.matrix.android.sdk.internal.task.Task
import org.matrix.android.sdk.internal.util.awaitTransaction
import javax.inject.Inject
Expand Down Expand Up @@ -75,21 +76,3 @@ internal class DefaultAddPusherTask @Inject constructor(
}
}
}

internal interface RequestExecutor {
suspend fun <DATA> executeRequest(globalErrorReceiver: GlobalErrorReceiver?,
canRetry: Boolean = false,
maxDelayBeforeRetry: Long = 32_000L,
maxRetriesCount: Int = 4,
requestBlock: suspend () -> DATA): DATA
}

internal object DefaultRequestExecutor : RequestExecutor {
override suspend fun <DATA> executeRequest(globalErrorReceiver: GlobalErrorReceiver?,
canRetry: Boolean,
maxDelayBeforeRetry: Long,
maxRetriesCount: Int,
requestBlock: suspend () -> DATA): DATA {
return executeRequest(globalErrorReceiver, canRetry, maxDelayBeforeRetry, maxRetriesCount, requestBlock)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ internal abstract class PushersModule {
fun providesPushRulesApi(retrofit: Retrofit): PushRulesApi {
return retrofit.create(PushRulesApi::class.java)
}

@Provides
@JvmStatic
fun providesRequestExecutor(): RequestExecutor {
return DefaultRequestExecutor
}
}

@Binds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.matrix.android.sdk.test.fakes

import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
import org.matrix.android.sdk.internal.session.pushers.RequestExecutor
import org.matrix.android.sdk.internal.network.RequestExecutor

internal class FakeRequestExecutor : RequestExecutor {

Expand Down

0 comments on commit e82de2b

Please sign in to comment.