Skip to content
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

add logic for replicating writes and reads to stores #20

Merged
merged 6 commits into from
Feb 8, 2013
Merged

add logic for replicating writes and reads to stores #20

merged 6 commits into from
Feb 8, 2013

Conversation

singhala
Copy link
Contributor

@singhala singhala commented Feb 8, 2013

No description provided.

/**
* Replicates writes to both stores, and uses the "or" logic defined on ReadableStore to replicate reads.
*/
def combinedWith(other: Store[Self, K, V]): Store[Self, K, V] = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we do this with a Seq[Store]?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a combine method to the companion object that does this with a seq, then have this method call Store.combine(Seq(this, other))

/**
* Replicates writes to all stores, and takes the first successful read.
*/
def replicate[Self <: Store[Self, K, V], K, V](stores: Seq[Store[Self, K, V]]): Store[Self, K, V] = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you do this, the trait returns don't need to change:

import Store.{selectFirstSuccessfulTrial => selectFirst}

class ReplicatedStore[StoreType <: Store[StoreType, K, V], K, V](stores: Seq[StoreType])
: Store[ReplicatedStore[StoreType, K V], K, V] = {
  override def get(k: K) = selectFirst(stores.map { _.get(k) })
  override def multiGet(ks: Set[K]) = selectFirst(stores.map { _.multiGet(ks) })
  override def update(k: K)(fn: Option[V] => Option[V]) =
    Future.collect(stores.map { _.update(k)(fn) }).map { new ReplicatedStore(_) }
  override def -(k: K) =
    Future.collect(stores.map { _ - k }).map { new ReplicatedStore(_) }
  override def +(pair: (K,V)) =
    Future.collect(stores.map { _ + pair }).map { new ReplicatedStore(_) }
}

sritchie added a commit that referenced this pull request Feb 8, 2013
add logic for replicating writes and reads to stores
@sritchie sritchie merged commit 853e476 into twitter:develop Feb 8, 2013
rubanm added a commit that referenced this pull request Dec 12, 2014
Merge from twitter/storehaus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants