com.pubnub.internal.endpoints.DelegatingRemoteAction.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pubnub-gson-impl Show documentation
Show all versions of pubnub-gson-impl Show documentation
PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter second!
package com.pubnub.internal.endpoints
import com.pubnub.api.PubNubException
import com.pubnub.api.endpoints.remoteaction.ExtendedRemoteAction
import com.pubnub.api.enums.PNOperationType
import com.pubnub.api.v2.callbacks.Result
import com.pubnub.internal.PubNubCore
import org.jetbrains.annotations.TestOnly
import java.util.function.Consumer
abstract class DelegatingRemoteAction(
@JvmField protected val pubnub: PubNubCore,
) : ExtendedRemoteAction {
@get:TestOnly
internal open val remoteAction: ExtendedRemoteAction by lazy {
mapResult(createAction())
}
protected abstract fun createAction(): ExtendedRemoteAction
protected abstract fun mapResult(action: ExtendedRemoteAction): ExtendedRemoteAction
@Throws(PubNubException::class)
override fun sync(): T {
validateParams()
return remoteAction.sync()
}
@Throws(PubNubException::class)
protected open fun validateParams() {
}
override fun async(callback: Consumer>) {
try {
validateParams()
} catch (pubnubException: PubNubException) {
callback.accept(Result.failure(pubnubException))
return
}
remoteAction.async(callback)
}
override fun retry() {
remoteAction.retry()
}
override fun silentCancel() {
remoteAction.silentCancel()
}
override fun operationType(): PNOperationType {
return remoteAction.operationType()
}
val operationType: PNOperationType
get() = operationType()
}
abstract class IdentityMappingAction(pubnub: PubNubCore) : DelegatingRemoteAction(pubnub) {
final override fun mapResult(action: ExtendedRemoteAction): ExtendedRemoteAction {
return action
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy