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

Reporting store algebra's #176

Merged
merged 6 commits into from
Mar 12, 2014
Merged

Reporting store algebra's #176

merged 6 commits into from
Mar 12, 2014

Conversation

ianoc
Copy link
Collaborator

@ianoc ianoc commented Nov 6, 2013

No description provided.


package com.twitter.storehaus.algebra.reporting

import com.twitter.algebird.Monoid
Copy link
Collaborator

Choose a reason for hiding this comment

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

where?

@johnynek
Copy link
Collaborator

johnynek commented Nov 8, 2013

@softprops you have an Proxy idea that seems like a slightly less structured Reporter. Pretty sure we don't need both of these ideas.

I feel that the Reporter, with more fixed behavior has a clearer usage pattern: do something with the input and output of a store as a sideeffect.

Seems like this could be used with your instrumentation to do counters.

@softprops
Copy link
Contributor

@johnynek Proxy is more of a utility make combinators that want to add some behavior to a store type without requiring the need to override all of thats store type's methods, the "wrapper" problem. If you mix this in you only need to implement the methods that are interesting for the new type you are defining. The rest will be covered by the proxy. The instrumented types are defined in terms of proxies because once you wrap a store, to appear as an instance of that store, you also need to implement ( and not forget ) to manually override and delegate to the wrapped store methods like close. This is easy to miss since the base traits define an implementation of this. It can be important for stores that hold network connections :)

}
}

trait ReadableStoreReporter[K, V] extends ReadableStore[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.

How about:

trait ReadableStoreReporter[S <: ReadableStore[K, V], K, V] extends ReadableStore[K, V] {
  def self: S // don't lose the type when we wrap.
  def close = self.close // don't forget to close.
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

SGTM, changed

override def multiGet[K1 <: K](keys: Set[K1]) = Reporter.sideEffect(keys, self.multiGet(keys), traceMultiGet)

def traceMultiGet[K1 <: K](ks: Set[K1], request: Map[K1, Future[Option[V]]]): Map[K1, Future[Unit]]
def traceGet(k: K, request: Future[Option[V]]): Future[Unit]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the trace methods be protected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, sounds about right. Added


object Reporter {
def sideEffect[T, U](params: U, f: Future[T], sideEffect: (U, Future[T]) => Future[Unit]): Future[T] =
Future.join(f, sideEffect(params, f)).map(_._1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I was a little confused at first as to why join instead of f map ...
But this makes it possible to perform the side effect either sequentially or in parallel I guess?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

its to effectively just separate the two, they are independent futures in this model that we select one from to return to the user

@rubanm
Copy link
Contributor

rubanm commented Mar 12, 2014

LGTM

johnynek added a commit that referenced this pull request Mar 12, 2014
@johnynek johnynek merged commit b55b5a8 into develop Mar 12, 2014
@johnynek johnynek deleted the feature/ReportingStore branch March 12, 2014 19:03
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.

4 participants