Package io.mats3

Interface MatsFactory.FactoryConfig

All Superinterfaces:
MatsConfig
Enclosing interface:
MatsFactory

public static interface MatsFactory.FactoryConfig extends MatsConfig
Provides for a way to configure factory-wide elements and defaults.
  • Method Details

    • setName

      Sets the name of the MatsFactory, default is "" (empty string).
      Parameters:
      name - the name that the MatsFactory should have.
    • getName

      String getName()
      Returns:
      the name of the MatsFactory, as set by setName(String), shall return "" (empty string) if not set, never null.
    • getNumberOfCpus

      int getNumberOfCpus()
      Returns:
      the number of CPUs that Mats shall assume there is available. Default should be Runtime.getRuntime().availableProcessors(). Implementations should honor the System Property "mats.cpus" and let that override this number, e.g. "-Dmats.cpus=8" on command line.
    • setInitiateTraceIdModifier

      MatsFactory.FactoryConfig setInitiateTraceIdModifier(Function<String,String> modifier)
      Sets a Function that may modify the TraceId of Mats flows that are initiated "from the outside", i.e. not from within a Stage. The intended use is to automatically prefix the Mats flow TraceId with some sort of contextual request id, typically when the Mats flow is initiated in a HTTP/REST context where the incoming request carries a "X-Request-ID" or "X-Correlation-ID" header. The idea is then that this header is picked out in some form of filter, placed in some ThreadLocal context, and then prepended to the TraceId that the Mats flow is initiated with using the provided function. For example, if the the HTTP Request has a X-Request-ID of "abc", and the Mats flow is initiated with TraceId "123", the resulting TraceId for the Mats flow would be "abc+123" (the plus character being the preferred separator for composed TraceIds, i.e. TraceIds that are put together by successively more specific information).

      The Function gets the entire user provided TraceId as input (as set via MatsInitiator.MatsInitiate.traceId(CharSequence), and should return a fully formed TraceId that should be used instead. Needless to say, it should never throw, and if it doesn't have any contextual id to prefix with, it should return whatever that was passed into it.

      Parameters:
      modifier - the function that accepts the TraceId that the Mats flow is initiated with, and returns the TraceId that the Mats flow should actually get.
      Returns:
      this for chaining.
    • setMatsDestinationPrefix

      MatsFactory.FactoryConfig setMatsDestinationPrefix(String prefix)
      Sets the prefix that should be applied to the endpointIds to get queue or topic name in the underlying messaging system - the default is "mats.". Needless to say, two MatsFactories which are configured differently here will not be able to communicate. Do not change this unless you have a compelling reason to why, as you then stray away from the standard, and it will be harder to later merge two setups.
      Parameters:
      prefix - the prefix that should be applied to the endpointIds to get queue or topic name in the underlying messaging system. Default is "mats.".
      Returns:
      this for chaining.
    • getMatsDestinationPrefix

      String getMatsDestinationPrefix()
      Returns:
      the prefix that is applied to endpointIds to get the queue and topic and topic names. Defaults to "mats.".
    • setMatsTraceKey

      MatsFactory.FactoryConfig setMatsTraceKey(String key)
      Sets the key name on which to store the "wire representation" of the Mats message if the underlying mechanism uses some kind of Map - the default is "mats:trace". (The JMS Implementation uses a JMS MapMessage, and this is the key). Needless to say, two MatsFactories which are configured differently here will not be able to communicate. Do not change this unless you have a compelling reason to why, as you then stray away from the standard, and it will be harder to later merge two setups.
      Parameters:
      key - the key name on which to store the "wire representation" of the Mats message if the underlying mechanism uses some kind of Map. Default is "mats:trace".
      Returns:
      this for chaining.
    • getMatsTraceKey

      String getMatsTraceKey()
      Returns:
      the key name on which to store the "wire representation" of the Mats message if the underlying mechanism uses some kind of Map. (The JMS Implementation uses a JMS MapMessage, and this is the key). Default is "mats:trace".
    • getAppName

      String getAppName()
      Returns:
      the name of the application/service that employs MATS, set at MatsFactory construction time.
    • getAppVersion

      String getAppVersion()
      Returns:
      the version string of the application/service that employs MATS, set at MatsFactory construction time.
    • setNodename

      MatsFactory.FactoryConfig setNodename(String nodename)
      Sets the nodename that getNodename() should return. This is not necessary if the current hosts's hostname is a good enough nodename (which it in a normal production system should be, both running on iron, VMs and containers like Docker or Kubernetes), as that is what is returned by the getter by default. Must be set before anything that depends on the return value of getNodename() is started, i.e. right away after having created the MatsFactory instance.
      Parameters:
      nodename - the nodename that this MatsFactory should report from getNodename().
      Returns:
      this for chaining.
    • getNodename

      String getNodename()
      Returns a node-specific identifier, that is, a name which is different between different instances of the same app running of different nodes. This can be used to make node-specific topics, which are nice when you need a message to return to the node that sent it, due to some synchronous process waiting for the message (which entirely defeats the Messaging Oriented Middleware Architecture, but sometimes you need a solution..). This string is used for such a purpose in the MatsFuturizer tool and the "MatsSockets" WebSocket system. The nodename is also used by the MatsTrace "wire protocol" as debug information. It is not used by any Mats-internal parts.
      Returns:
      the nodename, which by default should be the hostname which the application is running on.
    • getMatsImplementationName

      String getMatsImplementationName()
      Returns:
      the Mats Implementation name.
    • getMatsImplementationVersion

      String getMatsImplementationVersion()
      Returns:
      the Mats Implementation version.
    • instantiateNewObject

      <T> T instantiateNewObject(Class<T> type)
      This method is only relevant for tooling, and thus "hidden away" in this config class. It uses the MatsFactory-configured deserializer mechanism to instantiate the specified class. The rationale for this is to either test whether a STO (State Transfer Object) or a DTO (Data Transfer Object) actually can be instantiated (if e.g. Jackson is used as serialization mechanism, which is default for the "MatsTrace" implementation, it needs a no-args constructor to be able to instantiate, while if using GSON - which employs "Objenesis" for instantiation - a non-args constructor is not necessary) - or to just get hold of a new instance to do some kind of introspection (this is e.g. needed for Mats' SpringConfig when using @MatsClassMapping).
      Type Parameters:
      T - the type of the Class.
      Parameters:
      type - the Class that should be instantiated.
      Returns:
      a new instance
      Throws:
      RuntimeException - if the class could not be instantiated (e.g. lacking no-args constructor which can be an issue depending on the serialization mechanism).
    • setAttribute

      MatsFactory.FactoryConfig setAttribute(String key, Object value)
      Description copied from interface: MatsConfig
      Sets an attribute for this entity (factory, endpoint, stage) - can e.g. be used by tooling or interceptors. If the value is null, the mapping for the specified key is cleared.
      Specified by:
      setAttribute in interface MatsConfig
      Parameters:
      key - the key name for this attribute. Not null.
      value - the value for this attribute. If the value is null, the mapping for the specified key is cleared.
      Returns:
      the config object, for method chaining.
    • setConcurrency

      MatsFactory.FactoryConfig setConcurrency(int concurrency)
      Description copied from interface: MatsConfig
      Changes the default concurrency of the Factory, or of the endpoint (which defaults to the concurrency of the MatsFactory), or of the process stage (which defaults to the concurrency of the MatsEndpoint).

      Will only have effect before the MatsStage is started. Can be reset by stopping, setting, and restarting.

      Setting to 0 will invoke default logic.

      Specified by:
      setConcurrency in interface MatsConfig
      Parameters:
      concurrency - the concurrency for the Factory, or Endpoint, or Stage. If set to 0, default-logic is in effect.
      Returns:
      the config object, for method chaining.
      See Also:
    • setInteractiveConcurrency

      MatsFactory.FactoryConfig setInteractiveConcurrency(int concurrency)
      Description copied from interface: MatsConfig
      Like MatsConfig.setConcurrency(int), but changes the "interactive concurrency" specifically - this is relevant for the Mats Flows that are initiated with the interactive flag set.
      Specified by:
      setInteractiveConcurrency in interface MatsConfig
      Parameters:
      concurrency - the interactive concurrency for the Factory, or Endpoint, or Stage. If set to 0, default-logic is in effect.
      Returns:
      the config object, for method chaining.
      See Also: