Skip to content

SystemParameters

devlaam edited this page Oct 26, 2026 · 7 revisions

SystemParameters: Use DefaultParameters of roll your own.

Text compliant with Leucine version 0.7.x

Introduction

As with any library, there are some parameters that are needed during operation which should not completely fixed by the library designer. On the other hand, as a user of the library you do not want to set or think of them all the time, certainly not at first use. You expect the designer to provide you with reasonable defaults and rightfully so. These parameters are collected in the trait SystemParameters. Normally you safely ignore these and expect they to 'the right thing' but given the fact that you have reached this page, you might want to start playing with them.

SystemParameters

As said at the page ActorContext, each instance of ActorContext is parameterized with some system parameters. The signature of the class is:

/** Trait to define the parameters needed for the context and platform classes to run. */
trait SystemParameters extends ContextParameters, PlatformParameters

with

/** Trait to define the parameters needed for the context classes to run. */
trait ContextParameters :
  /** The prefix used in actor names for actors that are workers */
  def workerPrefix: String

  /** The character that will be used in the full name definitions of the actors.*/
  def familyPathSeparator: Char

  /** Global maximum number of letters per mailbox. */
  def maxMailboxSize: Int

  /** The minimal number of poll loops (from the guard) for an actor to be considered silent. */
  def silentStop: Int

  /** Start all actors directly after construction. Eliminates the need for start(). */
  def autoStart: Boolean

and

/** Trait to define the parameters needed for the platform classes to run. */
trait PlatformParameters :

  /** The natural time the system pauses when there are no tasks. The use is platform dependent. */
  def idleThreadPause: FiniteDuration

  /** The average thread load per core. Override to change. This is only used on multithreaded platforms. */
  def threadsPerCore: Int

and the default implementation that is used is:

/**
 * Default parameters for the system you may use. If other values are needed, construct an instance
 * of your own and initialize the ActorImplementation with that. You may of course also write a
 * completely new ActorImplementation.  */
object DefaultSystem extends SystemParameters :
  val idleThreadPause: FiniteDuration = 10.millis
  val threadsPerCore: Int             = 4
  val workerPrefix: String            = "#"
  val familyPathSeparator: Char       = '.'
  val maxMailboxSize: Int             = Int.MaxValue
  val silentStop: Int                 = 3
  val autoStart: Boolean              = false

These values should be good for every day use, but feel free to experiment with them.

The way you would go about is:

  • Declare a new object that derives from SystemParameters
  • Define a new instance of ActorContext that uses these parameters
  • This this instance as a given in your own code.

For example, the new SystemParameters object could be

object MySystem extends SystemParameters :
  val idleThreadPause: FiniteDuration = 10.millis
  val threadsPerCore: Int             = 1           /* Allow only one thread per core */
  val workerPrefix: String            = "#"
  val familyPathSeparator: Char       = '.'
  val maxMailboxSize: Int             = 100         /* Not more than 100 messages in the box */
  val silentStop: Int                 = 3
  val autoStart: Boolean              = true        /* Compliant with your code written for version < 0.7 */

then the ActorContext implementation becomes:

val mySystem: ActorContext = ActorContext.DirectImplementation(MySystem)

and use it like:

given ActorContext = mySystem

Internals of an actor

Clone this wiki locally