reactivedesignpatterns / codesamples Goto Github PK
View Code? Open in Web Editor NEWCode snippets appearing in the book are excerpts from these complete and tested samples.
License: Other
Code snippets appearing in the book are excerpts from these complete and tested samples.
License: Other
github chapter04 corresponds to book's chapter11. Perhaps book organization changed after code was prepared.
Hi, I and my friends nearly finish the translation, and we are syncing the code samples in the book and put them online.
A preview is here: http://rdp.reactiveplatform.xyz/chapter-03/index.html
But there is a problem that, some code lists and snips are not lives in this repo, So I have to manually recreate them, like, https://github.com/ReactivePlatform/reactive-design-patterns-cn/blob/master/chapter03/src/main/java/chapter03/UsingStringBuffer.java
Hopefully, we could rely on some of your great works and then make PR to merge back:) I did that before for Netty In Action book, eg: https://github.com/normanmaurer/netty-in-action
Thank you, your input is very needed.
I am reading this book years after it was published, and wanted to have a play with the code samples.
Running sbt in CodeSamples eventually turned up a NullPointerException as shown further below.
I was able to get around this by updating project/build.properties as follows, so I leave this as a note for any others who might follow:
-sbt.version=0.13.8
+sbt.version=0.13.16
(higher versions might work too, but I stuck with the 0.13 series)
~/src/ReactiveDesignPatterns/CodeSamples$ sbt
copying runtime jar...
[info] [launcher] getting org.scala-sbt sbt 0.13.8 (this may take some time)...
...
[info] Done updating.
java.lang.NullPointerException
at java.base/java.util.regex.Matcher.getTextLength(Matcher.java:1770)
at java.base/java.util.regex.Matcher.reset(Matcher.java:416)
...
See newly created PR, which addresses issue below (sbt.io was wrong)
Unable to compile chapter 13. I am using sbt 0.13.8. Do you use same? At the end there's an attached sbt.last.txt (aka sbt.last.log)
about
[info] This is sbt 0.13.8
[info] The current project is {file:/Users/philippederome/workspace/RDP/}rdp 0.1-SNAPSHOT
[info] The current project is built against Scala 2.11.8
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, spray.boilerplate.BoilerplatePlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
[error] (chapter13/:update) sbt.ResolveException: unresolved dependency: org.scala-sbt#io_2.11;0.13.8: not found
> compile
[info] Updating {file:/Users/philippederome/workspace/RDP/}chapter13...
[info] Resolving org.scala-sbt#io_2.11;0.13.8 ...
[warn] module not found: org.scala-sbt#io_2.11;0.13.8
[warn] ==== local: tried
[warn] /Users/philippederome/.ivy2/local/org.scala-sbt/io_2.11/0.13.8/ivys/ivy.xml
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/org/scala-sbt/io_2.11/0.13.8/io_2.11-0.13.8.pom
[info] Resolving jline#jline;2.12.1 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.scala-sbt#io_2.11;0.13.8: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Unresolved dependencies path:
[warn] org.scala-sbt:io_2.11:0.13.8 (/Users/philippederome/workspace/RDP/chapter13/build.sbt#L3-4)
[warn] +- com.reactivedesignpatterns:chapter13_2.11:0.1-SNAPSHOT
[trace] Stack trace suppressed: run last chapter13/:update for the full output.
[error] (chapter13/*:update) sbt.ResolveException: unresolved dependency: org.scala-sbt#io_2.11;0.13.8: not found
[error] Total time: 2 s, completed 1-Apr-2017 8:09:19 PM
last chapter13/*:update
Much details removed (can submit if required)
debug] resolve done (1598ms resolve - 15ms download)
[warn]
[warn] Note: Unresolved dependencies path:
[warn] org.scala-sbt:io_2.11:0.13.8 (/Users/philippederome/workspace/RDP/chapter13/build.sbt#L3-4)
[warn] +- com.reactivedesignpatterns:chapter13_2.11:0.1-SNAPSHOT
sbt.ResolveException: unresolved dependency: org.scala-sbt#io_2.11;0.13.8: not found
at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:291)
at sbt.IvyActions$$anonfun$updateEither$1.apply(IvyActions.scala:188)
at sbt.IvyActions$$anonfun$updateEither$1.apply(IvyActions.scala:165)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:155)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:155)
at sbt.IvySbt$$anonfun$withIvy$1.apply(Ivy.scala:132)
at sbt.IvySbt.sbt$IvySbt$$action$1(Ivy.scala:57)
at sbt.IvySbt$$anon$4.call(Ivy.scala:65)
at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:93)
at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:78)
at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:97)
at xsbt.boot.Using$.withResource(Using.scala:10)
at xsbt.boot.Using$.apply(Using.scala:9)
at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:58)
at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:48)
at xsbt.boot.Locks$.apply0(Locks.scala:31)
at xsbt.boot.Locks$.apply(Locks.scala:28)
at sbt.IvySbt.withDefaultLogger(Ivy.scala:65)
at sbt.IvySbt.withIvy(Ivy.scala:127)
at sbt.IvySbt.withIvy(Ivy.scala:124)
at sbt.IvySbt$Module.withModule(Ivy.scala:155)
at sbt.IvyActions$.updateEither(IvyActions.scala:165)
at sbt.Classpaths$$anonfun$sbt$Classpaths$$work$1$1.apply(Defaults.scala:1369)
at sbt.Classpaths$$anonfun$sbt$Classpaths$$work$1$1.apply(Defaults.scala:1365)
at sbt.Classpaths$$anonfun$doWork$1$1$$anonfun$87.apply(Defaults.scala:1399)
at sbt.Classpaths$$anonfun$doWork$1$1$$anonfun$87.apply(Defaults.scala:1397)
at sbt.Tracked$$anonfun$lastOutput$1.apply(Tracked.scala:37)
at sbt.Classpaths$$anonfun$doWork$1$1.apply(Defaults.scala:1402)
at sbt.Classpaths$$anonfun$doWork$1$1.apply(Defaults.scala:1396)
at sbt.Tracked$$anonfun$inputChanged$1.apply(Tracked.scala:60)
at sbt.Classpaths$.cachedUpdate(Defaults.scala:1419)
at sbt.Classpaths$$anonfun$updateTask$1.apply(Defaults.scala:1348)
at sbt.Classpaths$$anonfun$updateTask$1.apply(Defaults.scala:1310)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:235)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] (chapter13/*:update) sbt.ResolveException: unresolved dependency: org.scala-sbt#io_2.11;0.13.8: not found
Section 11.3.4 of pBook advertises source code archives for details on usage of CallingThreadDispatcher, which does not look to be present here.
http://myapp.com/shoppingcarts/143
. Firstly, what is a good approach to making each URI have that piece of uniqueness, and then secondly, the finer point, how should people like myself who are used to RDBMS databases generating IDs for them in classic n-tier monoliths? Would a UUID answer my own question? - example: http://myapp.com/shoppingcarts/gobbledygookofUUIDgoeshere
Not sure if I should research this on my own rather than the author as it is probably simple, but anyhow.
I forked the project, downloaded and issued sbt compile
. I have same errors compiling from Intellij IDEA CE 2016.3 (requested to Intelllij to create straight from my github fork URL using sources and didn't "tweak" anything in IDE thereafter) or straight from OSX 10.12.3 Sierra shell.
Notes:
I've been in the habit of doing Scala development on this computer for a year+ without a problem but I don't do Java so I could be missing Java artefacts of some kind.
I also found two pom.xml files in ch2, not sure whether I should use them in some way (mvn).
sbt about
>[info] This is sbt 0.13.8
>[info] The current project is {file:/Users/philippederome/workspace/CodeSamples2/}codesamples2 0.1-SNAPSHOT
>[info] The current project is built against Scala 2.11.6
>[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, spray.boilerplate.BoilerplatePlugin
>[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
MacBook-Pro-2:CodeSamples2 philippederome$ javac -version
javac 1.8.0_91
MacBook-Pro-2:CodeSamples2 philippederome$ scalac -version
Scala compiler version 2.11.7 -- Copyright 2002-2013, LAMP/EPFL
MacBook-Pro-2:CodeSamples2 philippederome$ which java
/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java
MacBook-Pro-2:CodeSamples2 philippederome$ which scala
/Applications/scala-2.11.7/bin/scala
MacBook-Pro-2:CodeSamples2 philippederome$
MacBook-Pro-2:CodeSamples2 philippederome$ sbt
[info] Loading project definition from /Users/philippederome/workspace/CodeSamples2/project
[info] Updating {file:/Users/philippederome/workspace/CodeSamples2/project/}codesamples2-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/philippederome/workspace/CodeSamples2/project/target/scala-2.10/sbt-0.13/classes...
[info] Set current project to codesamples2 (in build file:/Users/philippederome/workspace/CodeSamples2/)
compile
[info] Generating 'Scoped.scala'
[info] Updating {file:/Users/philippederome/workspace/CodeSamples2/}codesamples2...
[info] Updating {file:/Users/philippederome/workspace/CodeSamples2/}common...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[warn] Scala version was updated by one of library dependencies:
[warn] * org.scala-lang:scala-library:(2.11.6, 2.11.1) -> 2.11.7
[warn] To force scalaVersion, add the following:
[warn] ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
[warn] Run 'evicted' to see detailed eviction warnings
[info] Updating {file:/Users/philippederome/workspace/CodeSamples2/}chapter07...
[info] Updating {file:/Users/philippederome/workspace/CodeSamples2/}chapter15...
[info] Updating {file:/Users/philippederome/workspace/CodeSamples2/}chapter14...
[info] Updating {file:/Users/philippederome/workspace/CodeSamples2/}chapter02...
[info] Updating {file:/Users/philippederome/workspace/CodeSamples2/}chapter17...
[info] Updating {file:/Users/philippederome/workspace/CodeSamples2/}chapter16...
[info] Updating {file:/Users/philippederome/workspace/CodeSamples2/}chapter13...
[info] Updating {file:/Users/philippederome/workspace/CodeSamples2/}chapter12...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Resolving com.typesafe.akka#akka-actor_2.11;2.4.1 ...
[warn] Scala version was updated by one of library dependencies:
[warn] * org.scala-lang:scala-library:(2.11.6, 2.11.1) -> 2.11.7
[warn] To force scalaVersion, add the following:
[warn] ivyScala := ivyScala.value map { .copy(overrideScalaVersion = true) }
[warn] There may be incompatibilities among your library dependencies.
[warn] Here are some of the libraries that were evicted:
[warn] * com.typesafe.akka:akka-stream-experimental_2.11:1.0 -> 2.0.1
[warn] * com.typesafe.akka:akka-actor_2.11:2.3.12 -> 2.4.1
[warn] Run 'evicted' to see detailed eviction warnings
[info] Resolving org.scala-lang.modules#scala-async_2.11;0.9.2 ...
[info] Updating {file:/Users/philippederome/workspace/CodeSamples2/}chapter04...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[warn] Scala version was updated by one of library dependencies:
[warn] * org.scala-lang:scala-library:(2.11.6, 2.11.1) -> 2.11.7
[warn] To force scalaVersion, add the following:
[warn] ivyScala := ivyScala.value map { .copy(overrideScalaVersion = true) }
[warn] Run 'evicted' to see detailed eviction warnings
[info] Resolving com.typesafe.akka#akka-contrib_2.11;2.4.1 ...
[info] Compiling 4 Scala sources to /Users/philippederome/workspace/CodeSamples2/common/target/scala-2.11/classes...
[info] Resolving org.scala-sbt#io_2.11;0.13.8 ...
[warn] module not found: org.scala-sbt#io_2.11;0.13.8
[warn] ==== local: tried
[warn] /Users/philippederome/.ivy2/local/org.scala-sbt/io_2.11/0.13.8/ivys/ivy.xml
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/org/scala-sbt/io_2.11/0.13.8/io_2.11-0.13.8.pom
[info] Resolving jline#jline;2.12.1 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.scala-sbt#io_2.11;0.13.8: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[info] Resolving org.scala-lang#scala-library;2.11.6 ...
[warn]
[warn] Note: Unresolved dependencies path:
[warn] org.scala-sbt:io_2.11:0.13.8 (/Users/philippederome/workspace/CodeSamples2/chapter13/build.sbt#L3-4)
[warn] +- com.reactivedesignpatterns:chapter13_2.11:0.1-SNAPSHOT
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[warn] Scala version was updated by one of library dependencies:
[warn] * org.scala-lang:scala-library:(2.11.6, 2.11.1) -> 2.11.7
[warn] To force scalaVersion, add the following:
[warn] ivyScala := ivyScala.value map { .copy(overrideScalaVersion = true) }
[warn] Run 'evicted' to see detailed eviction warnings
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[warn] Scala version was updated by one of library dependencies:
[warn] * org.scala-lang:scala-library:(2.11.6, 2.11.1) -> 2.11.7
[warn] To force scalaVersion, add the following:
[warn] ivyScala := ivyScala.value map { .copy(overrideScalaVersion = true) }
[warn] There may be incompatibilities among your library dependencies.
[warn] Here are some of the libraries that were evicted:
[warn] * com.typesafe.akka:akka-stream-experimental_2.11:1.0 -> 2.0.1
[warn] * com.typesafe.akka:akka-actor_2.11:2.3.12 -> 2.4.1
[warn] Run 'evicted' to see detailed eviction warnings
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[warn] Scala version was updated by one of library dependencies:
[warn] * org.scala-lang:scala-library:(2.11.6, 2.11.1) -> 2.11.7
[warn] To force scalaVersion, add the following:
[warn] ivyScala := ivyScala.value map { .copy(overrideScalaVersion = true) }
[warn] There may be incompatibilities among your library dependencies.
[warn] Here are some of the libraries that were evicted:
[warn] * com.typesafe.akka:akka-stream-experimental_2.11:1.0 -> 2.0.1
[warn] * com.typesafe.akka:akka-actor_2.11:2.3.12 -> 2.4.1
[warn] Run 'evicted' to see detailed eviction warnings
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[warn] Scala version was updated by one of library dependencies:
[warn] * org.scala-lang:scala-library:(2.11.6, 2.11.1) -> 2.11.7
[warn] To force scalaVersion, add the following:
[warn] ivyScala := ivyScala.value map { .copy(overrideScalaVersion = true) }
[warn] There may be incompatibilities among your library dependencies.
[warn] Here are some of the libraries that were evicted:
[warn] * com.typesafe.akka:akka-actor_2.11:2.3.12 -> 2.4.1
[warn] Run 'evicted' to see detailed eviction warnings
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[warn] Scala version was updated by one of library dependencies:
[warn] * org.scala-lang:scala-library:(2.11.6, 2.11.1) -> 2.11.7
[warn] To force scalaVersion, add the following:
[warn] ivyScala := ivyScala.value map { .copy(overrideScalaVersion = true) }
[warn] Run 'evicted' to see detailed eviction warnings
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[warn] Scala version was updated by one of library dependencies:
[warn] * org.scala-lang:scala-library:(2.11.6, 2.11.1) -> 2.11.7
[warn] To force scalaVersion, add the following:
[warn] ivyScala := ivyScala.value map { .copy(overrideScalaVersion = true) }
[warn] Run 'evicted' to see detailed eviction warnings
[warn] there was one deprecation warning; re-run with -deprecation for details
[warn] one warning found
[info] Compiling 2 Scala sources to /Users/philippederome/workspace/CodeSamples2/chapter04/target/scala-2.11/classes...
[info] Compiling 7 Scala sources to /Users/philippederome/workspace/CodeSamples2/chapter17/target/scala-2.11/classes...
[info] Compiling 4 Java sources to /Users/philippederome/workspace/CodeSamples2/chapter14/target/scala-2.11/classes...
[info] Compiling 6 Scala sources and 1 Java source to /Users/philippederome/workspace/CodeSamples2/chapter15/target/scala-2.11/classes...
[info] Compiling 1 Scala source to /Users/philippederome/workspace/CodeSamples2/chapter07/target/scala-2.11/classes...
[info] Compiling 5 Scala sources to /Users/philippederome/workspace/CodeSamples2/chapter16/target/scala-2.11/classes...
[error] /Users/philippederome/workspace/CodeSamples2/chapter14/src/main/java/com/reactivedesignpatterns/chapter14/ComplexCommand.java:204: method toMat in class akka.stream.javadsl.Source<Out,Mat> cannot be applied to given types;
[error] required: akka.stream.Graph<akka.stream.SinkShape<com.reactivedesignpatterns.chapter14.ComplexCommand.DataElement>,M>,akka.japi.function.Function2<scala.runtime.BoxedUnit,M,M2>
[error] found: akka.stream.javadsl.Sink<com.reactivedesignpatterns.chapter14.ComplexCommand.DataElement,scala.concurrent.Future<java.lang.Long>>,scala.Function2<scala.runtime.BoxedUnit,java.lang.Long,java.lang.Long>
[error] reason: cannot infer type-variable(s) M,M2,U,In
[error] (argument mismatch; scala.Function2<scala.runtime.BoxedUnit,java.lang.Long,java.lang.Long> cannot be converted to akka.japi.function.Function2<scala.runtime.BoxedUnit,M,M2>)
[error] Source.empty()
[error] .filter(new InRange("year", 1950, 1960))
[error] .toMat
[warn] /Users/philippederome/workspace/CodeSamples2/chapter15/src/main/scala/com/reactivedesignpatterns/chapter15/AskPattern.scala:77: match may not be exhaustive.
[warn] It would fail on the following inputs: Sig(, Failed(, )), Sig(, PostRestart()), Sig(, PostStop), Sig(, PreRestart()), Sig(, Terminated())
[warn] val childActor = ctx.spawnAnonymous(Props(FullTotal[SendEmailResult] {
[warn] ^
[warn] /Users/philippederome/workspace/CodeSamples2/chapter15/src/main/scala/com/reactivedesignpatterns/chapter15/Saga.scala:73: match may not be exhaustive.
[warn] It would fail on the following input: RolledBack
[warn] last match {
[warn] ^
[warn] two warnings found
[trace] Stack trace suppressed: run last chapter13/:update for the full output.
**[error] (chapter14/compile:compileIncremental) javac returned nonzero exit code
[error] (chapter13/:update) sbt.ResolveException: unresolved dependency: org.scala-sbt#io_2.11;0.13.8: not found**
[error] Total time: 16 s, completed 19-Mar-2017 8:51:26 PM
There's no unit test for this and I didn't write one up now, so my analysis has to be reviewed but I think I am right. Note: I am not trying to find faults in code, simply making sure I understand discussion and solution and questioning validity to some extent is way to get better understanding
theStore is invariant in foldLeft and therefore persist is invariant in the dictionary kv it stores (always theStore). It should take the dynamic value "store" instead.
val nextStore = waiting.valuesIterator.take(prefix).foldLeft(theStore) { (store, replicate) =>
persist(name, replicate.seq, theStore)
replicate.replyTo ! Replicated(replicate.seq)
applied.enqueue(replicate)
store + (replicate.key -> replicate.value)
}
val nextStore = waiting.valuesIterator.take(prefix).foldLeft(theStore) { (store, replicate) =>
persist(name, replicate.seq, store)
replicate.replyTo ! Replicated(replicate.seq)
applied.enqueue(replicate)
store + (replicate.key -> replicate.value)
}
I know the book is using Akka 2.4.x,but yes,there is something changed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.