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()CreateNatswithout any start able configurationNats(int port)CreateNatswith the simplest start able configurationNats(String... kv)Create customNatswith the simplest configurationconfig(String...)Nats(List<String> customArgs)CreateNatswith custom args
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Map<NatsConfig,MapValue>config()GetNatServerConfigNatsconfig(NatsConfig key, String value)Configures the nats serverNatsconfig(String... kv)Configures the nats serverNatsconfig(Map<NatsConfig,String> config)Configures the nats serverNatsstart()Starts the server inProcessBuilderwith the given configconfig(String...)Natsstart(long timeoutMs)Starts the server inProcessBuilderwith the given configconfig(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 startedNatstryStart()Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)Throws all exceptions asRuntimeExceptionNatstryStart(long timeoutMs)Starts the server inProcessBuilderwith 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()
CreateNatswithout any start able configuration
-
Nats
public Nats(int port)
CreateNatswith the simplest start able configuration- Parameters:
port- start port, -1 = random, default is 4222
-
Nats
public Nats(String... kv)
Create customNatswith 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
Natsconfiguration
-
config
public Nats config(NatsConfig key, String value)
Configures the nats server- Returns:
- the
Natsconfiguration
-
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 inProcessBuilderwith the given parameterConfigconfig(String...)Throws all exceptions asRuntimeException- Returns:
Nats
-
tryStart
public Nats tryStart(long timeoutMs)
Starts the server inProcessBuilderwith the given configconfig(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 Exception
Starts the server inProcessBuilderwith the given configconfig(String...)- Returns:
Nats- Throws:
IOException- ifNatsis not found or unsupported on theSystemUtilBindException- if port is already takenPortUnreachableException- ifNatsis not starting cause port is not freeException
-
start
public Nats start(long timeoutMs) throws Exception
Starts the server inProcessBuilderwith the given configconfig(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 theSystemUtilBindException- if port is already takenPortUnreachableException- ifNatsis not starting cause port is not freeException
-
close
public void close()
-
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
-
-