Class DefaultConfig

java.lang.Object
net.sodacan.core.config.DefaultConfig
All Implemented Interfaces:
Config

public class DefaultConfig extends Object implements Config
Default implementation of the Config interface.
See Also:
  • Constructor Details

    • DefaultConfig

      public DefaultConfig(BaseBuilder builder)

      Construct a configuration object. Many of the settings can be specified as functions. This allows some behavior in configuring the system. For example, the message "eviction" setting could change depending on time of day.

      In a clustered configuration, some of the configuration settings are shared among all hosts. In these cases, the parameter is described as "dynamic". On the other hand, some configuration settings are unique to a specific host. These settings are described as local. In a single host configuration, there is no difference between local and global settings.

      Parameters:
      builder - The builder object used to construct this configuration
  • Method Details

    • validate

      public void validate(BaseBuilder builder)
    • getHostNumber

      public int getHostNumber()

      Each host in the network has a unique number. This number is used to coordinate among multiple hosts in a network. The default is 1. Once assigned, a host number should be permanent. No duplicates.

      Specified by:
      getHostNumber in interface Config
      Returns:
      An integer containing the host number
    • getActorGroups

      public int getActorGroups()

      The number of actorGroups in a network is more or less fixed. Changing this number is difficult. The number must be consistent on all hosts in the cluster. As such, this setting is maintained by the coordinator.

      Specified by:
      getActorGroups in interface Config
      Returns:
      The number of actorGroups
    • getActorGroupReplicas

      public int getActorGroupReplicas()
      Specified by:
      getActorGroupReplicas in interface Config
    • getBackpressureLimit

      public int getBackpressureLimit()

      The number of messages inFlight before backpressure is applied. This limit can change at any time.

      Specified by:
      getBackpressureLimit in interface Config
      Returns:
    • getEviction

      public int getEviction()
      Specified by:
      getEviction in interface Config
    • getActorGroupAssigner

      public ActorGroupAssigner getActorGroupAssigner()
      Specified by:
      getActorGroupAssigner in interface Config
    • createMessageId

      public MessageId createMessageId()
      Specified by:
      createMessageId in interface Config
    • createMessage

      public Message createMessage()
      Specified by:
      createMessage in interface Config
    • createActorId

      public ActorId createActorId(String actorType)
      Specified by:
      createActorId in interface Config
    • getActorGroupThreads

      public int getActorGroupThreads()
      Local static Return the current number of threads
      Specified by:
      getActorGroupThreads in interface Config
      Returns:
    • getCoordinator

      public Coordinator getCoordinator()
      Specified by:
      getCoordinator in interface Config
    • getHost

      public Host getHost()

      Return the singleton host for this application instance

      Specified by:
      getHost in interface Config
      Returns:
    • getClock

      public Clock getClock()
      Description copied from interface: Config

      Return the clock used throuhout the system. Usually the default is adequate except for testing.

      Specified by:
      getClock in interface Config
      Returns:
      The Clock
    • now

      public Instant now()
      Description copied from interface: Config
      Return the current instant of the configured clock.
      Specified by:
      now in interface Config
      Returns:
      an Instant
    • getRandom

      public Random getRandom()
      Description copied from interface: Config
      Get a Random Number Generator. The default implementation uses ThreadLocalRandom which is bound to the local Thread. Therefore, it is best to only use the result of this call on the stack. Or, at least don't use the returned generator from more than one thread.
      Specified by:
      getRandom in interface Config
      Returns:
      an instance of Random
    • createActorGroup

      public ActorGroup createActorGroup(int actorGroupNumber)
      Create a actorGroup.
      Specified by:
      createActorGroup in interface Config
      Returns:
    • createScheduler

      public Scheduler createScheduler(ActorGroup actorGroup)

      Create a new scheduler. The function is a factory for creating schedulers.

      Specified by:
      createScheduler in interface Config
      Returns:
      The new Scheduler subclass
    • getBackpressureWaitMs

      public int getBackpressureWaitMs()
      Specified by:
      getBackpressureWaitMs in interface Config
    • getShutdownWaitMs

      public int getShutdownWaitMs()
      Specified by:
      getShutdownWaitMs in interface Config
    • getProperty

      public String getProperty(String name)
      Specified by:
      getProperty in interface Config
    • getRootDirectory

      public String getRootDirectory()
      Description copied from interface: Config
      Get the root directory for this host. Local/Status
      Specified by:
      getRootDirectory in interface Config
      Returns:
    • getActorClass

      public Class<? extends Actor> getActorClass(String actorType)
      Get the class associated with an ActorType which is either a string assigned to the actor by the ActorType annotation or the full class name.
      Specified by:
      getActorClass in interface Config
      Parameters:
      actorType - string
      Returns:
      Either null or the Actor class, suitable to use to instantiate that actor.
    • getSerializerFactory

      public SerializerFactory getSerializerFactory()
      Description copied from interface: Config
      The SerializerFactory is instantiated during configuration
      Specified by:
      getSerializerFactory in interface Config
      Returns:
    • getPersisterFactory

      public PersisterFactory getPersisterFactory()
      Description copied from interface: Config
      The PersisterFactory provides access to persistent services for an Actor. The Factory is instantiated during configuration. The factory implementation can decide during construction how it will handle requests for multiple Actor threads.
      Specified by:
      getPersisterFactory in interface Config
      Returns:
      PersisterFactory implementation.
    • getActorMetadata

      public ActorMetadata getActorMetadata(String actorType)
      Description copied from interface: Config
      Static. We need to keep ActorMetadata along with the ActorClass.
      Specified by:
      getActorMetadata in interface Config
    • getActorTypes

      public List<String> getActorTypes()
      Return all of the actorClasses that we know of
      Specified by:
      getActorTypes in interface Config
      Returns:
    • getHostBoundActorTypes

      public List<String> getHostBoundActorTypes()
      Description copied from interface: Config
      Return a list of host-bound actor types
      Specified by:
      getHostBoundActorTypes in interface Config
      Returns:
    • createActor

      public Actor createActor(ActorId actorId)
      Specified by:
      createActor in interface Config
    • printConfig

      public void printConfig(PrintStream out)
      Send a list of actorType names and actor class name pairs
      Specified by:
      printConfig in interface Config
      Parameters:
      out -
    • listActors

      public void listActors(PrintStream out)
      Send a list of actorType names and actor class name pairs
      Specified by:
      listActors in interface Config
      Parameters:
      out -