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.AutoCloseable
Data 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 interface
DataConnection.Subscription
Listener subscription.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
DataFormat<T>
getFormat()
Returns the data format used by this connection.boolean
isOpen()
Indicates whether this connection is open.void
open()
Opens the connection.DataConnection.Subscription
registerDataListener(java.util.function.Consumer<T> l)
Registers a data listener that is notified whenever a message has been received.V
setOnDataReceived(java.util.function.Consumer<T> onDataReceived)
Sets the action to be executed if data has been received.V
setOnIOError(java.util.function.BiConsumer<V,java.lang.Exception> onIOError)
Specifies the action to be performed if an I/O error occurs.void
writeData(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:
true
if this connection is currently open;false
otherwise
-
open
void open()
Opens the connection.
-
close
void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-