This repository has been archived by the owner on Mar 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Feature/streaming take2 #79
Open
jedesah
wants to merge
65
commits into
Verizon:master
Choose a base branch
from
jedesah:feature/streaming_take2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
6c8055a
WIP - Client facing changes for Streaming
jedesah 5f5d72c
Merge branch 'master' into feature/streaming_take2
jedesah 3244392
Add collect method to Remote
jedesah b5135a8
Implement client side streaming (sending and receiving)
jedesah ae1e061
Update benchmark tests to reflect Response being a Process
jedesah 6e94f83
Server side streaming
jedesah e7d96e6
Factor out code common to evaluate and evaluateStream
jedesah caba72b
Improve runWithoutContext argument list
jedesah cf4d346
Update test for new Streaming API
jedesah 8432b80
Remove NonDeterminism instance from Response
jedesah 3647f81
Fix Capabilities Test
jedesah 7cb096e
Merge branch 'master' into feature/streaming_take2
jedesah a8f58e5
Fix compile errors due to merging of master with scodec upgrade
jedesah a733e94
Merge branch 'master' into feature/streaming_take2
jedesah bc2b26b
Fix minor compile error after merge
jedesah b93177d
Comment out a function that should not be available right now
jedesah 1aba960
Fix SSL spec
jedesah 2c09f7f
Fix issue where we were sending the Any tag to the server because of …
jedesah 2ce6a9e
Remove TODO that is now fixed
jedesah a23b227
Fix stack overflow issue
jedesah be6d7bc
Add test for Streaming
jedesah 57e88e5
Merge branch 'master' into feature/streaming_take2
jedesah 35a6836
Minor refactoring
jedesah 0930dfd
Merge branch 'master' into feature/streaming_take2
jedesah df9be48
Merge branch 'master' into feature/streaming_take2
jedesah 12b7ed6
Add concept of Streaming to Response
jedesah 661802e
Improve Streaming test
jedesah 3469be6
Use EmptyStream as placeholder instead of null
jedesah 1121089
Revert Response to original state and implement alternative way to id…
jedesah 4673822
Merge branch 'master' into feature/streaming_take2
jedesah 24bd9a1
Simple fix I don't understand to fix Streaming
jedesah aa199e8
Cleanup Streaming example
jedesah 69d7d8c
Add knowledge of Streaming to the macro code generation layer
jedesah 6745f04
Add documentation for collect
jedesah 7561472
Remove outdated comment
jedesah ad8df7f
Delete unused param (revert of unintended change)
jedesah 9bbb569
Add sealed to App
jedesah 329de89
Fix runWithoutContext (now I remember..._
jedesah 6a24514
Remote head() function from AugmentedProcess, use uncons instead
jedesah dacb2d8
Change Stream magic number to 255
jedesah ca57f81
Minor typing improvement around evalutate
jedesah f821d2d
Restore ResponseSpec to original state
jedesah 8da4370
Add test for failed Stream
jedesah 939c965
Improve test name
jedesah fdfe77c
Fix implementation of uncons
jedesah 8d60190
Merge branch 'master' into feature/streaming_take2
jedesah c3fba37
Add concept of strict or stream fields
jedesah e013ee6
Fix String representation of Signature
jedesah 42779bb
Merge branch 'master' into feature/streaming_take2
jedesah d483ae5
Fix bug in Signature
jedesah 0907369
Get GenerationSpec tests to compile
jedesah 4eebd5e
Fix tests
jedesah 3987183
Add tests for Signature String methods
jedesah f430fd2
Add extra arity for declareStream
jedesah 1478295
Enable support for Streaming arguments along side normal arguments in…
jedesah e30d763
Add Protocol level test for Streaming
jedesah e755771
Add very basic benchmarks for Streaming
jedesah f3443f7
Upgrade to scalaz 7.1.2
jedesah 20a94f9
Remove question in comments and clean imports
jedesah bf0c549
Refactor monitoring on Server side
jedesah 76457c5
Fix warning which uncovered error in test
jedesah 31a1312
Fix compile error
jedesah e0f3aef
Add chat server example
jedesah d807f4b
Cleanup chat example
jedesah 20c44af
Add TODO
jedesah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import scala.reflect.runtime.universe.TypeTag | |
import scodec.{Codec,Decoder,Encoder} | ||
import scodec.bits.BitVector | ||
import shapeless._ | ||
import scalaz.stream.Process | ||
|
||
/** | ||
* Represents a remote computation which yields a | ||
|
@@ -38,6 +39,18 @@ sealed trait Remote[+A] { | |
def pretty: String = "Remote {\n " + | ||
Remote.refs(this).mkString("\n ") + "\n " + | ||
toString + "\n}" | ||
|
||
/** | ||
* Builds a List by applying a partial function to all children of this Remote on which the function is defined. | ||
*/ | ||
def collect[B](partial: PartialFunction[Remote[Any],B]): List[B] = { | ||
val me = partial.lift(this).toList | ||
val rest = this match { | ||
case app: Remote.Ap[_] => (app.f :: app.args).map(_.collect(partial)).flatten | ||
case _ => Nil | ||
} | ||
me ++ rest | ||
} | ||
} | ||
|
||
object Remote { | ||
|
@@ -52,6 +65,15 @@ object Remote { | |
def local[A:Encoder:TypeTag](a: A): Remote[A] = | ||
Remote.Local(a, Some(Encoder[A]), Remote.toTag[A]) | ||
|
||
def localStream[A: Encoder:TypeTag](stream: Process[Task, A]): Remote[Process[Task,A]] = | ||
Remote.LocalStream(stream, Some(Encoder[A]), Remote.toTag[A]) | ||
|
||
implicit class RunSyntaxForStreaming[A](self: Remote[Process[Task,A]]) { | ||
/** Call `self.run(at, M).apply(ctx)` to get back a `Task[A]`. */ | ||
def run(at: Endpoint, ctx: Response.Context = Response.Context.empty, M: Monitoring = Monitoring.empty)(implicit A: TypeTag[A], C: Codec[A]): Task[Process[Task,A]] = | ||
evaluateStream(at,M)(self).apply(ctx) | ||
} | ||
|
||
/** Provides the syntax `expr.run(endpoint)`, where `endpoint: Endpoint`. */ | ||
implicit class RunSyntax[A](self: Remote[A]) { | ||
/** | ||
|
@@ -66,8 +88,8 @@ object Remote { | |
run(at, M).apply(ctx) | ||
|
||
/** Run this with an empty context */ | ||
def runWithoutContext(at: Endpoint)(implicit A: TypeTag[A], C: Codec[A]): Task[A] = | ||
runWithContext(at, Response.Context.empty) | ||
def runWithoutContext(at: Endpoint, M: Monitoring = Monitoring.empty)(implicit A: TypeTag[A], C: Codec[A]): Task[A] = | ||
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. something weird |
||
runWithContext(at, Response.Context.empty, M) | ||
} | ||
implicit class Ap1Syntax[A,B](self: Remote[A => B]) { | ||
def apply(a: Remote[A]): Remote[B] = | ||
|
@@ -95,64 +117,58 @@ object Remote { | |
override def toString = a.toString | ||
} | ||
|
||
private[remotely] case class LocalStream[A]( | ||
stream: Process[Task,A], | ||
format: Option[Encoder[A]], | ||
tag: String | ||
) extends Remote[Process[Task,A]] { | ||
override def toString = stream.toString | ||
} | ||
|
||
/** | ||
* Reference to a remote value on the server. | ||
*/ | ||
private[remotely] case class Ref[A](name: String) extends Remote[A] { | ||
override def toString = name.takeWhile(_ != ':') | ||
} | ||
|
||
private[remotely] sealed abstract class Ap[A](val f: Remote[Any],val args: List[Remote[Any]]) extends Remote[A] { | ||
override def toString = s"""$f({$args.mkString(","})""" | ||
} | ||
|
||
// we require a separate constructor for each function | ||
// arity, since remote invocations must be fully saturated | ||
private[remotely] case class Ap1[A,B]( | ||
f: Remote[A => B], | ||
a: Remote[A]) extends Remote[B] { | ||
override def toString = s"$f($a)" | ||
} | ||
override val f: Remote[A => B], | ||
a: Remote[A]) extends Ap[B](f,List(a)) | ||
|
||
private[remotely] case class Ap2[A,B,C]( | ||
f: Remote[(A,B) => C], | ||
override val f: Remote[(A,B) => C], | ||
a: Remote[A], | ||
b: Remote[B]) extends Remote[C] { | ||
override def toString = s"$f($a, $b)" | ||
} | ||
b: Remote[B]) extends Ap[C](f,List(a,b)) | ||
|
||
private[remotely] case class Ap3[A,B,C,D]( | ||
f: Remote[(A,B,C) => D], | ||
override val f: Remote[(A,B,C) => D], | ||
a: Remote[A], | ||
b: Remote[B], | ||
c: Remote[C]) extends Remote[D] { | ||
override def toString = s"$f($a, $b, $c)" | ||
} | ||
c: Remote[C]) extends Ap[D](f,List(a,b,c)) | ||
|
||
private[remotely] case class Ap4[A,B,C,D,E]( | ||
f: Remote[(A,B,C,D) => E], | ||
override val f: Remote[(A,B,C,D) => E], | ||
a: Remote[A], | ||
b: Remote[B], | ||
c: Remote[C], | ||
d: Remote[D]) extends Remote[E] { | ||
override def toString = s"$f($a, $b, $c, $d)" | ||
} | ||
d: Remote[D]) extends Ap[E](f,List(a,b,c,d)) | ||
|
||
/** Collect up all the `Ref` names referenced by `r`. */ | ||
def refs[A](r: Remote[A]): SortedSet[String] = r match { | ||
case Local(a,e,t) => SortedSet.empty | ||
def refs[A](r: Remote[A]): SortedSet[String] = (r collect { | ||
case Ref(t) => SortedSet(t) | ||
case Ap1(f,a) => refs(f).union(refs(a)) | ||
case Ap2(f,a,b) => refs(f).union(refs(b)).union(refs(b)) | ||
case Ap3(f,a,b,c) => refs(f).union(refs(b)).union(refs(b)).union(refs(c)) | ||
case Ap4(f,a,b,c,d) => refs(f).union(refs(b)).union(refs(b)).union(refs(c)).union(refs(d)) | ||
} | ||
}).fold(SortedSet.empty[String])(_.union(_)) | ||
|
||
/** Collect up all the formats referenced by `r`. */ | ||
def formats[A](r: Remote[A]): SortedSet[String] = r match { | ||
def formats[A](r: Remote[A]): SortedSet[String] = r.collect { | ||
case Local(a,e,t) => SortedSet(t) | ||
case Ref(t) => SortedSet.empty | ||
case Ap1(f,a) => formats(f).union(formats(a)) | ||
case Ap2(f,a,b) => formats(f).union(formats(b)).union(formats(b)) | ||
case Ap3(f,a,b,c) => formats(f).union(formats(b)).union(formats(b)).union(formats(c)) | ||
case Ap4(f,a,b,c,d) => formats(f).union(formats(b)).union(formats(b)).union(formats(c)).union(formats(d)) | ||
} | ||
}.fold(SortedSet.empty[String])(_.union(_)) | ||
|
||
def toTag[A:TypeTag]: String = { | ||
val tt = typeTag[A] | ||
|
@@ -175,6 +191,8 @@ object Remote { | |
|
||
/** Implicitly promote a local value to a `Remote[A]`. */ | ||
implicit def localToRemote[A:Encoder:TypeTag](a: A): Remote[A] = local(a) | ||
|
||
implicit def localStreamToRemote[A: Encoder:TypeTag](stream: Process[Task, A]): Remote[Process[Task,A]] = localStream(stream) | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add documentation