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 onFailure to EnrichedMergeableStore #200

Merged
merged 4 commits into from
Jan 13, 2014

Conversation

singhala
Copy link
Contributor

No description provided.

@@ -49,4 +49,17 @@ class EnrichedMergeableStore[K, V](store: MergeableStore[K, V]) {

def convert[K1, V1](fn: K1 => K)(implicit bij: ImplicitBijection[V1, V]): MergeableStore[K1, V1] =
MergeableStore.convert(store)(fn)

def onFailure(rescueException: Throwable => Unit): MergeableStore[K, V] = new MergeableStore[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.

can we rename "onMergeFailure"+

@johnynek
Copy link
Collaborator

Can you change this (should be less code) to use the proxy pattern in #202 ?

@johnynek
Copy link
Collaborator

for instance, close was not plumbed through here.

@softprops
Copy link
Contributor

yea. that's the reason it's useful. All delegation is handled for you so you don't forget things. Like closing a network connection cleanly!

you could probably do

def onMergeFailure(rescueException: Throwable => Unit): MergeableStore[K, V] =
  new MergeableStoreProxy(store) {
    override def merge(kv: (K, V)) = self.merge(kv).onFailure(rescueException)
    override def multiMerge[K1 <: K](kvs: Map[K1, V]) =
      self.multiMerge(kvs).mapValues { _.onFailure(rescueException) }
  }

shorter and safer

@johnynek
Copy link
Collaborator

johnynek commented Jan 4, 2014

@singhala ? Any update? Can we talk you into using the pattern above?

@johnynek
Copy link
Collaborator

ping

@singhala
Copy link
Contributor Author

Sorry I lost track of this while on vacation. Yes, I'll update this diff with the new pattern later today.

johnynek added a commit that referenced this pull request Jan 13, 2014
add onFailure to EnrichedMergeableStore
@johnynek johnynek merged commit abb5d32 into twitter:develop Jan 13, 2014
override def self = store
override def merge(kv: (K, V)) = store.merge(kv).onFailure(rescueException)
override def multiMerge[K1 <: K](kvs: Map[K1, V]) =
store.multiMerge(kvs).mapValues { _.onFailure(rescueException) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

mapValues is lazy. This is not being applied if any keys are not accessed.

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