public class SmfRecordReader extends Object implements Iterable<SmfRecord>, Closeable
SmfRecordReader implements Closeable and so should be used with try with resources so that it will be closed automatically:
try (SmfRecordReader reader = SmfRecordReader.fromName("//DD:INPUT"))
{
for (SmfRecord record : reader)
{
// process record
}
}
include(int)
and include(int, int)
methods allow you
to select the record types and subtypes
returned by the SmfRecordReader.
To select only SMF 30 subtype 5 records:
reader.include(30, 5);
The include method returns the SmfRecordReader itself, so calls can be chained to select multiple types and/or subtypes. To select SMF 14 and 15 records:
reader .include(14) .include(15);
If you don't include
a specific record type, all records are selected.
SmfRecordReader can also be used with Java 8 Streams. This allows you to chain operations such as filters, grouping, sorting, actions etc.
Java Streams allow you to create complex filters and queries with little code,
however they have the disadvantage that it is difficult to refer back to
the result of previous steps in the chain. This is a disadvantage when processing SMF as you
often want to refer to information in the parent record or other sections.
For this reason the for (SmfRecord record : reader)
style above is
probably preferred.
try (SmfRecordReader reader =
SmfRecordReader.fromName("//DD:INPUT").include(100))
{
reader.stream()
.filter(r -> r.system().equals("SYSA")) // use criteria to filter records
.filter(r -> r.smfTime().isAfter(LocalTime.of(9, 00))
&& r.smfTime().isBefore(LocalTime.of(17, 00)))
.map(r -> new Smf100Record(r)) // map to SMF 100 record type
.map(r100 -> r100.qwos()) // get list of Qwos from each record (maybe empty)
.flatMap(List::stream) // combine stream of lists into a single stream
.forEach(s -> System.out.println(s.dump())); // do something with each item
//.count(); // or count items in stream - returns a long
//.collect(Collectors.toList()); // or collect into List<> - returns List<Qwos>
}
Modifier and Type | Class and Description |
---|---|
static class |
SmfRecordReader.RecordFormat
Record formats for stream data.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the input dataset or stream.
|
static SmfRecordReader |
fromDD(String dd)
Create a new SmfRecordReader to read from an allocated DD.
|
static SmfRecordReader |
fromName(String name)
Create a new SmfRecordReader to read from a named file or dataset.
|
static SmfRecordReader |
fromStream(InputStream stream)
Create a new SmfRecordReader to read from an existing stream.
|
static SmfRecordReader |
fromStream(InputStream stream,
SmfRecordReader.RecordFormat format)
Create a new SmfRecordReader to read from an existing stream.
|
SmfRecordReader |
include(int smftype)
Include all records of a particular SMF record type.
|
SmfRecordReader |
include(int smftype,
int subtype)
Include records of a particular SMF record type and subtype.
|
Iterator<SmfRecord> |
iterator()
Get an Iterator to read SmfRecords from the input stream or DD.
|
Stream<SmfRecord> |
stream()
Get a Java 8 Stream to read SmfRecords from the input stream or DD.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public static SmfRecordReader fromDD(String dd) throws IOException
close()
when finished reading.
The stream can also be automatically closed using a try-with-resources block.dd
- The DDNAME for the SMF data file. The DD must be already allocated e.g. via JCL.IOException
public static SmfRecordReader fromName(String name) throws IOException, FileNotFoundException
"//DD:INPUT"
"//'MVS.DATASET.NAME'" "//'MVS.DATASET.NAME(0)'"
The input source will be automatically closed at end of file.
You can ensure the stream is closed using a try-with-resources block (recommended),
or if the program does not read all records from the
dataset, call close()
when finished reading.
name
- The name of the resource to open, in the formats documented above.IOException
FileNotFoundException
public static SmfRecordReader fromStream(InputStream stream)
The stream must contain complete SMF records, including the RDW
The stream will be
automatically closed at end of file. If the program does not read all records from the
stream, call close()
when finished reading.
The stream can also be automatically closed using a try-with-resources block.
Usually, the format of the data in the stream (V or U) can be automatically
detected. If this doesn't work (typically you will see data errors very quickly) you can
fromStream(InputStream, RecordFormat)
to specify the record format explicitly.
stream
- the InputStream to read.public static SmfRecordReader fromStream(InputStream stream, SmfRecordReader.RecordFormat format)
The stream must contain complete SMF records, including the RDW, and the BDW if RecordFormat.U is specified
The stream will be
automatically closed at end of file. If the program does not read all records from the
stream, call close()
when finished reading.
The stream can also be automatically closed using a try-with-resources block.
stream
- the InputStream to read.format
- the SmfRecordReader.RecordFormat
of the records in the stream - U, V or AutoDetectpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public SmfRecordReader include(int smftype)
If no include statements are used, all SMF record types are returned from the SmfRecordReader. If any include statements are used, only the types and optionally subtypes listed in include statements are returned.
If previous include statements listed specific subtypes for this record type, this method will override that and return all subtypes for this record type.
smftype
- the SMF record type to includepublic SmfRecordReader include(int smftype, int subtype)
If no include statements are used, all SMF record types are returned from the SmfRecordReader. If any include statements are used, only the types and optionally subtypes listed in include statements are returned.
If a previous include statement specified this SMF type without a subtype, this statement has no effect - all subtypes will still be returned.
smftype
- the SMF record type to includesubtype
- the subtype to includepublic Iterator<SmfRecord> iterator()
public Stream<SmfRecord> stream()
java.util.stream
Copyright © 2020 Black Hill Software Pty Ltd. All rights reserved.