-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Property name used by batch launcher to cause stderr/stdout to be merged to DD:SYSOUTstatic final int
Debug level logging @seesetLoggingLevel(int)
static final int
Error level logging @seesetLoggingLevel(int)
static final int
Informational level logging @seesetLoggingLevel(int)
static final int
Notice level logging @seesetLoggingLevel(int)
static final int
Trace level logging @seesetLoggingLevel(int)
static final int
Warning level logging @seesetLoggingLevel(int)
static final int
The length of an SMF header prefix -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]
environ()
Get an array of strings that represent the environment variables of the current process.static String
Print the stacktrace related to the supplied Throwable and return it as a String.static String
Native method to retrieve the default locale codepage name used by the toolkit native library.static long
Gets the amount of CPU time consumed, expressed in microseconds, for the current thread.static String
Get the current MVS job correlator, blanks trimmedstatic int
Get the current Job Entry Datestatic long
Get the current Job Entrystatic String
Get the current MVS jobid, blanks trimmedstatic String
Get the current MVS jobname, blanks trimmedstatic String
Get the current MVS proc stepname, blanks trimmed.static String
Get the current MVS stepname, blanks trimmed.static String
Get the current MVS step number, blanks trimmedstatic long
Gets the current time, expressed in microseconds since 00:00:00 Coordinated Universal Time (UTC), January 1, 1970static String
Gets the TSO prefix, if running under TSO.static String
Get the current MVS userid.static String
Get the default platform encoding for this instance of the JVM.static String
Get the value of the Environment variable.static Properties
Return a Properties object containing the current process environment variables.static long
getEpochMillis
(byte[] stckOrStcke) Get the Unix Epoch milliseconds equivalent to the input STCK time in bytes.static long
getEpochMillis
(long stck) Get the Unix Epoch milliseconds equivalent to the input STCK time in long value.static final long
getEpochMilliSeconds
(long stck) Get the Unix Epoch milliseconds equivalent to the input STCK time in long value.static String
Get a multi-line string that contains information about the version of Java that is currently running.static String
Return a string representing the version of the JZOS shared library.static String
Load the build_version.properties class resource and return a string representing the version of the JZOS Java archive.static int
Answer the current logging level for the Toolkit native code.static int
getPid()
Get the process id of the current process.static int
getPPid()
Get the parent process id of the current process.static byte[]
A JNI wrapper for the z/architecture STORE CLOCK (STCK) instructionstatic void
getTodClock
(byte[] buffer) A JNI wrapper for the z/architecture STORE CLOCK (STCK) instructionstatic byte[]
A JNI wrapper for the z/architecture STORE CLOCK EXTENDED (STCKE) instructionstatic void
getTodClockExtended
(byte[] buffer) A JNI wrapper for the z/architecture STORE CLOCK EXTENDED (STCKE) instructionstatic void
logDiagnostic
(int level, String msg) Send a message to the JZOS toolkit's log, which goes to the Language Environment messages file, which is usually stderr or DD SYSOUT.static PrintStream
newEncodedPrintStream
(OutputStream os, boolean autoFlush) Construct a PrintStream which is configured to transcode from the current Java file encoding to the current default platform encoding.static PrintStream
newEncodedPrintStream
(OutputStream os, boolean autoFlush, String encoding) Construct a PrintStream which is configured to transcode from the current Java file encoding to the given encoding.static PrintStream
newEncodedPrintStream
(OutputStream os, boolean autoFlush, String encoding, boolean enable) Construct a PrintStream which which can be used to transcode characters and bytes from the current Java file encoding to the given encoding.static void
peekOSMemory
(long address, byte[] bytes) Peek bytes from OS memory.static void
peekOSMemory
(long address, byte[] bytes, int offset, int len) Peek bytes from OS memory.static long
peekOSMemory
(long address, int len) Peek (read) a long from OS memory.static void
Redirect the standard streams using the default platform character encoding.static boolean
redirectStandardStreams
(String requestedEncoding, boolean enableTranscoding) A static method which redirects the standard streams as follows: System.out is redirected to DD:STDOUT (required) System.err is redirected to DD:STDERR (required) System.in is redirected from DD:STDIN (optional)static void
setDefaultPlatformEncoding
(String encoding) Set the default output encoding for this instance of the JVM.static void
Set an Environment variable.static void
setLoggingLevel
(int level) Sets the logging level for the Toolkit native code.static void
smfRecord
(int type, int subtype, byte[] record) Write a System Management Facility (SMF) record.static String
substituteSystemSymbols
(String pattern) Substitute text for MVS system symbols.static String
substituteSystemSymbols
(String pattern, boolean warn) Substitute text for MVS system symbols.static final Instant
toInstant
(byte[] stckOrStcke) Convert the given z-Architecture TOD clock or extended TOD clock value to a java.time.Instant, which represents the time in Java epoch seconds and nanoseconds within the second.static final Instant
toInstant
(long stck) Convert the given z-Architecture TOD clock to a java.time.Instant, which represents the time in Java epoch seconds and nanoseconds within the second.static void
touch()
-
Field Details
-
LOG_ERR
public static final int LOG_ERRError level logging @seesetLoggingLevel(int)
- See Also:
-
LOG_WARN
public static final int LOG_WARNWarning level logging @seesetLoggingLevel(int)
- See Also:
-
LOG_NOTICE
public static final int LOG_NOTICENotice level logging @seesetLoggingLevel(int)
- See Also:
-
LOG_INFO
public static final int LOG_INFOInformational level logging @seesetLoggingLevel(int)
- See Also:
-
LOG_DEBUG
public static final int LOG_DEBUGDebug level logging @seesetLoggingLevel(int)
- See Also:
-
LOG_TRACE
public static final int LOG_TRACETrace level logging @seesetLoggingLevel(int)
- See Also:
-
SMF_HEADER_PREFIX_LEN
public static final int SMF_HEADER_PREFIX_LENThe length of an SMF header prefix- See Also:
-
JZOS_MERGE_SYSOUT_PROPERTY
Property name used by batch launcher to cause stderr/stdout to be merged to DD:SYSOUT- See Also:
-
-
Method Details
-
getDefaultPlatformEncoding
Get the default platform encoding for this instance of the JVM. The encoding is generally some variant of EBCDIC.The default value is the Java codepage that matches the default locale encoding for the z/OS Unix process running the JVM, or "IBM-1047" if no matching Java encoding can be found.
- Returns:
- the default output encoding
- See Also:
-
setDefaultPlatformEncoding
Set the default output encoding for this instance of the JVM. The encoding is generally some variant of EBCDIC.The default value is the Java codepage that matches the default locale encoding for the z/OS Unix process running the JVM, or "IBM-1047" if no matching Java encoding can be found.
Note: This method should be used with caution, and is generally not recommended for customer use.
- Parameters:
encoding
- the charset encoding to use as a default- Throws:
UnsupportedEncodingException
- if the encoding is not supported
-
environ
Get an array of strings that represent the environment variables of the current process.This method reads and returns the values held in the C-library 'environ' global.
- Returns:
- an array of environment variable strings in name=value format
-
getEnvironment
Return a Properties object containing the current process environment variables.- Since:
- 2.1.0
-
getEnv
Get the value of the Environment variable.This method calls the getenv() C-library routine.
- Parameters:
varName
- the name of the environment variable- Returns:
- the value of the environment variable. Null if not found.
-
setEnv
Set an Environment variable.This method calls the setenv() C-library routine.
- Parameters:
varName
- the name of the environment variablevarValue
- the value of the environment variable- Throws:
ErrnoException
- if the native call fails.- Since:
- 2.1.0
-
getCurrentJobname
Get the current MVS jobname, blanks trimmed- Returns:
- the jobname
-
getCurrentTsoPrefix
Gets the TSO prefix, if running under TSO.- Returns:
- the TSO prefix; null if not running under TSO; an empty string if under TSO with no prefix
-
getCurrentStepname
Get the current MVS stepname, blanks trimmed. This is the "jobstep name" if running under a proc.- Returns:
- the proc stepname
-
getCurrentProcStepname
Get the current MVS proc stepname, blanks trimmed. This is an empty string if not running in a proc.- Returns:
- the proc stepname
-
getCurrentStepNumber
Get the current MVS step number, blanks trimmed- Returns:
- the step number
-
getCurrentJobId
Get the current MVS jobid, blanks trimmed- Returns:
- the jobid (job number)
-
getCurrentJobCorrelator
Get the current MVS job correlator, blanks trimmed- Returns:
- the job correlator
-
getCurrentJobEntry
public static long getCurrentJobEntry()Get the current Job Entry- Returns:
- the job entry
-
getCurrentJobEDate
public static int getCurrentJobEDate()Get the current Job Entry Date- Returns:
- the job entry date
-
getCurrentTimeMicros
public static long getCurrentTimeMicros()Gets the current time, expressed in microseconds since 00:00:00 Coordinated Universal Time (UTC), January 1, 1970This function uses the gettimeofday64() C library function, which returns a 64-bit number of seconds since 1/1/1970, and the fractional microseconds as a 32 bit number.
- Returns:
- a (64-bit) Java long containing the number of microseconds since UTC January 1, 1970.
- Since:
- 2.1.0, 2.4.8 Changed to use gettimeofday64() to avoid year 2038 overflows
-
getCpuTimeMicros
Gets the amount of CPU time consumed, expressed in microseconds, for the current thread.This function calls the TIMEUSED ECT=COND system macro. Refer to the
z/OS MVS Programming: Authorized Assembler Services Reference SET-WTO
, SA22-7612 for more information on the TIMEUSED macro.- Returns:
- a Java long containing the number of microseconds of CPU time consumed by the current thread
- Throws:
an
- (unchecked) RcException if call fails (not expected)RcException
- Since:
- 2.1.0
-
getEpochMillis
Get the Unix Epoch milliseconds equivalent to the input STCK time in bytes.This function converts a timestamp in STCK byte array to Epoch milliseconds. The returned value is of the same type used by Java for time values, c.f.
System.currentTimeMillis()
.- Parameters:
stckOrStcke
- 8-byte timestamp in STCK format or 16-byte STCKE format- Returns:
- a Java long containing time in Epoch milliseconds
- Throws:
IllegalArgumentException
- if stck is null or is not 8 bytes longRcException
- Since:
- 2.4.5, 2.4.8 Added support for stcke format
-
getEpochMillis
public static long getEpochMillis(long stck) Get the Unix Epoch milliseconds equivalent to the input STCK time in long value.This function converts a timestamp in STCK byte array to Epoch milliseconds. The returned value is of the same type used by Java for time values, c.f.
System.currentTimeMillis()
.- Parameters:
stck
- a STCK timestamp in long- Returns:
- a Java long containing time in Epoch milliseconds
- Since:
- 2.4.5
-
getEpochMilliSeconds
public static final long getEpochMilliSeconds(long stck) Get the Unix Epoch milliseconds equivalent to the input STCK time in long value.Note: this is equivalent to
getEpochMillis(long)
This function converts a timestamp in STCK byte array to Epoch milliseconds.
- Parameters:
stck
- a STCK timestamp in long- Returns:
- a Java long containing time in Epoch milliseconds
- Since:
- 2.4.5
-
toInstant
Convert the given z-Architecture TOD clock to a java.time.Instant, which represents the time in Java epoch seconds and nanoseconds within the second.- Parameters:
stck
- a long representing the 8 byte z-architecture TOD clock value.- Since:
- 2.4.8
- See Also:
-
toInstant
Convert the given z-Architecture TOD clock or extended TOD clock value to a java.time.Instant, which represents the time in Java epoch seconds and nanoseconds within the second.- Parameters:
stckOrStcke
- the 8 or 16 byte z-architecture clock value.- Since:
- 2.4.8
- See Also:
-
getCurrentUser
Get the current MVS userid.This is a convenience method that simply delegates to PlatformThread.getUserName()
- Returns:
- the current MVS userid
- Throws:
RcException
- See Also:
-
-
getJavaVersionInfo
Get a multi-line string that contains information about the version of Java that is currently running. This method is called by the JZOS batch launcher to display the Java version information on the //SYSOUT DD- Returns:
- a String in the general form specified by sun.misc.Version.print()
-
getJzosJarVersion
Load the build_version.properties class resource and return a string representing the version of the JZOS Java archive. -
getJzosDllVersion
Return a string representing the version of the JZOS shared library. -
peekOSMemory
Peek (read) a long from OS memory.- Parameters:
address
- the address of the OS memory to start peeking from.len
- the number of bytes to read into the returned long, must be <= 8- Throws:
RcException
- if there is an error accessing the memory location.IllegalArgumentException
- if len > 8 or len <=0SecurityException
- if a a SecurityManager is active and the user doesn't have access to JzosPermission("peekOSMemory")
-
peekOSMemory
Peek bytes from OS memory.- Parameters:
address
- the address of the OS memory to start peeking from.bytes
- the location to store the bytes peeked, for bytes.length- Throws:
RcException
- if there is an error accessing the memory location.SecurityException
- if a a SecurityManager is active and the user doesn't have access to JzosPermission("peekOSMemory")
-
peekOSMemory
Peek bytes from OS memory.- Parameters:
address
- the address of the OS memory to start peeking from.bytes
- the location to store the bytes peekedoffset
- the 0-based offset into bytes where to store the first byte peekedlen
- the number of bytes to copy from memory- Throws:
IllegalArgumentException
- if offset and len are incompatible with bytesRcException
- if there is an error accessing the memory location.SecurityException
- if a a SecurityManager is active and the user doesn't have access to JzosPermission("peekOSMemory")
-
logDiagnostic
Send a message to the JZOS toolkit's log, which goes to the Language Environment messages file, which is usually stderr or DD SYSOUT.Note: This method is not intended to be used from customer code.
- Parameters:
level
- one of the LOG_XXX constants. If an invalid value is supplied, the message is ignored.msg
- the message text
-
redirectStandardStreams
Redirect the standard streams using the default platform character encoding.The JZOS batch launcher calls this method on startup to cause System.out, System.err and System.in to be directed to/from the job stream. Customers may also wish to use this method for the same purpose when Java is invoked without using the JZOS batch launcher. For example: from a COBOL main program that invokes Java code.
The I/O for will be redirected to DD:STDIN, DD:STDOUT, and DD:STDERR, using the same EBCDIC encoding that is specified by
getDefaultPlatformEncoding()
. These DDs must be allocated prior to calling this method, except that DD:SYSIN is optional. If the system property jzos.merge.sysout is set to true, System.out and System.err are redirected to DD:SYSOUT rather than DD:STDOUT and DD:STDERR respectively.This facility may only be used to redirect standard streams once, otherwise the results are not predictable.
- Throws:
Exception
- if the streams could not be redirected.- See Also:
-
redirectStandardStreams
public static boolean redirectStandardStreams(String requestedEncoding, boolean enableTranscoding) throws Exception A static method which redirects the standard streams as follows:- System.out is redirected to DD:STDOUT (required)
- System.err is redirected to DD:STDERR (required)
- System.in is redirected from DD:STDIN (optional)
This method is invoked by the JZOS batch launcher to redirect the standard Java streams to MVS DDs. If STDIN is not defined, System.in is set to an InputStream that immediately returns -1 (EOS).
This facility may only be used to redirect standard streams once, and is NOT intended to be used from customer code.
If the system property jzos.merge.sysout is set to true, System.out and System.err are redirected to DD:SYSOUT rather than DD:STDOUT and DD:STDERR respectively.
- Parameters:
requestedEncoding
- the requested character encoding. If this encoding is not supported, defaultPlatformEncoding is used.- Returns:
true
if the requestedEncoding was used,false
if the default was used.- Throws:
Exception
- if the streams could not be redirected.- See Also:
-
newEncodedPrintStream
public static PrintStream newEncodedPrintStream(OutputStream os, boolean autoFlush) throws UnsupportedEncodingException Construct a PrintStream which is configured to transcode from the current Java file encoding to the current default platform encoding.The current Java file encoding can be obtained from the "file.encoding" System property.
- Parameters:
os
- the stream to base the PrintStream on.autoFlush
- whether or not to autoFlush.- Returns:
- the printStream
- Throws:
UnsupportedEncodingException
- See Also:
-
newEncodedPrintStream
public static PrintStream newEncodedPrintStream(OutputStream os, boolean autoFlush, String encoding) throws UnsupportedEncodingException Construct a PrintStream which is configured to transcode from the current Java file encoding to the given encoding.The current Java file encoding can be obtained from the "file.encoding" System property.
- Parameters:
os
- the stream to base the PrintStream on.autoFlush
- whether or not to autoFlushencoding
- the target charset encoding to use- Returns:
- the printStream
- Throws:
UnsupportedEncodingException
- See Also:
-
newEncodedPrintStream
public static PrintStream newEncodedPrintStream(OutputStream os, boolean autoFlush, String encoding, boolean enable) throws UnsupportedEncodingException Construct a PrintStream which which can be used to transcode characters and bytes from the current Java file encoding to the given encoding.The current Java file encoding can be obtained from the "file.encoding" System property.
- Parameters:
os
- the stream to base the PrintStream on.autoFlush
- whether or not to autoFlushencoding
- the charset encoding to useenable
- if false, transcoding is disabled- Returns:
- the printStream
- Throws:
UnsupportedEncodingException
- See Also:
-
getLoggingLevel
public static int getLoggingLevel()Answer the current logging level for the Toolkit native code.- See Also:
-
setLoggingLevel
public static void setLoggingLevel(int level) Sets the logging level for the Toolkit native code. This method can be used to enable debugging output from the toolkit native library.In order of decreasing severity, the logging levels are:
Alternatively, a system property can be used to set the toolkit logging level. This property has the form: -Djzos.logging={E|W|N|I|D|T}
- Parameters:
level
- one of the LOG_XXX constants. If an invalid level is given it is ignored, but a warning is logged.- See Also:
-
getCodePageCurrentLocale
Native method to retrieve the default locale codepage name used by the toolkit native library. This is the default codepage for the z/OS process based on the LANG environment variable. -
getPid
public static int getPid()Get the process id of the current process.This method calls the getpid() C-library routine.
- Returns:
- the process id.
- Since:
- 2.1.0
-
getPPid
public static int getPPid()Get the parent process id of the current process.This method calls the getppid() C-library routine.
- Returns:
- the parent process id.
- Since:
- 2.1.0
-
getTodClock
public static byte[] getTodClock()A JNI wrapper for the z/architecture STORE CLOCK (STCK) instructionRefer to
SA22-7832 z/Architecture Principles of Operations
for more information.- Returns:
- byte[] an 8 byte array containing the TOD clock value
- Throws:
RcException
- if the STCK instruction returns a CC != 0 (should not happen)- Since:
- 2.3.0
-
getTodClock
public static void getTodClock(byte[] buffer) A JNI wrapper for the z/architecture STORE CLOCK (STCK) instructionRefer to
SA22-7832 z/Architecture Principles of Operations
for more information.- Parameters:
buffer
- a byte array a least 8 bytes long to receive the TOD clock value- Throws:
RcException
- if the STCK instruction returns a CC != 0 (should not happen)IllegalArgumentException
- if the given buffer is not at least 8 bytes in length- Since:
- 2.3.0
-
getTodClockExtended
public static byte[] getTodClockExtended()A JNI wrapper for the z/architecture STORE CLOCK EXTENDED (STCKE) instructionRefer to
SA22-7832 z/Architecture Principles of Operations
for more information.- Returns:
- byte[] a 16-byte byte array containing the extended TOD clock value
- Throws:
RcException
- if the STCKE instruction returns a CC != 0 (should not happen)- Since:
- 2.3.0
-
getTodClockExtended
public static void getTodClockExtended(byte[] buffer) A JNI wrapper for the z/architecture STORE CLOCK EXTENDED (STCKE) instructionRefer to
SA22-7832 z/Architecture Principles of Operations
for more information.- Parameters:
buffer
- a byte array a least 16 bytes long to receive the extended TOD clock value- Throws:
RcException
- if the STCKE instruction returns a CC != 0 (should not happen)IllegalArgumentException
- if the given buffer is not at least 16 bytes in length- Since:
- 2.3.0
-
smfRecord
Write a System Management Facility (SMF) record.This method calls the __smf_record() C-library routine. The first 24 bytes of the given record are reserved for the
Standard SMF Record Header with Subtypes
, as described in the manual:MVS Systems Management Facilities (SMF)
.Before writing the record, this API will overwrite the 24 byte SMF header area, filling in all header fields, including the current date/time and the system id (SID). If the SUBSYS starts with a blank or null(zero), then it is also filled in with either "JES2", "JES3", "TSO", or "STC" as appropriate. If the SUBSYS field starts with a character other than blank or null, then it is unchanged.
Note: The "TZ" environment variable must be properly set to the correct timezone in order for the date/time in the SMF header to reflect the current local time.
- Throws:
ErrnoException
- on failure. Refer to __smf_record() API documentation for specific errno reason code constants, which are provided as constants in the ErrnoException class.
-
substituteSystemSymbols
Substitute text for MVS system symbols.This method calls the ASASYMBM Assembler service. For more information, see
MVS Programming: Assembler Services Reference, Volume 1
(SA22-7606). User symbol tables are not supported by this API.- Parameters:
pattern
- a string containing MVS system symbol(s) to be substituted. MVS system symbols have the form&SYMBOL.
, or&SYMBOL(n:m).
(if a substring of the resulting text is requested). In this case,n
is the start index of the resulting text andm
is the number of characters to substitute. For more information on how symbol substrings are specified, see theMVS Initialization and Tuning Reference
(SA22-7592)warn
- if true will force ASASYMBM to check for symbol substitution warnings. See the notes under RcException for details. If false, symbol substitution warnings are ignored.- Returns:
- the pattern string with text substituted for the system symbols.
- Throws:
RcException
- if an error occurs with one of the following return codes:- 4 - warn=true and there was a substring error
- 8 - the target buffer was too small to hold the substituted pattern
- 12 - warn=true and the length of the text substituted for a system symbol was zero
- 16 - warn=true and none of the specified symbols was substituted
- Since:
- 2.3.0
-
substituteSystemSymbols
Substitute text for MVS system symbols.Calls
substituteSystemSymbols(String, boolean)
with warn=false.- Throws:
RcException
- Since:
- 2.3.0
-
touch
public static void touch() -
formatStackTrace
Print the stacktrace related to the supplied Throwable and return it as a String.
-