Class SmfConnection
- All Implemented Interfaces:
com.blackhillsoftware.common.interfaces.Emptyable
,Closeable
,AutoCloseable
,Iterable<byte[]>
Create the SmfConnection using
SmfConnection.forResourceName(String)
to get a SmfConnection.Connectable
, set connection options as required and call
connect()
.
This class implements Closeable and should be used with a try-with-resources block to ensure that the connection is closed when it exits.
try (SmfConnection connection = SmfConnection.forResourceName("IFASMF.MYRECS") .disconnectOnStop() .connect()) { for (byte[] smfRecord : connection) { // process smfRecord } }
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Class used to set options for the SmfConnection prior to connection to the in memory resource. -
Method Summary
Modifier and TypeMethodDescriptionabstract void
close()
Close the connection.static SmfConnection.Connectable
forResourceName
(String name) Create a Connectable object for a SMF In Memory Resource name.Get the name of the resource for this connectionboolean
isEmpty()
Return true if the internal queue of SMF records is empty and the next record will be read from the in memory resource, potentially waiting until a record is written.Iterator<byte[]>
iterator()
Get a SMF record Iterator.boolean
Deprecated.static List<InMemoryResource>
query()
Query the list of SMF in memory resources defined to the systembyte[]
read()
Read a record, waiting if necessary.Spliterator<byte[]>
Get a Spliterator for the records from the SMF connection.Stream<byte[]>
stream()
Get a Java Stream to read SmfRecords as byte arrays from the in memory resource.
-
Method Details
-
query
Query the list of SMF in memory resources defined to the system- Returns:
- a list of SMF In Memory Resources
- Throws:
IOException
- if an error occurs getting the list of resources- See Also:
-
forResourceName
Create a Connectable object for a SMF In Memory Resource name. Callconnect()
to return a usable SmfConnection object or callonMissedData(Consumer)
to setup missed data handling.- Parameters:
name
- the name of the in memory resource.- Returns:
- Connectable the object ready to connect.
-
read
Read a record, waiting if necessary.- Returns:
- a record, or null if the connection has been closed.
- Throws:
IOException
- if an error occurs reading the record
-
stream
Get a Java Stream to read SmfRecords as byte arrays from the in memory resource.- Returns:
- Stream<byte[]>
- See Also:
-
iterator
Get a SMF record Iterator. Each SMF record is returned as a byte array containing the SMF record data, including the record descriptor word (RDW).Note: The
Iterator.hasNext()
method will wait if there is no SMF record immediately available. It will return true when the next record is available, or false if the connection is closed. Likewise,Iterator.next()
will wait if there is no record currently available. -
spliterator
Get a Spliterator for the records from the SMF connection.Note: The
Spliterator.tryAdvance(Consumer)
method will wait if there is no SMF record immediately available. It will return true when a record has been read and processed, or false if the connection is closed.- Specified by:
spliterator
in interfaceIterable<byte[]>
-
isEmpty
public boolean isEmpty()Return true if the internal queue of SMF records is empty and the next record will be read from the in memory resource, potentially waiting until a record is written.Multiple records can be read from the in memory resource and queued internally. If there are records queued i.e. (isEmpty() == false) the next record will be returned immediately. If (isEmpty() == true) the next record will be read from the in memory resource, waiting if necessary until a record is available.
- Specified by:
isEmpty
in interfacecom.blackhillsoftware.common.interfaces.Emptyable
- Returns:
- true if there are no records currently queued and the next record will be read from the in memory resource
-
moreQueued
Deprecated.seeisEmpty()
- Returns:
- false if the next record will be read from the in memory resource
-
close
Close the connection.Close can be called from a different thread to the thread reading the records. In that case, close() will wait up to 5 seconds for a read in progress to end. A read started before close() is called might return data after close() has been called from another thread.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getResourceName
Get the name of the resource for this connection- Returns:
- the resource name
-
isEmpty()