Package berlin.yuna.natsserver.logic
Class Nats
- java.lang.Object
-
- berlin.yuna.natsserver.logic.NatsBase
-
- berlin.yuna.natsserver.logic.Nats
-
- All Implemented Interfaces:
AutoCloseable
public class Nats extends NatsBase
- Since:
- 1.0
- Author:
- Yuna Morgenstern
- See Also:
SystemUtil
,Nats
-
-
Field Summary
-
Fields inherited from class berlin.yuna.natsserver.logic.NatsBase
NATS_PREFIX
-
-
Constructor Summary
Constructors Constructor Description Nats()
CreateNats
without any start able configurationNats(int port)
CreateNats
with the simplest start able configurationNats(String... kv)
Create customNats
with the simplest configurationconfig(String...)
Nats(List<String> customArgs)
CreateNats
with custom args
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Map<NatsConfig,MapValue>
config()
GetNatServerConfigNats
config(NatsConfig key, String value)
Configures the nats serverNats
config(String... kv)
Configures the nats serverNats
config(Map<NatsConfig,String> config)
Configures the nats serverNats
start()
Starts the server inProcessBuilder
with the given configconfig(String...)
Nats
start(long timeoutMs)
Starts the server inProcessBuilder
with the given configconfig(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 startedNats
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 configconfig(String...)
Throws all exceptions asRuntimeException
-
Methods inherited from class berlin.yuna.natsserver.logic.NatsBase
args, args, binaryFile, downloadUrl, getConfigFile, getValue, getValue, pid, pidFile, port, toString, url
-
-
-
-
Constructor Detail
-
Nats
public Nats()
CreateNats
without any start able configuration
-
Nats
public Nats(int port)
CreateNats
with the simplest start able configuration- Parameters:
port
- start port, -1 = random, default is 4222
-
Nats
public Nats(String... kv)
Create customNats
with the simplest configurationconfig(String...)
- Parameters:
kv
- passes the original parameters to the server. example: port:4222, user:admin, password:admin
-
-
Method Detail
-
config
public Map<NatsConfig,MapValue> config()
GetNatServerConfig- Returns:
- the
Nats
configuration
-
config
public Nats config(NatsConfig key, String value)
Configures the nats server- Returns:
- the
Nats
configuration
-
config
public Nats config(Map<NatsConfig,String> config)
Configures the nats server- Parameters:
config
- passes the original parameters to the server.- Returns:
Nats
- See Also:
config(String...)
,NatsConfig
-
config
public Nats config(String... kv)
Configures the nats server- Parameters:
kv
- 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 configconfig(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 Exception
Starts the server inProcessBuilder
with the given configconfig(String...)
- Returns:
Nats
- Throws:
IOException
- ifNats
is not found or unsupported on theSystemUtil
BindException
- if port is already takenPortUnreachableException
- ifNats
is not starting cause port is not freeException
-
start
public Nats start(long timeoutMs) throws Exception
Starts the server inProcessBuilder
with the given configconfig(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
BindException
- if port is already takenPortUnreachableException
- ifNats
is not starting cause port is not freeException
-
close
public void close()
-
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
-
-