Skip to content

Commit

Permalink
Markdown linting: blank lines around fences (MD031) (#5317)
Browse files Browse the repository at this point in the history
Markdown linting: blank lines around fences (MD031) (#5317)
  • Loading branch information
SeanKilleen committed Oct 14, 2021
1 parent cb28679 commit 514c007
Show file tree
Hide file tree
Showing 38 changed files with 168 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/articles/actors/coordinated-shutdown.md
Expand Up @@ -140,6 +140,7 @@ By default, when the final phase of the `CoordinatedShutdown` executes the calli
```
akka.coordinated-shutdown.terminate-actor-system = off
```

If this setting is disabled (it is enabled b default), the `ActorSystem` will not be terminated as the final phase of the `CoordinatedShutdown` phases.

`CoordinatedShutdown` phases, by default, are also executed when the `ActorSystem` is terminated. You can change this behavior by disabling this HOCON value in your configuration:
Expand Down
1 change: 1 addition & 0 deletions docs/articles/actors/dependency-injection.md
Expand Up @@ -95,6 +95,7 @@ var system = ActorSystem.Create("MySystem");
// Create the dependency resolver for the actor system
IDependencyResolver resolver = new XyzDependencyResolver(someContainer, system);
```

When creating actorRefs straight off your ActorSystem instance, you can use the DI() Extension.

```csharp
Expand Down
13 changes: 13 additions & 0 deletions docs/articles/actors/finite-state-machine.md
Expand Up @@ -9,6 +9,7 @@ title: FSM
To demonstrate most of the features of the `FSM` class, consider an actor which shall receive and queue messages while they arrive in a burst and send them on after the burst ended or a flush request is received.

First, consider all of the below to use these import statements:

```csharp
using Akka.Actor;
using Akka.Event;
Expand Down Expand Up @@ -80,9 +81,11 @@ The `FSM` class takes two type parameters:
### Defining States

A state is defined by one or more invocations of the method

```csharp
When(<stateName>, <stateFunction>[, timeout = <timeout>]).
```

The given name must be an object which is type-compatible with the first type parameter given to the `FSM` class. This object is used as a hash key, so you must ensure that it properly implements `Equals` and `GetHashCode`; in particular it must not be mutable. The easiest fit for these requirements are case objects.

If the `timeout` parameter is given, then all transitions into this state, including staying, receive this timeout by default. Initiating the transition with an explicit timeout may be used to override this default, see [Initiating Transitions](#initiating-transitions) for more information. The state timeout of any state may be changed during action processing with `SetStateTimeout(state, duration)`. This enables runtime configuration e.g. via external message.
Expand All @@ -94,9 +97,11 @@ The `stateFunction` argument is a `delegate State<TState, TData> StateFunction(E
### Defining the Initial State

Each `FSM` needs a starting point, which is declared using

```csharp
StartWith(state, data[, timeout])
```

The optionally given timeout argument overrides any specification given for the desired initial state. If you want to cancel a default timeout, use `null`.

### Unhandled Events
Expand All @@ -118,6 +123,7 @@ WhenUnhandled(state =>
}
});
```

Within this handler the state of the `FSM` may be queried using the stateName method.

> [!IMPORTANT]
Expand All @@ -132,6 +138,7 @@ The result of any stateFunction must be a definition of the next state unless te
- `Replying(msg)`. This modifier sends a reply to the currently processed message and otherwise does not modify the state transition.

All modifiers can be chained to achieve a nice and concise description:

```csharp
When(State.SomeState, state => {
return GoTo(new Processing())
Expand All @@ -148,9 +155,11 @@ Transitions occur "between states" conceptually, which means after any actions y
#### Internal Monitoring

Up to this point, the `FSM DSL` has been centered on states and events. The dual view is to describe it as a series of transitions. This is enabled by the method

```csharp
OnTransition(handler)
```

which associates actions with a transition instead of with a state and event. The handler is a delegate `void TransitionHandler(TState initialState, TState nextState)` function which takes a pair of states as input; no resulting state is needed as it is not possible to modify the transition in progress.

```csharp
Expand Down Expand Up @@ -202,6 +211,7 @@ Timers may be canceled using
CancelTimer(name);

```

which is guaranteed to work immediately, meaning that the scheduled message will not be processed after this call even if the timer already fired and queued it. The status of any timer may be inquired with

```csharp
Expand All @@ -213,9 +223,11 @@ These named timers complement state timeouts because they are not affected by in
### Termination from Inside

The `FSM` is stopped by specifying the result state as

```csharp
Stop(reason, stateData);
```

The reason must be one of `Normal` (which is the default), `Shutdown` or `Failure(reason)`, and the second argument may be given to change the state data which is available during termination handling.

> [!NOTE]
Expand Down Expand Up @@ -252,6 +264,7 @@ OnTermination(termination =>
}
});
```

As for the `WhenUnhandled` case, this handler is not stacked, so each invocation of `OnTermination` replaces the previously installed handler.

### Termination from Outside
Expand Down
2 changes: 2 additions & 0 deletions docs/articles/actors/inbox.md
Expand Up @@ -6,6 +6,7 @@ title: Inbox
# The Inbox

When writing code outside of actors which shall communicate with actors, the ask pattern can be a solution (see below), but there are two things it cannot do: receiving multiple replies (e.g. by subscribing an `IActorRef` to a notification service) and watching other actors' lifecycle. For these purposes there is the `Inbox` class:

```csharp
var target = system.ActorOf(Props.Empty);
var inbox = Inbox.Create(system);
Expand All @@ -23,6 +24,7 @@ catch (TimeoutException)
```

The send method wraps a normal `Tell` and supplies the internal actor's reference as the sender. This allows the reply to be received on the last line. Watching an actor is quite simple as well

```csharp
using System.Diagnostics;
...
Expand Down
15 changes: 15 additions & 0 deletions docs/articles/actors/receive-actor-api.md
Expand Up @@ -16,6 +16,7 @@ The Actor Model provides a higher level of abstraction for writing concurrent an
In order to use the `Receive()` method inside an actor, the actor must inherit from ReceiveActor. Inside the constructor, add a call to `Receive<T>(Action<T> handler)` for every type of message you want to handle:

Here is an example:

```csharp
public class MyActor: ReceiveActor
{
Expand All @@ -35,12 +36,14 @@ public class MyActor: ReceiveActor
### Props

`Props` is a configuration class to specify options for the creation of actors, think of it as an immutable and thus freely shareable recipe for creating an actor including associated deployment information (e.g. which dispatcher to use, see more below). Here are some examples of how to create a `Props` instance

```csharp
Props props1 = Props.Create(typeof(MyActor));
Props props2 = Props.Create(() => new MyActorWithArgs("arg"));
Props props3 = Props.Create<MyActor>();
Props props4 = Props.Create(typeof(MyActorWithArgs), "arg");
```

The second variant shows how to pass constructor arguments to the `Actor` being created, but it should only be used outside of actors as explained below.

#### Recommended Practices
Expand Down Expand Up @@ -71,6 +74,7 @@ system.ActorOf(DemoActor.Props(42), "demo");
```

Another good practice is to declare local messages (messages that are sent in process) within the Actor, which makes it easier to know what messages are generally being sent over the wire vs in process.:

```csharp
public class DemoActor : ReceiveActor
{
Expand Down Expand Up @@ -174,6 +178,7 @@ protected override void PostStop()
{
}
```

The implementations shown above are the defaults provided by the `ReceiveActor` class.

### Actor Lifecycle
Expand Down Expand Up @@ -266,6 +271,7 @@ Context.ActorSelection("/user/serviceA/actor");
// will look up sibling beneath same supervisor
Context.ActorSelection("../joe");
```

> [!NOTE]
> It is always preferable to communicate with other Actors using their `IActorRef` instead of relying upon `ActorSelection`. Exceptions are: sending messages using the At-Least-Once Delivery facility, initiating first contact with a remote system. In all other cases `ActorRefs` can be provided during Actor creation or initialization, passing them from parent to child or introducing Actors by sending their `ActorRefs` to other Actors within messages.
Expand All @@ -280,6 +286,7 @@ Context.ActorSelection("/user/serviceB/worker*");
// will look up all siblings beneath same supervisor
Context.ActorSelection("../*");
```

Messages can be sent via the `ActorSelection` and the path of the `ActorSelection`is looked up when delivering each message. If the selection does not match any actors the message will be dropped.

To acquire an `IActorRef` for an `ActorSelection` you need to send a message to the selection and use the `Sender` reference of the reply from the actor. There is a built-in `Identify` message that all Actors will understand and automatically reply to with a `ActorIdentity` message containing the `IActorRef`. This message is handled specially by the actors which are traversed in the sense that if a concrete name lookup fails (i.e. a non-wildcard path element does not correspond to a live actor) then a negative result is generated. Please note that this does not mean that delivery of that reply is guaranteed, it still is a normal message.
Expand Down Expand Up @@ -379,6 +386,7 @@ This is the preferred way of sending messages. No blocking waiting for a message
// don’t forget to think about who is the sender (2nd argument)
target.Tell(message, Self);
```

The sender reference is passed along with the message and available within the receiving actor via its `Sender` property while processing this message. Inside of an actor it is usually `Self` who shall be the sender, but there can be cases where replies shall be routed to some other actor—e.g. the parent—in which the second argument to `Tell` would be a different one. Outside of an actor and if no reply is needed the second argument can be `null`; if a reply is needed outside of an actor you can use the ask-pattern described next.

### Ask: Send-And-Receive-Future
Expand Down Expand Up @@ -430,6 +438,7 @@ target.Forward(result);
## Receive messages

To receive a message you should create a `Receive` handler in a constructor.

```csharp
Receive<string>(ms => Console.WriteLine("Received message: " + msg));
```
Expand All @@ -443,6 +452,7 @@ Receive<string>(s => Console.WriteLine("Received string: " + s)); //1
Receive<string>(s => Console.WriteLine("Also received string: " + s)); //2
Receive<object>(o => Console.WriteLine("Received object: " + o)); //3
```

> **Example**<br/>
> The actor receives a message of type string. Only the first handler is invoked, even though all three handlers can handle that message.
Expand Down Expand Up @@ -493,6 +503,7 @@ protected override void Unhandled(object message)
//Do something with the message.
}
```

Another option is to add a handler last that matches all messages, using `ReceiveAny()`.

### ReceiveAny
Expand All @@ -503,6 +514,7 @@ To catch messages of any type the `ReceiveAny(Action<object> handler)` overload
Receive<string>(s => Console.WriteLine("Received string: " + s);
ReceiveAny(o => Console.WriteLine("Received object: " + o);
```

Since it handles everything, it must be specified last. Specifying handlers it after will cause an exception.

```csharp
Expand Down Expand Up @@ -783,6 +795,7 @@ static void Main(string[] args)
The `IWithUnboundedStash` interface enables an actor to temporarily stash away messages that can not or should not be handled using the actor's current behavior. Upon changing the actor's message handler, i.e., right before invoking `Context.BecomeStacked()` or `Context.UnbecomeStacked()`;, all stashed messages can be "un-stashed", thereby prepending them to the actor's mailbox. This way, the stashed messages can be processed in the same order as they have been received originally. An actor that implements `IWithUnboundedStash` will automatically get a dequeue-based mailbox.

Here is an example of the `IWithUnboundedStash` interface in action:

```csharp
public class ActorWithProtocol : ReceiveActor, IWithUnboundedStash
{
Expand Down Expand Up @@ -887,6 +900,7 @@ protected override void PreRestart(Exception reason, object message)
PostStop();
}
```

Please note, that the child actors are *still restarted*, but no new `IActorRef` is created. One can recursively apply the same principles for the children, ensuring that their `PreStart()` method is called only at the creation of their refs.

For more information see [What Restarting Means](xref:supervision#what-restarting-means).
Expand Down Expand Up @@ -917,6 +931,7 @@ public class Service : ReceiveActor
}
}
```

If the actor may receive messages before it has been initialized, a useful tool can be the `Stash` to save messages until the initialization finishes, and replaying them after the actor became initialized.

> [!WARNING]
Expand Down
19 changes: 19 additions & 0 deletions docs/articles/actors/routers.md
Expand Up @@ -49,6 +49,7 @@ akka.actor.deployment {
}
}
```

```cs
var props = Props.Create<Worker>().WithRouter(FromConfig.Instance);
var actor = system.ActorOf(props, "workers");
Expand All @@ -64,6 +65,7 @@ akka.actor.deployment {
}
}
```

```cs
var props = Props.Create<Worker>().WithRouter(FromConfig.Instance);
var actor = system.ActorOf(props, "workers");
Expand Down Expand Up @@ -118,6 +120,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Create<Worker>().WithRouter(FromConfig.Instance), "some-pool");
```
Expand All @@ -138,6 +141,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "some-group");
```
Expand Down Expand Up @@ -167,6 +171,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Create<Worker>().WithRouter(FromConfig.Instance), "some-pool");
```
Expand All @@ -187,6 +192,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "some-group");
```
Expand Down Expand Up @@ -214,6 +220,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Create<Worker>().WithRouter(FromConfig.Instance), "some-pool");
```
Expand All @@ -234,6 +241,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "some-group");
```
Expand Down Expand Up @@ -266,6 +274,7 @@ By using a `ConsistentHash` router we can now process multiple commands in paral
There are 3 ways to define what data to use for the consistent hash key.

1. You can define a *hash mapping delegate* using the `WithHashMapper` method of the router to map incoming messages to their consistent hash key. This makes the decision transparent for the sender.

```cs
new ConsistentHashingPool(5).WithHashMapping(o =>
{
Expand All @@ -277,6 +286,7 @@ There are 3 ways to define what data to use for the consistent hash key.
```

2. The messages may implement `IConsistentHashable`. The key is part of the message and it's convenient to define it together with the message definition.

```cs
public class SomeMessage : IConsistentHashable
{
Expand All @@ -286,6 +296,7 @@ There are 3 ways to define what data to use for the consistent hash key.
```

3. The messages can be wrapped in a `ConsistentHashableEnvelope` to define what data to use for the consistent hash key. The sender knows the key to use.

```cs
public class SomeMessage
{
Expand All @@ -311,6 +322,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Create<Worker>().WithRouter(FromConfig.Instance), "some-pool");
```
Expand All @@ -332,6 +344,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "some-group");
```
Expand Down Expand Up @@ -369,6 +382,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Create<Worker>().WithRouter(FromConfig.Instance), "some-pool");
```
Expand All @@ -393,6 +407,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "some-group");
```
Expand Down Expand Up @@ -431,6 +446,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Create<Worker>().WithRouter(FromConfig.Instance), "some-pool");
```
Expand All @@ -453,6 +469,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "some-group");
```
Expand Down Expand Up @@ -490,6 +507,7 @@ akka.actor.deployment {
}
}
```

```cs
var router = system.ActorOf(Props.Create<Worker>().WithRouter(FromConfig.Instance), "some-pool");
```
Expand Down Expand Up @@ -524,6 +542,7 @@ You can also set a resizer in code when creating a router.
```cs
new RoundRobinPool(5, new DefaultResizer(1, 10))
```

These are settings you usually change in the resizer:

* `enabled` - Turns on or off the resizer. The default is `off`.
Expand Down

0 comments on commit 514c007

Please sign in to comment.