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()
GetNatServerConfigNats
config(NatsConfig key, String value)
Sets a single config valueNats
config(String... config)
Passes the original parameters to the server on startupNats
config(Map<NatsConfig,String> config)
Passes the original parameters to the server on startupprotected Path
getNatsServerPath(berlin.yuna.clu.logic.SystemUtil.OperatingSystem operatingSystem)
Gets Nats server pathPath
natsPath()
Gets Nats server pathint
pid()
get process idPath
pidFile()
int
port()
Gets the port out of the configurationNats
port(int port)
Sets the port out of the configurationString
source()
Url to find nats server sourceNats
source(String natsServerUrl)
Url to find nats server sourceNats
start()
Starts the server inProcessBuilder
with the given parameterConfigconfig(String...)
Nats
start(long timeoutMs)
Starts the server inProcessBuilder
with the given parameterConfigconfig(String...)
Nats
stop()
Stops theProcessBuilder
and kills theNats
Only a log error will occur if theNats
were never startedNats
stop(long timeoutMs)
Stops theProcessBuilder
and kills theNats
Only a log error will occur if theNats
were never startedString
toString()
Nats
tryStart()
Starts the server inProcessBuilder
with the given parameterConfigconfig(String...)
Throws all exceptions asRuntimeException
Nats
tryStart(long timeoutMs)
Starts the server inProcessBuilder
with the given parameterConfigconfig(String...)
Throws all exceptions asRuntimeException
static boolean
waitForPort(int port, long timeoutMs, boolean isFree)
-
-
-
Constructor Detail
-
Nats
public Nats()
CreateNats
without any start able configuration
-
Nats
public Nats(int port)
CreateNats
with simplest start able configuration- Parameters:
port
- start port - common default port is 4222
-
Nats
public Nats(String... config)
Create customNats
with 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
Nats
configuration
-
config
public Nats config(NatsConfig key, String value)
Sets a single config value- Returns:
- the
Nats
configuration
-
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 inProcessBuilder
with the given parameterConfigconfig(String...)
Throws all exceptions asRuntimeException
- Returns:
Nats
-
tryStart
public Nats tryStart(long timeoutMs)
Starts the server inProcessBuilder
with the given parameterConfigconfig(String...)
Throws all exceptions asRuntimeException
- Parameters:
timeoutMs
- defines the start up timeout-1
no timeout, else waits until port up- Returns:
Nats
-
start
public Nats start() throws IOException
Starts the server inProcessBuilder
with the given parameterConfigconfig(String...)
- Returns:
Nats
- Throws:
IOException
- ifNats
is not found or unsupported on theSystemUtil.OperatingSystem
BindException
- if port is already takenPortUnreachableException
- ifNats
is not starting cause port is not free
-
start
public Nats start(long timeoutMs) throws IOException
Starts the server inProcessBuilder
with the given parameterConfigconfig(String...)
- Parameters:
timeoutMs
- defines the start up timeout-1
no timeout, else waits until port up- Returns:
Nats
- Throws:
IOException
- ifNats
is not found or unsupported on theSystemUtil.OperatingSystem
BindException
- if port is already takenPortUnreachableException
- ifNats
is not starting cause port is not free
-
stop
public Nats stop()
Stops theProcessBuilder
and kills theNats
Only a log error will occur if theNats
were never started- Returns:
Nats
-
stop
public Nats stop(long timeoutMs)
Stops theProcessBuilder
and kills theNats
Only a log error will occur if theNats
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
- withConnectException
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
- withConnectException
when 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)
-
-