-
Notifications
You must be signed in to change notification settings - Fork 647
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
Cassandra sink #56
Cassandra sink #56
Changes from 3 commits
9bc59d4
da6f91d
29314ab
3e5c17c
2af79f8
197ecc2
56a1021
595ed76
b4da679
e6fa29d
a682466
9d80e1f
ac18a87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
package akka.stream.alpakka.cassandra | ||
|
||
import com.google.common.util.concurrent.{ FutureCallback, Futures, ListenableFuture } | ||
|
||
import scala.concurrent.{ Future, Promise } | ||
|
||
package object cassandra { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Johan, where do you want me to put that. I cant get it to work. Its a compiler error on the object and cant be used on the implicit class. ??? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, you cannot put access restrictions on the package object itself, so then it needs to go on the implicit decorator, if kept public the risk is that library consumers start using it and then it cannot be moved/changed in the future, and this library is not here to provide guice-conversions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Thanks. I had two issues,
I that right, |
||
implicit class GuavaFutureOpts[A](val guavaFut: ListenableFuture[A]) extends AnyVal { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
def asScala(): Future[A] = { | ||
val p = Promise[A]() | ||
val callback = new FutureCallback[A] { | ||
override def onSuccess(a: A): Unit = p.success(a) | ||
override def onFailure(err: Throwable): Unit = p.failure(err) | ||
} | ||
Futures.addCallback(guavaFut, callback) | ||
p.future | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
package akka.stream.alpakka.cassandra.scaladsl | ||
|
||
import akka.Done | ||
import akka.stream.scaladsl.{ Flow, Keep, Sink } | ||
import com.datastax.driver.core.{ BoundStatement, PreparedStatement, Session } | ||
|
||
import scala.concurrent.{ ExecutionContext, Future } | ||
|
||
import akka.stream.alpakka.cassandra.cassandra._ | ||
|
||
object CassandraSink { | ||
def apply[T](parallelism: Int, statement: PreparedStatement, statementBinder: (T, PreparedStatement) => BoundStatement)(implicit session: Session, ex: ExecutionContext): Sink[T, Future[Done]] = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some hints for the javadsl
|
||
Flow[T].mapAsyncUnordered(parallelism)(t ⇒ | ||
session.executeAsync(statementBinder(t, statement)).asScala()).toMat(Sink.ignore)(Keep.right) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final class
(please boyscout this for us)