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.LoggerLOGprotected Stringnameprotected static berlin.yuna.clu.logic.SystemUtil.OperatingSystemOPERATING_SYSTEMprotected intpidsimpleName fromNatsStreamingclassprotected static StringTMP_DIR
-
Constructor Summary
Constructors Constructor Description NatsStreaming()CreateNatsStreamingwithout any start able configurationNatsStreaming(int port)CreateNatsStreamingwith simplest start able configurationNatsStreaming(String... config)Create customNatsStreamingwith simplest configurationconfig(String...)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<NatsStreamingConfig,String>config()GetNatServerConfigNatsStreamingconfig(NatsStreamingConfig key, String value)Sets a single config valueNatsStreamingconfig(String... config)Passes the original parameters to the server on startupNatsStreamingconfig(Map<NatsStreamingConfig,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 configurationNatsStreamingport(int port)Sets the port out of the configurationStringsource()Url to find nats server sourceNatsStreamingsource(String natsServerUrl)Url to find nats server sourceNatsStreamingstart()Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)NatsStreamingstart(long timeoutMs)Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)NatsStreamingstop()Stops theProcessBuilderand kills theNatsStreamingOnly a log error will occur if theNatsStreamingwere never startedNatsStreamingstop(long timeoutMs)Stops theProcessBuilderand kills theNatsStreamingOnly a log error will occur if theNatsStreamingwere never startedStringtoString()NatsStreamingtryStart()Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)Throws all exceptions asRuntimeExceptionNatsStreamingtryStart(long timeoutMs)Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)Throws all exceptions asRuntimeExceptionstatic booleanwaitForPort(int port, long timeoutMs, boolean isFree)
-
-
-
Field Detail
-
pid
protected int pid
simpleName fromNatsStreamingclass
-
name
protected final String name
-
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()
CreateNatsStreamingwithout any start able configuration
-
NatsStreaming
public NatsStreaming(int port)
CreateNatsStreamingwith simplest start able configuration- Parameters:
port--1for random port
-
NatsStreaming
public NatsStreaming(String... config)
Create customNatsStreamingwith simplest configurationconfig(String...)- Parameters:
config- passes the original parameters to the server. example: port:4222, user:admin, password:admin
-
-
Method Detail
-
config
public Map<NatsStreamingConfig,String> config()
GetNatServerConfig- Returns:
- the
NatsStreamingconfiguration
-
config
public NatsStreaming config(NatsStreamingConfig key, String value)
Sets a single config value- Returns:
- the
NatsStreamingconfiguration
-
config
public NatsStreaming config(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:
config(String...),NatsStreamingConfig
-
config
public NatsStreaming config(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 inProcessBuilderwith the given parameterConfigconfig(String...)Throws all exceptions asRuntimeException- Returns:
NatsStreaming
-
tryStart
public NatsStreaming 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:
NatsStreaming
-
start
public NatsStreaming start() throws IOException
Starts the server inProcessBuilderwith the given parameterConfigconfig(String...)- Returns:
NatsStreaming- Throws:
IOException- ifNatsStreamingis not found or unsupported on theSystemUtil.OperatingSystemBindException- if port is already takenPortUnreachableException- ifNatsStreamingis not starting cause port is not free
-
start
public NatsStreaming 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:
NatsStreaming- Throws:
IOException- ifNatsStreamingis not found or unsupported on theSystemUtil.OperatingSystemBindException- if port is already takenPortUnreachableException- ifNatsStreamingis not starting cause port is not free
-
stop
public NatsStreaming stop()
Stops theProcessBuilderand kills theNatsStreamingOnly a log error will occur if theNatsStreamingwere never started- Returns:
NatsStreaming
-
stop
public NatsStreaming stop(long timeoutMs)
Stops theProcessBuilderand kills theNatsStreamingOnly a log error will occur if theNatsStreamingwere never started- Parameters:
timeoutMs- defines the tear down timeout,-1no 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- withConnectExceptionwhen there is no port configured
-
port
public NatsStreaming port(int port)
Sets the port out of the configuration- Parameters:
port--1for random port- Returns:
NatsStreaming- Throws:
RuntimeException- withConnectExceptionwhen 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
-
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)
-
-