Skip to content

Commit

Permalink
Refactor from ConcurrentOperationManager to OperationPipeline
Browse files Browse the repository at this point in the history
Signed-off-by: matt-ramotar <[email protected]>
  • Loading branch information
matt-ramotar committed Jul 21, 2024
1 parent 2431a7e commit b37a2ce
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 143 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.mobilenativefoundation.storex.paging.runtime.internal.pagingScope.imp

interface PagingScope<ItemId : Any, PageRequestKey : Any, ItemValue : Any> {
fun getPager(): Pager<ItemId, PageRequestKey, ItemValue>
fun getOperationManager(): OperationManager<ItemId, PageRequestKey, ItemValue>
fun getDispatcher(): Dispatcher<ItemId, PageRequestKey, ItemValue>
fun getUpdatingItemProvider(): UpdatingItemProvider<ItemId, ItemValue>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import kotlinx.coroutines.sync.withLock
import org.mobilenativefoundation.storex.paging.runtime.FetchingState
import org.mobilenativefoundation.storex.paging.runtime.ItemSnapshotList
import org.mobilenativefoundation.storex.paging.runtime.Operation
import org.mobilenativefoundation.storex.paging.runtime.OperationManager
import org.mobilenativefoundation.storex.paging.runtime.OperationPipeline
import org.mobilenativefoundation.storex.paging.runtime.PagingState
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.MutableOperationPipeline
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.OperationApplier

/**
Expand All @@ -21,8 +20,7 @@ import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.Opera
* @param ItemValue The type of the item value.
*/
class ConcurrentOperationApplier<ItemId : Any, PageRequestKey : Any, ItemValue : Any>(
private val operationManager: OperationManager<ItemId, PageRequestKey, ItemValue>,
private val mutableOperationPipeline: MutableOperationPipeline<ItemId, PageRequestKey, ItemValue>
private val operationPipeline: OperationPipeline<ItemId, PageRequestKey, ItemValue>
) : OperationApplier<ItemId, PageRequestKey, ItemValue> {

// Mutex for ensuring thread-safe access to shared resources
Expand All @@ -49,7 +47,7 @@ class ConcurrentOperationApplier<ItemId : Any, PageRequestKey : Any, ItemValue :
pagingState: PagingState<ItemId, PageRequestKey, ItemValue>,
fetchingState: FetchingState<ItemId, PageRequestKey>
): ItemSnapshotList<ItemId, ItemValue> = mutex.withLock {
operationManager.get().fold(snapshot) { acc, operation ->
operationPipeline.fold(snapshot) { acc, operation ->
if (operation.shouldApply(key, pagingState, fetchingState)) {
val cacheKey = CacheKey(operation, acc, key, pagingState, fetchingState)
operationCache.getOrPut(cacheKey) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.mobilenativefoundation.storex.paging.runtime.internal.logger.api.Pagi
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.FetchingStateHolder
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.LoadParamsQueue
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.LoadingHandler
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.MutableOperationPipeline
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.PagingStateManager
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.QueueManager
import org.mobilenativefoundation.storex.paging.runtime.internal.store.api.NormalizedStore
Expand All @@ -46,6 +47,7 @@ internal class RealPager<ItemId : Any, PageRequestKey : Any, ItemValue : Any>(
private val queueManager: QueueManager<PageRequestKey>,
private val loadingHandler: LoadingHandler<ItemId, PageRequestKey, ItemValue>,
private val coroutineScope: CoroutineScope,
private val mutableOperationPipeline: MutableOperationPipeline<ItemId, PageRequestKey, ItemValue>
) : Pager<ItemId, PageRequestKey, ItemValue> {

init {
Expand Down Expand Up @@ -143,9 +145,9 @@ internal class RealPager<ItemId : Any, PageRequestKey : Any, ItemValue : Any>(
is Action.Enqueue -> handleEnqueueAction(action)
Action.Invalidate -> handleInvalidateAction()

is Action.AddOperation -> TODO()
Action.ClearOperations -> TODO()
is Action.RemoveOperation -> TODO()
is Action.AddOperation -> mutableOperationPipeline.add(action.operation)
Action.ClearOperations -> mutableOperationPipeline.clear()
is Action.RemoveOperation -> mutableOperationPipeline.remove(action.operation)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.Fetch
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.LinkedHashMapManager
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.ListSortAnalyzer
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.LoadingHandler
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.MutableOperationPipeline
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.OperationApplier
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.PagingStateManager
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.api.QueueManager
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.impl.ConcurrentFetchingStateHolder
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.impl.ConcurrentOperationApplier
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.impl.ConcurrentOperationManager
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.impl.DefaultFetchingStrategy
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.impl.DefaultListSortAnalyzer
import org.mobilenativefoundation.storex.paging.runtime.internal.pager.impl.RealLinkedHashMapManager
Expand Down Expand Up @@ -136,7 +134,6 @@ class PagingScopeBuilder<ItemId : Any, PageRequestKey : Any, ItemValue : Any>(
}

override fun build(): PagingScope<ItemId, PageRequestKey, ItemValue> {
val operationManager = ConcurrentOperationManager<ItemId, PageRequestKey, ItemValue>()
val fetchingStateHolder = ConcurrentFetchingStateHolder(initialFetchingState, itemIdComparator, pageRequestKeyComparator)

val dataPersistence = RealDataPersistence(itemPersistence, pagePersistence)
Expand All @@ -162,7 +159,7 @@ class PagingScopeBuilder<ItemId : Any, PageRequestKey : Any, ItemValue : Any>(
val pagingStateManager = RealPagingStateManager(initialState, logger)
val queueManager = RealQueueManager(logger, pageRequestKeyComparator)
val mutableOperationPipeline = RealMutableOperationPipeline(initialOperations)
val operationApplier = ConcurrentOperationApplier(operationManager, mutableOperationPipeline)
val operationApplier = ConcurrentOperationApplier(mutableOperationPipeline)
val loadingHandler = createLoadingHandler(
store = store,
pagingStateManager = pagingStateManager,
Expand All @@ -184,12 +181,12 @@ class PagingScopeBuilder<ItemId : Any, PageRequestKey : Any, ItemValue : Any>(
pagingStateManager = pagingStateManager,
queueManager = queueManager,
loadingHandler = loadingHandler,
coroutineScope = coroutineScope
coroutineScope = coroutineScope,
mutableOperationPipeline = mutableOperationPipeline
)

return RealPagingScope(
pager = pager,
operationManager = operationManager,
dispatcher = dispatcher,
updatingItemProvider = updatingItemProvider
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
package org.mobilenativefoundation.storex.paging.runtime.internal.pagingScope.impl

import org.mobilenativefoundation.storex.paging.runtime.Dispatcher
import org.mobilenativefoundation.storex.paging.runtime.OperationManager
import org.mobilenativefoundation.storex.paging.runtime.Pager
import org.mobilenativefoundation.storex.paging.runtime.PagingScope
import org.mobilenativefoundation.storex.paging.runtime.UpdatingItemProvider

class RealPagingScope<ItemId : Any, PageRequestKey : Any, ItemValue : Any>(
private val pager: Pager<ItemId, PageRequestKey, ItemValue>,
private val operationManager: OperationManager<ItemId, PageRequestKey, ItemValue>,
private val dispatcher: Dispatcher<ItemId, PageRequestKey, ItemValue>,
private val updatingItemProvider: UpdatingItemProvider<ItemId, ItemValue>
) : PagingScope<ItemId, PageRequestKey, ItemValue> {
override fun getPager(): Pager<ItemId, PageRequestKey, ItemValue> {
return pager
}

override fun getOperationManager(): OperationManager<ItemId, PageRequestKey, ItemValue> {
return operationManager
}

override fun getDispatcher(): Dispatcher<ItemId, PageRequestKey, ItemValue> {
return dispatcher
}
Expand Down

0 comments on commit b37a2ce

Please sign in to comment.