Package berlin.yuna.natsserver.logic
Class Nats
- java.lang.Object
-
- berlin.yuna.natsserver.logic.Nats
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<NatsConfig,String>config()GetNatServerConfigNatsconfig(NatsConfig key, String value)Sets a single config valueNatsconfig(String... config)Passes the original parameters to the server on startupNatsconfig(Map<NatsConfig,String> config)Passes the original parameters to the server on startupprotected PathgetNatsServerPath(berlin.yuna.clu.logic.SystemUtil.OperatingSystem operatingSystem)Gets Nats server pathPathnatsPath()Gets Nats server pathintpid()get process idPathpidFile()intport()Gets the port out of the configurationNatsport(int port)Sets the port out of the configurationStringsource()Url to find nats server sourceNatssource(String natsServerUrl)Url to find nats server sourceNatsstart()Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)Natsstart(long timeoutMs)Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)Natsstop()Stops theProcessBuilderand kills theNatsOnly a log error will occur if theNatswere never startedNatsstop(long timeoutMs)Stops theProcessBuilderand kills theNatsOnly a log error will occur if theNatswere never startedStringtoString()NatstryStart()Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)Throws all exceptions asRuntimeExceptionNatstryStart(long timeoutMs)Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)Throws all exceptions asRuntimeExceptionstatic booleanwaitForPort(int port, long timeoutMs, boolean isFree)
-
-
-
Constructor Detail
-
Nats
public Nats()
CreateNatswithout any start able configuration
-
Nats
public Nats(int port)
CreateNatswith simplest start able configuration- Parameters:
port- start port - common default port is 4222
-
Nats
public Nats(String... config)
Create customNatswith simplest configurationconfig(String...)- Parameters:
config- passes the original parameters to the server. example: port:4222, user:admin, password:admin
-
-
Method Detail
-
config
public Map<NatsConfig,String> config()
GetNatServerConfig- Returns:
- the
Natsconfiguration
-
config
public Nats config(NatsConfig key, String value)
Sets a single config value- Returns:
- the
Natsconfiguration
-
config
public Nats config(Map<NatsConfig,String> config)
Passes the original parameters to the server on startup- Parameters:
config- passes the original parameters to the server.- Returns:
Nats- See Also:
config(String...),NatsConfig
-
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()
Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)Throws all exceptions asRuntimeException- Returns:
Nats
-
tryStart
public Nats tryStart(long timeoutMs)
Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)Throws all exceptions asRuntimeException- Parameters:
timeoutMs- defines the start up timeout-1no timeout, else waits until port up- Returns:
Nats
-
start
public Nats start() throws IOException
Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)- Returns:
Nats- Throws:
IOException- ifNatsis not found or unsupported on theSystemUtil.OperatingSystemBindException- if port is already takenPortUnreachableException- ifNatsis not starting cause port is not free
-
start
public Nats start(long timeoutMs) throws IOException
Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)- Parameters:
timeoutMs- defines the start up timeout-1no timeout, else waits until port up- Returns:
Nats- Throws:
IOException- ifNatsis not found or unsupported on theSystemUtil.OperatingSystemBindException- if port is already takenPortUnreachableException- ifNatsis not starting cause port is not free
-
stop
public Nats stop()
Stops theProcessBuilderand kills theNatsOnly a log error will occur if theNatswere never started- Returns:
Nats
-
stop
public Nats stop(long timeoutMs)
Stops theProcessBuilderand kills theNatsOnly a log error will occur if theNatswere never started- Parameters:
timeoutMs- defines the tear down timeout,-1no 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- withConnectExceptionwhen there is no port configured
-
port
public Nats port(int port)
Sets the port out of the configuration- Parameters:
port--1for random port- Returns:
Nats- Throws:
RuntimeException- withConnectExceptionwhen there is no port configured
-
source
public Nats source(String natsServerUrl)
Url to find nats server source- Parameters:
natsServerUrl- url of the sourceNatsSourceConfig- 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)
-
-