Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@

package docs.org.apache.pekko.typed

//#fiddle_code
//#imports
import org.apache.pekko
import pekko.actor.typed.scaladsl.Behaviors
import pekko.actor.typed.scaladsl.LoggerOps
import pekko.actor.typed.{ ActorRef, ActorSystem, Behavior }
//#imports
//#fiddle_code

import pekko.NotUsed
import pekko.Done
Expand All @@ -35,17 +33,14 @@ import java.nio.charset.StandardCharsets

object IntroSpec {
//format: OFF
//#fiddle_code


//#hello-world-actor
object HelloWorld {
final case class Greet(whom: String, replyTo: ActorRef[Greeted])
final case class Greeted(whom: String, from: ActorRef[Greet])

def apply(): Behavior[Greet] = Behaviors.receive { (context, message) =>
//#fiddle_code
context.log.info("Hello {}!", message.whom)
//#fiddle_code
//#hello-world-actor
println(s"Hello ${message.whom}!")
//#hello-world-actor
Expand All @@ -65,9 +60,7 @@ object IntroSpec {
private def bot(greetingCounter: Int, max: Int): Behavior[HelloWorld.Greeted] =
Behaviors.receive { (context, message) =>
val n = greetingCounter + 1
//#fiddle_code
context.log.info2("Greeting {} for {}", n, message.whom)
//#fiddle_code
//#hello-world-bot
println(s"Greeting $n for ${message.whom}")
//#hello-world-bot
Expand Down Expand Up @@ -111,7 +104,6 @@ object IntroSpec {

// Entry point for the execution
HelloWorldMain.main(Array.empty)
//#fiddle_code
//format: ON

object CustomDispatchersExample {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ object ClassicSample {

override def receive: Receive = {
case Greet(whom) =>
// #fiddle_code
log.info("Hello {}!", whom)
sender() ! Greeted(whom)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/paradox/actors.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ construction.

#### Here is another example:

@@snip [ActorDocSpec.scala](/docs/src/test/scala/docs/actor/ActorDocSpec.scala) { #fiddle_code template="Pekko" layout="v75" minheight="400px" }
@@snip [ActorDocSpec.scala](/docs/src/test/scala/docs/actor/ActorDocSpec.scala) { #my-actor }

@@@

Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/paradox/stream/stream-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ whether the stream terminated normally or exceptionally.
<a name="here-is-another-example"></a>
Here is another example:

@@snip [TwitterStreamQuickstartDocSpec.scala](/docs/src/test/scala/docs/stream/TwitterStreamQuickstartDocSpec.scala) { #fiddle_code template=Pekko layout=v75 minheight=400px }
@@snip [TwitterStreamQuickstartDocSpec.scala](/docs/src/test/scala/docs/stream/TwitterStreamQuickstartDocSpec.scala) { #first-sample }


## Reusable Pieces
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/paradox/typed/actors.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ You will also need to add a @ref:[logging dependency](logging.md) to see that ou

#### Here is another example:

@@snip [IntroSpec.scala](/actor-typed-tests/src/test/scala/docs/org/apache/pekko/typed/IntroSpec.scala) { #fiddle_code template=Pekko layout=v75 minheight=400px }
@@snip [IntroSpec.scala](/actor-typed-tests/src/test/scala/docs/org/apache/pekko/typed/IntroSpec.scala) { #hello-world-main }

@@@

Expand Down
6 changes: 0 additions & 6 deletions docs/src/test/scala/docs/actor/ActorDocSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ final case class Give(thing: Any)

//#receive-orElse

//#fiddle_code
import org.apache.pekko.actor.{ Actor, ActorRef, ActorSystem, PoisonPill, Props }
import scala.concurrent.duration._

Expand Down Expand Up @@ -364,8 +363,6 @@ class Ponger(pinger: ActorRef) extends Actor {
}
}

//#fiddle_code

//#immutable-message-definition
case class User(name: String)

Expand Down Expand Up @@ -409,7 +406,6 @@ class ActorDocSpec extends PekkoSpec("""
}

"run basic Ping Pong" in {
// #fiddle_code
val system = ActorSystem("pingpong")

val pinger = system.actorOf(Props[Pinger](), "pinger")
Expand All @@ -421,8 +417,6 @@ class ActorDocSpec extends PekkoSpec("""
ponger ! Ping
}

// #fiddle_code

val testProbe = new TestProbe(system)
testProbe.watch(pinger)
testProbe.expectTerminated(pinger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import org.apache.pekko.testkit.PekkoSpec
import scala.concurrent.ExecutionContext

object TwitterStreamQuickstartDocSpec {
// #fiddle_code
import org.apache.pekko
import pekko.NotUsed
import pekko.actor.ActorSystem
Expand All @@ -53,15 +52,12 @@ object TwitterStreamQuickstartDocSpec {
val pekkoTag = Hashtag("#pekko")
// #model

// #fiddle_code

abstract class TweetSourceDecl {
// #tweet-source
val tweets: Source[Tweet, NotUsed]
// #tweet-source
}

// #fiddle_code
val tweets: Source[Tweet, NotUsed] = Source(
Tweet(Author("rolandkuhn"), System.currentTimeMillis, "#pekko rocks!") ::
Tweet(Author("patriknw"), System.currentTimeMillis, "#pekko !") ::
Expand All @@ -75,7 +71,6 @@ object TwitterStreamQuickstartDocSpec {
Tweet(Author("drama"), System.currentTimeMillis, "we compared #apples to #oranges!") ::
Nil)

// #fiddle_code
}

class TwitterStreamQuickstartDocSpec extends PekkoSpec {
Expand All @@ -87,14 +82,12 @@ class TwitterStreamQuickstartDocSpec extends PekkoSpec {
def println(s: Any): Unit = ()

trait Example1 {
// #fiddle_code
// #first-sample
// #system-setup
implicit val system: ActorSystem = ActorSystem("reactive-tweets")
// #system-setup
// #first-sample

// #fiddle_code
}

"filter and map" in {
Expand Down Expand Up @@ -158,17 +151,15 @@ class TwitterStreamQuickstartDocSpec extends PekkoSpec {
// format: ON
}

"simple fiddle showcase" in {
"simple example showcase" in {

// #fiddle_code
tweets
.filterNot(_.hashtags.contains(pekkoTag)) // Remove all tweets containing #pekko hashtag
.map(_.hashtags) // Get all sets of hashtags ...
.reduce(_ ++ _) // ... and reduce them to a single set, removing duplicates across all tweets
.mapConcat(identity) // Flatten the set of hashtags to a stream of hashtags
.map(_.name.toUpperCase) // Convert all hashtags to upper case
.runWith(Sink.foreach(println)) // Attach the Flow to a Sink that will finally print the hashtags
// #fiddle_code
.value
}

Expand Down