• No results found

Application Development A Cocktail of Java and MCP. MCP Guru Series Dan Meyer & Pramod Nair

N/A
N/A
Protected

Academic year: 2021

Share "Application Development A Cocktail of Java and MCP. MCP Guru Series Dan Meyer & Pramod Nair"

Copied!
37
0
0

Loading.... (view fulltext now)

Full text

(1)

Application Development

A

Cocktail of Java and MCP

MCP Guru Series

(2)

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

(3)

“A Cocktail of Java and MCP”

(4)

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?

(5)

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

(6)

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 …

(7)

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

(8)

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

(9)

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

(10)

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;

} }

(11)

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; }

(12)

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;

(13)

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) { …; } } }

(14)

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

(15)

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

(16)

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.

(17)

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.

(18)

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.

(19)

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

(20)

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.

(21)

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

(22)

“A Cocktail of Java and MCP”

(23)

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:

(24)

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),

(25)

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,

(26)

McpFileAttributes Class

Provides most MCP attributes for a file.

All the various time stamps.

Title

Note

(27)

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

(28)

Open Options

Specify any of these when opening a file.

File Options

Record Options

Buffers

Fold

BufferSize

IncludeSequenceNumbers

HostName

NoCrLf

IntName

StripSpaces

Truncate

Unfold

(29)

Initial File Attributes

Specify any of these when creating a file.

areaLength

areas

blockSize

clearAreas

familyIndex

frameSize

hostName

maximumRecordSize

note

sensitiveData

userInfo

(30)

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

(31)

“A Cocktail of Java and MCP”

(32)

Accessing DMSII From Java

DMSII Databases

D

M

S

Q

L

(33)

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

(34)

Querying DMSII using JDBC SQL Client Tools

(35)

DMSII-JDBC @ GSA

ClearPath

MCP

SQL Query Processor for ClearPath MCP DMSII

JProcessor

Presentation Tier/ Business Tier JSF/RichFaces POJO

JDBC

Drive

r

(36)

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

from Java

(37)
Bouncy Castle Java Naming and Directory Interface (JNDI) http://www.componentsource.com/features/java-components/index.html

References

Related documents

In accordance with the insured categories outlined below for personal liability insurance, we protect the assets of the insured persons from the financial consequences of

Changes in sensory attributes over time after harvest were observed and all 9:00hrs samples were rated highly for each attribute compared to the 12:00hrs and 15:00hrs samples

This includes (numbers correspond to scenarios): (1) delete any number called Tennis Club; (2) delete Jack’s – or Jack Hall’s - mobile number; (3) Delete Jack Straw, rename Jack

Also, the currently used asphalt cements with penetration grades (40-50) and (60-70) were tested by both of conventional test methods and Superpave methods to determine the

Intercomparison of global river discharge simulations focusing on dam operation --- Part II: Multiple models analysis in two case-study river basins, Missouri-Mississippi and

 Under ADB Education IV Project, rehabilitation and expansion of the 31 out of the targeted 42 traditional secondary school is ongoing with additional 15 seed secondary

Furthermore, many signs indicate that the pharmaceutical industry – and in particu- lar the clinical research sector – will be relying on the help and support of freelancers more

The growth in recognition of the Islamic education system, particularly Pesantren and Madrasah education, has brought new expectations and challenges for all stakeholders of