Package de.julielab.ipc.javabridge
Class Options<O>
- java.lang.Object
-
- de.julielab.ipc.javabridge.Options<O>
-
- Type Parameters:
O- The class of the received messages. EitherStringor byte[].
public class Options<O> extends java.lang.ObjectThis is class is a simple container for options given to the constructor ofStdioBridge. The meaning of each option is explained at its setter method.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetExecutable()java.lang.StringgetExternalProgramReadySignal()java.lang.StringgetExternalProgramTerminationSignal()java.lang.StringgetMultilineResponseDelimiter()java.util.function.Predicate<O>getResultLineIndicator()java.util.function.Function<O,O>getResultReshaper()java.lang.Class<O>getResultType()java.lang.StringgetTerminationSignalFromErrorStream()booleanisGzipReceivedData()booleanisGzipSentData()voidsetExecutable(java.lang.String executable)The name of the external program to execute.voidsetExternalProgramReadySignal(java.lang.String externalProgramReadySignal)voidsetExternalProgramTerminationSignal(java.lang.String externalProgramTerminationSignal)To gracefully terminate the external process, some signal likequitorexitcould be accepted by the external program as signal to end the application.voidsetGzipReceivedData(boolean gzipReceivedData)Whether or not the data received from the external program should be decompressed from GZIP format or left untouched.voidsetGzipSentData(boolean gzipSentData)Whether or not the data sent to the external program should be compressed in GZIP format or left untouched.voidsetMultilineResponseDelimiter(java.lang.String multilineResponseDelimiter)If the external program may respond with multiple lines perStdioBridge.send(String)call, there must be a signal to indicate that the response is complete.voidsetResultLineIndicator(java.util.function.Predicate<O> resultLineIndicator)APredicatethat is used to find the actual output lines of the external program.voidsetResultReshaper(java.util.function.Function<O,O> resultReshaper)The result reshaper is a method that takes the received line from the external process and transforms it into the final format.voidsetTerminationSignalFromErrorStream(java.lang.String terminationSignalFromErrorStream)
-
-
-
Constructor Detail
-
Options
public Options(java.lang.Class<O> resultType)
-
-
Method Detail
-
getTerminationSignalFromErrorStream
public java.lang.String getTerminationSignalFromErrorStream()
-
setTerminationSignalFromErrorStream
public void setTerminationSignalFromErrorStream(java.lang.String terminationSignalFromErrorStream)
-
getExternalProgramReadySignal
public java.lang.String getExternalProgramReadySignal()
-
setExternalProgramReadySignal
public void setExternalProgramReadySignal(java.lang.String externalProgramReadySignal)
-
isGzipSentData
public boolean isGzipSentData()
-
setGzipSentData
public void setGzipSentData(boolean gzipSentData)
Whether or not the data sent to the external program should be compressed in GZIP format or left untouched. This should be left at false because the compression introduces a large time overhead.- Parameters:
gzipSentData- If the sent data should be compressed.
-
isGzipReceivedData
public boolean isGzipReceivedData()
-
setGzipReceivedData
public void setGzipReceivedData(boolean gzipReceivedData)
Whether or not the data received from the external program should be decompressed from GZIP format or left untouched. This should be left at false, if possible, because the compression introduces a large time overhead.- Parameters:
gzipReceivedData- If the received data should be decompressed.
-
getResultType
public java.lang.Class<O> getResultType()
-
setResultReshaper
public void setResultReshaper(java.util.function.Function<O,O> resultReshaper)
The result reshaper is a method that takes the received line from the external process and transforms it into the final format. This is used to remove markers on the input line that indicate the line to be a result line in contrast to other program output. For example, lines could be prefixed withOutput:to indicate lines that are meant for the Java program to read.- Parameters:
resultReshaper- The result reshaper.
-
getExecutable
public java.lang.String getExecutable()
-
setExecutable
public void setExecutable(java.lang.String executable)
The name of the external program to execute. For Python programs this would bypython, for example, or even another version specific path like/usr/local/bin/python36.- Parameters:
executable- The path to the executable for the external program.
-
getResultLineIndicator
public java.util.function.Predicate<O> getResultLineIndicator()
-
setResultLineIndicator
public void setResultLineIndicator(java.util.function.Predicate<O> resultLineIndicator)
APredicatethat is used to find the actual output lines of the external program. This is useful when the external process might output not only result lines meant to receive by the Java side but also other messages. Then, the external program could indicate lines to actually be received with a prefix likeResult:, for example. The predicate would then need to recognize lines beginning with this prefix to filter out undesired lines. No predicate has to be defined. However, without a predicate, the external program is only allowed to output exactly one line per request. Otherwise, we might miss the actual data lines we are interested in because we can never know when the external process has sent all data. With the predicate set, we will wait for eachStdioBridge.receive()call for the next line to occur that is accepted by the predicate.- Parameters:
resultLineIndicator- A predicate to filter output lines, may be null.
-
getExternalProgramTerminationSignal
public java.lang.String getExternalProgramTerminationSignal()
-
setExternalProgramTerminationSignal
public void setExternalProgramTerminationSignal(java.lang.String externalProgramTerminationSignal)
To gracefully terminate the external process, some signal likequitorexitcould be accepted by the external program as signal to end the application. If such a signal is accepted, provide it here. It is sent to the external process onStdioBridge.stop().- Parameters:
externalProgramTerminationSignal- A string that signals the external process to end.
-
getMultilineResponseDelimiter
public java.lang.String getMultilineResponseDelimiter()
-
setMultilineResponseDelimiter
public void setMultilineResponseDelimiter(java.lang.String multilineResponseDelimiter)
If the external program may respond with multiple lines perStdioBridge.send(String)call, there must be a signal to indicate that the response is complete. This signal is the multilineResponseDelimiter. Setting this field does activate the possibility to receive multiple lines of response for a single request.- Parameters:
multilineResponseDelimiter-
-
-