Application Development
A
Cocktail of Java and MCP
MCP Guru Series
Agenda
Which of the following topics can be found in an Application
Development cocktail?
o
Calling Java from COBOL-85
o
Using Java7 NIO2 features
o
Accessing DMSII from Java
o
All of the above
o
Some of the above
“A Cocktail of Java and MCP”
Application Development
•
“Wouldn’t It Be Nice” by the Beach Boys
“Wouldn't it be nice if we were older
Then we wouldn't have to wait so long
Wouldn't it be nice to live together
In the kind of world where we belong
You know its gonna make it that much better
When we can say goodnight and stay together”
•
Wouldn’t it be nice if:
–
Your favorite programming language could be used for everything?
–
You could find libraries that could be easily called and not support?
–
There were an endless supply of COBOL programmers?
Mixing Languages Through Libraries
•
We Invented It Application Program Interface (Wii API)
–
A “was well documented”, in-house developed standard
–
Specific application during definition
–
Communication over TCPIP (Socket-to-Socket)
•
Common Object Request Broker Architecture (CORBA)
–
A well-defined Object Management Group (OMG) standard
–
Vendor-independent architecture and structure
–
Communication over the Internet Inter-Orb Protocol (IIOP)
•
Java Native Interface (JNI)
–
A well-defined Java standard
–
Defined for C
COBOL
????
•
COBOL app needs to access an Oracle database
•
COBOL app needs to be web services enabled
•
COBOL app needs to create a PDF file
•
COBOL app needs to decrypt messages encrypted with …
Java Invocation Interface (Jii)
•
COBOL-85 (via ALGOL) calling Java methods
•
Can invoke standard Java packages
•
Usually need minimal Java code
•
Native program is in control
•
Uses Java as a private library
Java Invocation Interface (Jii)
•
API developed to call Java methods
–
Simplified with “com.unisys.mcp.tools.JifGen”
•
Reads Java source or class and generates “entrypoint” INCLUDE file
•
Does all the ‘dirty work’ of calling JNI methods
–
Based on C JNI method definition in a generated ALGOL library
•
Calls for identifying methods by name
•
Calls for identifying objects by name
•
Chatty and “error prone”
JNI Proxy Lib JProcessor Java Worker Java Worker JVM Application JNI Interfaces Java Class
Jii Development Process Demo
•
Create or identify a Java class with public methods
– Demo – COBOL program needing to accessing ‘remote’ database using data from a DMSII database
– Java application needs 3 methods
• Connect to the remote database – getConnection()
• Close database connection – releaseConnection()
• Retrieve record using key passed from COBOL-85 and compare data – compareEqual (int id, String word)
JNI Proxy Lib JProcessor Java Worker Java Worker JVM Application JNI Interfaces Java Class
UniverseDemo.zip
Jii Development Process Demo
package com.unisys.mcp.universe; import java.sql.*;
public class Demo {
static Connection con = null;
static PreparedStatement pStmt = null;
static String url = “jdbc:unisys:dmsql:Unisys.DMSII”; public static boolean releaseConnection()
{
try {
if (pStmt <> null) pStmt.close(); if (con <> null) con.close();
return true;
} catch (SQLException seq) { sqe.printStackTrace(); return false;
} }
Jii Development Process Demo
public static boolean getConnection() {
boolean onMCP = System.getProperty("os.name").contains("MCP"); String hostname = onMCP ? “EVLANMCP” : “ECCSK”;
try {
Class.forName ("com.unisys.jdbc.dmsql.Driver“) url = url + “resource=UNIVERSEDB;”
+ “host=“ + hostname + “;port=1897” + “user=JAVA;password=JAVA”);
con = DriverManager.getConnection (url); if (con == null) return false;
pStmt = con.prepareStatement
("SELECT * FROM universedb.words “ + “ where word_id = ?");
if (pStmt == null) return false; return true;
} catch (SQLException sqe) { sqe.printStackTrace();
return false; }
Jii Development Process Demo
public static boolean compareEqual (int id, String wordA) { wordA = wordA.trim(); try { pStmt.setInt(1, id); ResultSet rs = pStmt.executeQuery(); if (rs.next() { String a = rs.getString(“dmsii_word_a”); if (a.compareTo(wordA) != 0) {
System.err.println (id + “) “ + a + “<>” + wordA); return false;
}
} else {
System.err.println (id + “) not found [“+ wordA +”]”); return false;
}
return true;
} catch (SQLException sqe) { sqe.printStackTrace(); return false;
Jii Development Process Demo
public static void main (String args[]) {
String command = “select * from dmsii_words”); try {
if (getConnection()) {
Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(command); while (rs.next()) {
int id = rs.getInt (“word_id”);
String wordA = rs.getString (“dmsii_word_a”);
System.out.println (“(“ + id + “) “ + wordA.trim() + “ : “
+ compareEqual (id, wordA.getBytes())
); } rs.close(); stmt.close(); releaseConnection(); } } catch (Exception e) { …; } } }
Jii Development Process Demo
•
Run JifGen to create files to be used on MCP
RUN *DIR/JRE7/BIN/MCPTOOLS
("JifGen -verbose -cobol -d /-/JAVA/USERCODE/JAVA/UD -classpath /-/JAVA/DIR/JAVA/universedemo.jar
-output DEMO com.unisys.mcp.universe.Demo")
[Creating file /-/JAVA/USERCODE/JAVA/UD/DEMOINCL.C85_M]
[Creating file /-/JAVA/USERCODE/JAVA/UD/DEMO.ALG_M]
JNI Proxy Lib JProcessor Java Worker Java Worker JVM Application JNI Interfaces Java Class
Jii Development Process Demo
•
Modify “existing” application to use Java methods
–
Include sections from
*DIR/JRE7/JDK/INCLUDE/JNILIB/COBOL
–
Include sections from
"DEMOINCL.C85_M“
–
CALL JNI-CREATE-JAVA-VM USING … GIVING RESULT.
–
Do work using the following generated entry points
• ENTRY PROCEDURE INITIALIZE-DEMO
• ENTRY PROCEDURE DEMO-DEMO-GET-CONNECTION
• ENTRY PROCEDURE DEMO-DEMO-RELEASE-CONNECTION
• ENTRY PROCEDURE DEMO-DEMO-COMPARE-EQUAL
–
CALL JNI-DESTROY-JAVA-VM USING … GIVING RESULT.
•
Create ALGOL library DEMO/LIBRARY
–
COMPILE UD/"DEMO.ALG_M“ AS DEMO/LIBRARY
Jii Development Process Demo
LOCAL-STORAGE SECTION.
$$INCLUDE JNICOB="COBOL" ("JNI-PARAMETERS")
$$INCLUDE DEMOCOB="""DEMOINCL.C85_M""" ("DEMO-PARAMETERS") PROGRAM-LIBRARY SECTION.
$$INCLUDE JNICOB="COBOL" ("JNI-FUNCTIONS")
$$INCLUDE DEMOCOB="""DEMOINCL.C85_M""" ("DEMO-FUNCTIONS") PROCEDURE DIVISION.
Jii Development Process Demo
Initialize-JVM.
STRING jvmOptions, jvmCP1, jvmCP2, jvmCP3, jvmCP4 DELIMITED BY SIZE INTO ARGUMENTS.
ADD FUNCTION Length ( jvmOptions ), FUNCTION Length ( jvmCP1 ), FUNCTION Length ( jvmCP2 ), FUNCTION Length ( jvmCP3 ), FUNCTION Length ( jvmCP4 ) GIVING ArgLength.
MOVE MCP-Options TO Arguments-2.
MOVE FUNCTION Length ( MCP-Options ) to Arg2Length. CALL JNI-CREATE-JAVA-VM
USING JNI-VM, JNI-ENV, Interface-Version, ARGUMENTS, ArgLength ARGUMENTS-2, Arg2Length GIVING RESULT. CALL INITIALIZE-DEMO USING JNI-ENV. CALL DEMO-DEMO-GET-CONNECTION USING JNI-ENV, bRESULT.
Jii Development Process Demo
OPEN INQUIRY UNIVERSEDB ON EXCEPTION GO TO XIT. loop-it.
FIND WORD VIA NEXT IDX-WORDS ON EXCEPTION GO TO XIT. MOVE DMSII-WORD-A TO DataWord.
MOVE WORD-SZ TO WordSz.
CALL DEMO-DEMO-COMPARE-EQUAL
USING JNI-ENV, WORD-ID, DataWord, WordSz, bRESULT. IF NOT bRESULT THEN
DISPLAY "COMPARE STRING ERROR=", bRESULT. GO loop-it.
xit.
Jii Possibilities?
•
Calling
Bouncy Castle
Crypto API
•
Accessing JBoss through its
Java Naming and Directory
Interface (JNDI)
•
Accessing third-party databases
•
Creating thumbnails of images
•
PDF Generation
•
Creating JSON data files
•
Using “off-the-shelf” components written in Java
Guidelines for Calling Java
•
Calling Java from native code is complicated and tedious.
•
Crossing between MCP and the Java environment is
expensive.
•
Try to write “heavy” functions.
•
Pass everything as parameters rather than calling back for
more information.
Java Docs Main Page
Virtual Machine for the
Java™ 6.0 Platform
on ClearPath MCP
Programming Guide
Installation and Administration Guide
ClearPath Common Appliance Configuration Guide
JVM for MCP API Specification
Java Native Interface for MCP
Readme, Errata and Other Notes
Optimizing Java Socket Performance
“A Cocktail of Java and MCP”
Java 7
•
Java SE 7 – Available with MCPJAVA in 15.0
•
New I/O features:
–
Asynchronous I/O
–
Ability to extend and customize the I/O interface.
•
For MCP this means:
Java 7 Example
import java.nio.file.*;
import com.unisys.mcp.file.*;
import static com.unisys.mcp.file.InitialFileAttributes.*;
…
Path file = FileSystems.getDefault().getPath( args[0] );
file.createFile(
FileKind.COBOL85SYMBOL.asFileAttribute(),
FileClass.RECORDORIENTED.asFileAttribute(),
maximumRecordSize(80),
Java 7 Example
•
Copies a file identified by the “file” path at ECCSK to
the local host as the file identified by the destination
path.
•
Uses MCP copy operation (BNA, FTP).
•
Similar moveTo will change the file name, if possible;
otherwise copy and delete the original.
file.copyTo( destination,
StandardCopyOption.ReplaceExisting,
McpCopyOption.Recursive,
McpFileAttributes Class
•
Provides most MCP attributes for a file.
•
All the various time stamps.
•
Title
•
Note
File Attributes
areaLength
accessTimestamp
fileClass
areas
alterTimestamp
fileKind
blockSize
attributeModifyTimestamp
fileName
clearAreas
backupTimestamp
fileStructure
compilerKind
copyDestinationTimestamp
frameSize
ccsVersion
copySourceTimestamp
hostName
extMode
creationTimestamp
licenseKey
familyIndex
executeTimestamp
note
familyName
openTimestamp
pathName
sensitiveData
readTimestamp
product
userInfo
maximumRecordSize
title
Open Options
•
Specify any of these when opening a file.
File Options
Record Options
Buffers
Fold
BufferSize
IncludeSequenceNumbers
HostName
NoCrLf
IntName
StripSpaces
Truncate
Unfold
Initial File Attributes
•
Specify any of these when creating a file.
areaLength
areas
blockSize
clearAreas
familyIndex
frameSize
hostName
maximumRecordSize
note
sensitiveData
userInfo
Java Docs Main Page
Virtual Machine for the
Java™ 6.0 Platform
on ClearPath MCP
Programming Guide
Installation and Administration Guide
ClearPath Common Appliance Configuration Guide
JVM for MCP API Specification
Java Native Interface for MCP
Readme, Errata and Other Notes
Optimizing Java Socket Performance
“A Cocktail of Java and MCP”
Accessing DMSII From Java
DMSII Databases
D
M
S
Q
L
Accessing DMSII From Java
•
COBOL & ALGOL access via Host Language constructs
–
OPEN, FIND/LOCK, CREATE, STORE, …
–
BEGIN-TRANSACTION, END-TRANSACTION, …
•
Java access
–
Java Host Language Interface (JHLI) and Java DMInterface (JDMI)
–
Java EE Connector Architecture (JCA) components
•
Resource Adapters
– MCP Transaction Resource Adapter (JRAC)
– Open Distributed Transaction Processing Resource Adapter (DTP-RA)
–
Java Database Connectivity (JDBC)
•
Resource adapters based on JCA
•
Structured Query Language (SQL) based
Querying DMSII using JDBC SQL Client Tools
DMSII-JDBC @ GSA
ClearPath
MCP
SQL Query Processor for ClearPath MCP DMSIIJProcessor
Presentation Tier/ Business Tier JSF/RichFaces POJOJDBC
Drive
r
Summary
•
Invocation interface lets ALGOL or COBOL program call
Java libraries.
•
Java 7 will allow tighter file system integration.
•
Consider the alternatives for accessing a DMSII database