Wednesday 5 January 2011

JAVA ile MAINFRAME EKRAN (CICS) SIMULASYONU

MAINFRAME SCREEN PROCESSING SIMULATION WITH JAVA

This is a simple simulation of mainframe screen processing in application servers
such as CICS or Natural-ADABAS processing.

Many mainframe programs are straight forward single flow programs. For example a COBOL or PLI program begins and some does initiation. After that it needs to take input and makes a CICS or NATURAL call to display a screen, after the user completes the input the program receives it via the CICS or NATURAL substructure.

Convertin mainframe programs require the conversion of this substructure also. It is not only the language and the conversion of statements line by line but also the conversion of the framework they reside in.

My previous prototype shows how a simple JAVA program can be started from a JSP screen. Please first read and play with the code I have provided there. It is fully operational.

This simple prototype will demonstrate how you can start a JAVA program(a transaction if you like) from a given library jar. This JAVA program will begin and run till it needs to get user input and so display a JSP. It displays the JSP and waits its output. The new JSP of which identity is specified by the JAVA program opens.

I will take the liberty to stop there. The JAVA program remains in waitin situation and the JSP screen remains as it is on the screen. I will provide the output of the thread management, how the HTTP thread waits the JAVA thread and vice versa.

After this point, one could continue with the new JSP screen notifies the JAVA thread
at the SUBMIT action andputs itself into wait. JAVA thread proceeds and does the JAVA work till the next JSP screen and then it notifies the HTTP thread and puts itself into wait.

I chose not to do these because it makes the demonstration unnecessarily complex and long. I also have to respect the work and interest of the others as well as mine. If you are interested to convert mainframe programs to JAVA-UNIX or WIN please send me an e-mail at arsaral (AT) yahoo.com. I may give more info personally.

A detailed explanation and the code of the working application follows:




web.xml
-------
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Transaction Call Simulation</display-name>

<welcome-file-list>
<welcome-file>getProgName.jsp</welcome-file>
</welcome-file-list>

</web-app>


getProgName.jsp
---------------
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
String tranName=request.getParameter("tranName"); if(tranName==null) tranName="DVP1000";
System.out.println(tranName);
if (tranName != "DVP1000") pageContext.forward("transactionCall.jsp");
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<form action="getProgName.jsp" method="post">
<table cellpadding="5">
<tr>
<td align="right">Transaction Name (enter testClass):</td>
<td align='left' style='text-align:left'>
<input id="s1" name="tranName" size="8" value="<%=tranName%>"/>
</td>
</tr>
</table>
</form>
</body>
</html>



transactionCall.jsp
-------------------
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="testPackage.*" %>

<%
String tranName = request.getParameter("tranName");
if (tranName == null) {
tranName = "DVP1000";
}
ARSlibrary ARSlib = new ARSlibrary();
ARSlib.invokeProgramThread("testPackage." + tranName);
System.out.println("TRANSACTIONCALL.JSP: Transaction is called -------(before lock.wait())");

synchronized (ARSlib.lock) {
try {
System.out.println("TRANSACTIONCALL.JSP: ------- before lock.wait()");
ARSlib.lock.wait();
System.out.println("TRANSACTIONCALL.JSP: -------- after lock.wait()");
} catch (java.lang.InterruptedException ie) {
System.out.println("TRANSACTIONCALL.JSP:--------- lock.wait()is interrupted");
}
System.out.println("TRANSACTIONCALL.JSP: ----------- after try catch");

}
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
<%
pageContext.forward(ARSlib.nextScreen);
%>


ARSlibrary.java
---------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package testPackage;

public class ARSlibrary {

public static Object lock = new Object();
public static Object libLock = new Object();
public String nextScreen = "";

public ARSlibrary() {
System.out.println("ARSlibrary's constructor");
}

public void invokeProgram(String name) throws Exception {
Class<? extends ARSprogram> np = (Class<? extends ARSprogram>) Class.forName(name);
if (np == null) {
throw new Exception("Program " + name + " not in this library");
}
ARSprogram a = (ARSprogram) np.newInstance();
a.ARSlib = this;
a.main();
}
public void invokeProgramThread(String name) throws Exception {
ARSthread thread = new ARSthread(name);
thread.ARSlib = this;
thread.start();
}
}


ARSthread.java
--------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testPackage;

/**
*
* @author Ali Riza SARAL
*/
public class ARSthread extends Thread {
public ARSlibrary ARSlib = new ARSlibrary();
String progName;

public ARSthread(String progName) {
this.progName = progName;
}

public void run() {
try{
ARSlib.invokeProgram(this.progName);
} catch(java.lang.Exception e) {System.out.println("ARSthread exception");}
}
}



ARSprogram.java
---------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package testPackage;

public class ARSprogram {
ARSlibrary ARSlib = new ARSlibrary();
public void main() {
System.out.println("ARSprogram's constructor");
}
}



testClass.java
--------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testPackage;

public class testClass extends ARSprogram {

public testClass() {
System.out.println("testClassS constructor");
}

public void main() {

System.out.println("TESTCLASS.JAVA: has begun! -------- before JSP call");
System.out.println("TESTCLASS.JAVA: work done --------- now open new JSP");
ARSlib.nextScreen = "displayScreen.jsp";
synchronized (ARSlib.libLock) {
synchronized (ARSlib.lock) {
ARSlib.lock.notify();
System.out.println("TESTCLASS.JAVA: enable screen processing ----------- after lock.notify()");
}
try {
System.out.println("TESTCLASS.JAVA: wait the users screen entry ----------- before libLock.wait()");
ARSlib.libLock.wait();
System.out.println("TESTCLASS.JAVA: ------------ after libLock.wait()");
} catch (java.lang.InterruptedException ie) {
System.out.println("TESTCLASS.JAVA: libLock.wait()is interrupted");
}
}

System.out.println("TESTCLASS.JAVA: after the first JSP entry!");
}
}



displayScreen.jsp
-----------------
<%--
Document : displayScreen
Created on : 05.Oca.2011, 14:04:58
Author : Ali Riza SARAL
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
System.out.println("next screen displayScreen.jsp is opened");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>1st Screen</title>
</head>
<body>
<h1>First screen of the CICS APP</h1>
</body>
</html>



OUTPUTS at the server log
-------------------------
INFO: testClass
INFO: ARSlibrary's constructor
INFO: ARSlibrary's constructor
INFO: TRANSACTIONCALL.JSP: Transaction is called -------(before lock.wait())
INFO: TRANSACTIONCALL.JSP: ------- before lock.wait()
INFO: ARSlibrary's constructor
INFO: testClassS constructor
INFO: TESTCLASS.JAVA: has begun! -------- before JSP call
INFO: TESTCLASS.JAVA: work done --------- now open new JSP
INFO: TESTCLASS.JAVA: enable screen processing ----------- after lock.notify()
INFO: TESTCLASS.JAVA: wait the users screen entry ----------- before libLock.wait()
INFO: TRANSACTIONCALL.JSP: -------- after lock.wait()
INFO: TRANSACTIONCALL.JSP: ----------- after try catch
INFO: next screen displayScreen.jsp is opened