java.lang.Object
com.blackhillsoftware.smf.realtime.SmfConnection
All Implemented Interfaces:
com.blackhillsoftware.common.interfaces.Emptyable, Closeable, AutoCloseable, Iterable<byte[]>

public abstract class SmfConnection extends Object implements Closeable, Iterable<byte[]>, com.blackhillsoftware.common.interfaces.Emptyable
Connect to and read from a z/OS SMF in Memory Resource (z/OS SMF Real Time Interface).

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

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Class used to set options for the SmfConnection prior to connection to the in memory resource.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Close the connection.
    Create a Connectable object for a SMF In Memory Resource name.
    Get the name of the resource for this connection
    boolean
    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[]>
    Get a SMF record Iterator.
    boolean
    Deprecated.
    Query the list of SMF in memory resources defined to the system
    byte[]
    Read a record, waiting if necessary.
    Spliterator<byte[]>
    Get a Spliterator for the records from the SMF connection.
    Stream<byte[]>
    Get a Java Stream to read SmfRecords as byte arrays from the in memory resource.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach
  • Method Details

    • query

      public static List<InMemoryResource> query() throws IOException
      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

      public static SmfConnection.Connectable forResourceName(String name)
      Create a Connectable object for a SMF In Memory Resource name. Call connect() to return a usable SmfConnection object or call onMissedData(Consumer) to setup missed data handling.
      Parameters:
      name - the name of the in memory resource.
      Returns:
      Connectable the object ready to connect.
    • read

      public byte[] read() throws IOException
      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

      public Stream<byte[]> stream()
      Get a Java Stream to read SmfRecords as byte arrays from the in memory resource.
      Returns:
      Stream<byte[]>
      See Also:
    • iterator

      public Iterator<byte[]> 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.

      Specified by:
      iterator in interface Iterable<byte[]>
      See Also:
    • spliterator

      public Spliterator<byte[]> 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 interface Iterable<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 interface com.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 public boolean moreQueued()
      Deprecated.
      Returns:
      false if the next record will be read from the in memory resource
    • close

      public abstract void close() throws IOException
      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 interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • getResourceName

      public String getResourceName()
      Get the name of the resource for this connection
      Returns:
      the resource name