The idea is to filter the sources, replacing @<var>@ occurrences with the mapping for <var> (which is currently hard-coded). @@ -> @. In order to make this work, I had to move the doc sources one directory down (into akka-docs/rst) so that the filtered result could be in a sibling directory so that relative links (to _sphinx plugins or real code) would continue to work. While I was at it I also changed it so that WARNINGs and ERRORs are not swallowed into the debug dump anymore but printed at [warn] level (minimum). One piece of fallout is that the (online) html build is now run after the normal one, not in parallel.
This commit is contained in:
parent
c0f60da8cc
commit
9bc01ae265
266 changed files with 270 additions and 182 deletions
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package docs.extension
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import akka.actor.Actor
|
||||
import akka.testkit.AkkaSpec
|
||||
|
||||
//#extension
|
||||
import akka.actor.Extension
|
||||
|
||||
class CountExtensionImpl extends Extension {
|
||||
//Since this Extension is a shared instance
|
||||
// per ActorSystem we need to be threadsafe
|
||||
private val counter = new AtomicLong(0)
|
||||
|
||||
//This is the operation this Extension provides
|
||||
def increment() = counter.incrementAndGet()
|
||||
}
|
||||
//#extension
|
||||
|
||||
//#extensionid
|
||||
import akka.actor.ExtensionId
|
||||
import akka.actor.ExtensionIdProvider
|
||||
import akka.actor.ExtendedActorSystem
|
||||
|
||||
object CountExtension
|
||||
extends ExtensionId[CountExtensionImpl]
|
||||
with ExtensionIdProvider {
|
||||
//The lookup method is required by ExtensionIdProvider,
|
||||
// so we return ourselves here, this allows us
|
||||
// to configure our extension to be loaded when
|
||||
// the ActorSystem starts up
|
||||
override def lookup = CountExtension
|
||||
|
||||
//This method will be called by Akka
|
||||
// to instantiate our Extension
|
||||
override def createExtension(system: ExtendedActorSystem) = new CountExtensionImpl
|
||||
}
|
||||
//#extensionid
|
||||
|
||||
object ExtensionDocSpec {
|
||||
|
||||
val config = """
|
||||
//#config
|
||||
akka {
|
||||
extensions = ["docs.extension.CountExtension"]
|
||||
}
|
||||
//#config
|
||||
"""
|
||||
|
||||
//#extension-usage-actor
|
||||
|
||||
class MyActor extends Actor {
|
||||
def receive = {
|
||||
case someMessage ⇒
|
||||
CountExtension(context.system).increment()
|
||||
}
|
||||
}
|
||||
//#extension-usage-actor
|
||||
|
||||
//#extension-usage-actor-trait
|
||||
|
||||
trait Counting { self: Actor ⇒
|
||||
def increment() = CountExtension(context.system).increment()
|
||||
}
|
||||
class MyCounterActor extends Actor with Counting {
|
||||
def receive = {
|
||||
case someMessage ⇒ increment()
|
||||
}
|
||||
}
|
||||
//#extension-usage-actor-trait
|
||||
}
|
||||
|
||||
class ExtensionDocSpec extends AkkaSpec(ExtensionDocSpec.config) {
|
||||
import ExtensionDocSpec._
|
||||
|
||||
"demonstrate how to create an extension in Scala" in {
|
||||
//#extension-usage
|
||||
CountExtension(system).increment
|
||||
//#extension-usage
|
||||
}
|
||||
|
||||
"demonstrate how to lookup a configured extension in Scala" in {
|
||||
//#extension-lookup
|
||||
system.extension(CountExtension)
|
||||
//#extension-lookup
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package docs.extension
|
||||
|
||||
//#imports
|
||||
import akka.actor.Extension
|
||||
import akka.actor.ExtensionId
|
||||
import akka.actor.ExtensionIdProvider
|
||||
import akka.actor.ExtendedActorSystem
|
||||
import scala.concurrent.util.Duration
|
||||
import com.typesafe.config.Config
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
//#imports
|
||||
|
||||
import akka.actor.Actor
|
||||
import akka.testkit.AkkaSpec
|
||||
|
||||
//#extension
|
||||
class SettingsImpl(config: Config) extends Extension {
|
||||
val DbUri: String = config.getString("myapp.db.uri")
|
||||
val CircuitBreakerTimeout: Duration = Duration(config.getMilliseconds("myapp.circuit-breaker.timeout"), TimeUnit.MILLISECONDS)
|
||||
}
|
||||
//#extension
|
||||
|
||||
//#extensionid
|
||||
object Settings extends ExtensionId[SettingsImpl] with ExtensionIdProvider {
|
||||
|
||||
override def lookup = Settings
|
||||
|
||||
override def createExtension(system: ExtendedActorSystem) = new SettingsImpl(system.settings.config)
|
||||
}
|
||||
//#extensionid
|
||||
|
||||
object SettingsExtensionDocSpec {
|
||||
|
||||
val config = """
|
||||
//#config
|
||||
myapp {
|
||||
db {
|
||||
uri = "mongodb://example1.com:27017,example2.com:27017"
|
||||
}
|
||||
circuit-breaker {
|
||||
timeout = 30 seconds
|
||||
}
|
||||
}
|
||||
//#config
|
||||
"""
|
||||
|
||||
//#extension-usage-actor
|
||||
|
||||
class MyActor extends Actor {
|
||||
val settings = Settings(context.system)
|
||||
val connection = connect(settings.DbUri, settings.CircuitBreakerTimeout)
|
||||
|
||||
//#extension-usage-actor
|
||||
def receive = {
|
||||
case someMessage ⇒
|
||||
}
|
||||
|
||||
def connect(dbUri: String, circuitBreakerTimeout: Duration) = {
|
||||
"dummy"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SettingsExtensionDocSpec extends AkkaSpec(SettingsExtensionDocSpec.config) {
|
||||
|
||||
"demonstrate how to create application specific settings extension in Scala" in {
|
||||
//#extension-usage
|
||||
val dbUri = Settings(system).DbUri
|
||||
val circuitBreakerTimeout = Settings(system).CircuitBreakerTimeout
|
||||
//#extension-usage
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue