Package eu.mihosoft.devcom
Interface DataConnection<T,V extends DataConnection<T,?>>
-
- All Superinterfaces:
java.lang.AutoCloseable
- All Known Implementing Classes:
COMPortConnection,StreamConnection
public interface DataConnection<T,V extends DataConnection<T,?>> extends java.lang.AutoCloseableData connection for reading and writing data. Applications include reading and writing from/to a stream, COM ports etc.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceDataConnection.SubscriptionListener subscription.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()DataFormat<T>getFormat()Returns the data format used by this connection.booleanisOpen()Indicates whether this connection is open.voidopen()Opens the connection.DataConnection.SubscriptionregisterDataListener(java.util.function.Consumer<T> l)Registers a data listener that is notified whenever a message has been received.VsetOnDataReceived(java.util.function.Consumer<T> onDataReceived)Sets the action to be executed if data has been received.VsetOnIOError(java.util.function.BiConsumer<V,java.lang.Exception> onIOError)Specifies the action to be performed if an I/O error occurs.voidwriteData(T msg)Writes the specified raw message to the output stream.
-
-
-
Method Detail
-
setOnDataReceived
V setOnDataReceived(java.util.function.Consumer<T> onDataReceived)
Sets the action to be executed if data has been received.- Parameters:
onDataReceived- consumer to be called if data has been received
-
setOnIOError
V setOnIOError(java.util.function.BiConsumer<V,java.lang.Exception> onIOError)
Specifies the action to be performed if an I/O error occurs.- Parameters:
onIOError- the action to be performed if an I/O error occurs
-
registerDataListener
DataConnection.Subscription registerDataListener(java.util.function.Consumer<T> l)
Registers a data listener that is notified whenever a message has been received.- Parameters:
l- the data listener to register- Returns:
- a subscription that allows a listener to be unsubscribed
-
writeData
void writeData(T msg) throws java.io.IOException
Writes the specified raw message to the output stream.- Parameters:
msg- the message to send- Throws:
java.io.IOException- if an i/o error occurs during message sending
-
getFormat
DataFormat<T> getFormat()
Returns the data format used by this connection.- Returns:
- the data format used by this connection
-
isOpen
boolean isOpen()
Indicates whether this connection is open.- Returns:
trueif this connection is currently open;falseotherwise
-
open
void open()
Opens the connection.
-
close
void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
-