Class Nats


  • public class Nats
    extends Object
    Since:
    1.0
    Author:
    Yuna Morgenstern
    See Also:
    SystemUtil.OperatingSystem, Nats
    • Field Detail

      • pid

        protected int pid
        simpleName from Nats class
      • name

        protected final String name
      • LOG

        protected static final org.slf4j.Logger LOG
      • OPERATING_SYSTEM

        protected static final berlin.yuna.clu.logic.SystemUtil.OperatingSystem OPERATING_SYSTEM
      • TMP_DIR

        protected static final String TMP_DIR
    • Constructor Detail

      • Nats

        public Nats()
        Create Nats without any start able configuration
      • Nats

        public Nats​(int port)
        Create Nats with simplest start able configuration
        Parameters:
        port - start port - common default port is 4222
      • Nats

        public Nats​(String... config)
        Create custom Nats with simplest configuration config(String...)
        Parameters:
        config - passes the original parameters to the server. example: port:4222, user:admin, password:admin
    • Method Detail

      • config

        public Nats config​(NatsConfig key,
                           String value)
        Sets a single config value
        Returns:
        the Nats configuration
      • config

        public Nats config​(String... config)
        Passes the original parameters to the server on startup
        Parameters:
        config - example: port:4222, user:admin, password:admin
        Returns:
        Nats
        See Also:
        NatsConfig
      • tryStart

        public Nats tryStart​(long timeoutMs)
        Starts the server in ProcessBuilder with the given parameterConfig config(String...) Throws all exceptions as RuntimeException
        Parameters:
        timeoutMs - defines the start up timeout -1 no timeout, else waits until port up
        Returns:
        Nats
      • stop

        public Nats stop​(long timeoutMs)
        Stops the ProcessBuilder and kills the Nats Only a log error will occur if the Nats were never started
        Parameters:
        timeoutMs - defines the tear down timeout, -1 no timeout, else waits until port is free again
        Returns:
        Nats
      • port

        public int port()
        Gets the port out of the configuration
        Returns:
        configured port of the server
        Throws:
        RuntimeException - with ConnectException when there is no port configured
      • port

        public Nats port​(int port)
        Sets the port out of the configuration
        Parameters:
        port - -1 for random port
        Returns:
        Nats
        Throws:
        RuntimeException - with ConnectException when there is no port configured
      • source

        public Nats source​(String natsServerUrl)
        Url to find nats server source
        Parameters:
        natsServerUrl - url of the source NatsSourceConfig
        Returns:
        Nats
      • source

        public String source()
        Url to find nats server source
      • pid

        public int pid()
        get process id
        Returns:
        process id from nats server
      • pidFile

        public Path pidFile()
      • natsPath

        public Path natsPath()
        Gets Nats server path
        Returns:
        Resource/{SIMPLE_CLASS_NAME}/{NATS_SERVER_VERSION}/{OPERATING_SYSTEM}/{SIMPLE_CLASS_NAME}
      • getNatsServerPath

        protected Path getNatsServerPath​(berlin.yuna.clu.logic.SystemUtil.OperatingSystem operatingSystem)
        Gets Nats server path
        Returns:
        Resource/{SIMPLE_CLASS_NAME}/{NATS_SERVER_VERSION}/{OPERATING_SYSTEM}/{SIMPLE_CLASS_NAME}
      • waitForPort

        public static boolean waitForPort​(int port,
                                          long timeoutMs,
                                          boolean isFree)