Package berlin.yuna.natsserver.logic
Class NatsStreaming
- java.lang.Object
-
- berlin.yuna.natsserver.logic.NatsStreaming
-
public class NatsStreaming extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
LOG
protected String
name
simpleName fromNatsStreaming
classprotected static berlin.yuna.clu.logic.SystemUtil.OperatingSystem
OPERATING_SYSTEM
protected static String
TMP_DIR
-
Constructor Summary
Constructors Constructor Description NatsStreaming()
CreateNatsStreaming
without any start able configurationNatsStreaming(int port)
CreateNatsStreaming
with simplest start able configurationNatsStreaming(String... config)
Create customNatsStreaming
with simplest configurationsetConfig(String...)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description NatsStreaming
config(NatsStreamingConfig key, String value)
Sets a single condig valueMap<NatsStreamingConfig,String>
getConfig()
GetNatServerConfigprotected Path
getNatsServerPath(berlin.yuna.clu.logic.SystemUtil.OperatingSystem operatingSystem)
Gets Nats server pathint
port()
Gets the port out of the configurationNatsStreaming
port(int port)
Sets the port out of the configurationNatsStreaming
setConfig(String... config)
Passes the original parameters to the server on startupNatsStreaming
setConfig(Map<NatsStreamingConfig,String> config)
Passes the original parameters to the server on startupString
source()
Url to find nats server sourceNatsStreaming
source(String natsServerUrl)
Url to find nats server sourceNatsStreaming
start()
Starts the server inProcessBuilder
with the given parameterConfigsetConfig(String...)
NatsStreaming
start(long timeoutMs)
Starts the server inProcessBuilder
with the given parameterConfigsetConfig(String...)
NatsStreaming
stop()
Stops theProcessBuilder
and kills theNatsStreaming
Only a log error will occur if theNatsStreaming
were never startedNatsStreaming
stop(long timeoutMs)
Stops theProcessBuilder
and kills theNatsStreaming
Only a log error will occur if theNatsStreaming
were never startedString
toString()
NatsStreaming
tryStart()
Starts the server inProcessBuilder
with the given parameterConfigsetConfig(String...)
Throws all exceptions asRuntimeException
NatsStreaming
tryStart(long timeoutMs)
Starts the server inProcessBuilder
with the given parameterConfigsetConfig(String...)
Throws all exceptions asRuntimeException
static boolean
waitForPort(int port, long timeoutMs, boolean isFree)
-
-
-
Field Detail
-
name
protected final String name
simpleName fromNatsStreaming
class
-
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
-
NatsStreaming
public NatsStreaming()
CreateNatsStreaming
without any start able configuration
-
NatsStreaming
public NatsStreaming(int port)
CreateNatsStreaming
with simplest start able configuration- Parameters:
port
--1
for random port
-
NatsStreaming
public NatsStreaming(String... config)
Create customNatsStreaming
with simplest configurationsetConfig(String...)
- Parameters:
config
- passes the original parameters to the server. example: port:4222, user:admin, password:admin
-
-
Method Detail
-
getConfig
public Map<NatsStreamingConfig,String> getConfig()
GetNatServerConfig- Returns:
- the
NatsStreaming
configuration
-
config
public NatsStreaming config(NatsStreamingConfig key, String value)
Sets a single condig value- Returns:
- the
NatsStreaming
configuration
-
setConfig
public NatsStreaming setConfig(Map<NatsStreamingConfig,String> config)
Passes the original parameters to the server on startup- Parameters:
config
- passes the original parameters to the server.- Returns:
NatsStreaming
- See Also:
setConfig(String...)
,NatsStreamingConfig
-
setConfig
public NatsStreaming setConfig(String... config)
Passes the original parameters to the server on startup- Parameters:
config
- example: port:4222, user:admin, password:admin- Returns:
NatsStreaming
- See Also:
NatsStreamingConfig
-
tryStart
public NatsStreaming tryStart()
Starts the server inProcessBuilder
with the given parameterConfigsetConfig(String...)
Throws all exceptions asRuntimeException
- Returns:
NatsStreaming
-
tryStart
public NatsStreaming tryStart(long timeoutMs)
Starts the server inProcessBuilder
with the given parameterConfigsetConfig(String...)
Throws all exceptions asRuntimeException
- Parameters:
timeoutMs
- defines the start up timeout-1
no timeout, else waits until port up- Returns:
NatsStreaming
-
start
public NatsStreaming start() throws IOException
Starts the server inProcessBuilder
with the given parameterConfigsetConfig(String...)
- Returns:
NatsStreaming
- Throws:
IOException
- ifNatsStreaming
is not found or unsupported on theSystemUtil.OperatingSystem
BindException
- if port is already takenPortUnreachableException
- ifNatsStreaming
is not starting cause port is not free
-
start
public NatsStreaming start(long timeoutMs) throws IOException
Starts the server inProcessBuilder
with the given parameterConfigsetConfig(String...)
- Parameters:
timeoutMs
- defines the start up timeout-1
no timeout, else waits until port up- Returns:
NatsStreaming
- Throws:
IOException
- ifNatsStreaming
is not found or unsupported on theSystemUtil.OperatingSystem
BindException
- if port is already takenPortUnreachableException
- ifNatsStreaming
is not starting cause port is not free
-
stop
public NatsStreaming stop()
Stops theProcessBuilder
and kills theNatsStreaming
Only a log error will occur if theNatsStreaming
were never started- Returns:
NatsStreaming
-
stop
public NatsStreaming stop(long timeoutMs)
Stops theProcessBuilder
and kills theNatsStreaming
Only a log error will occur if theNatsStreaming
were never started- Parameters:
timeoutMs
- defines the tear down timeout,-1
no timeout, else waits until port is free again- Returns:
NatsStreaming
-
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 NatsStreaming port(int port)
Sets the port out of the configuration- Parameters:
port
--1
for random port- Returns:
NatsStreaming
- Throws:
RuntimeException
- withConnectException
when there is no port configured
-
source
public NatsStreaming source(String natsServerUrl)
Url to find nats server source- Parameters:
natsServerUrl
- url of the sourceNatsStreamingSourceConfig
- Returns:
NatsStreaming
-
source
public String source()
Url to find nats server source
-
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)
-
-