All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.com.ibm.as400.vaccess.VJavaGetResult Maven / Gradle / Ivy

The newest version!
///////////////////////////////////////////////////////////////////////////////
//                                                                             
// JTOpen (IBM Toolbox for Java - OSS version)                              
//                                                                             
// Filename: VJavaGetResult.java
//                                                                             
// The source code contained herein is licensed under the IBM Public License   
// Version 1.0, which has been approved by the Open Source Initiative.         
// Copyright (C) 1997-2000 International Business Machines Corporation and     
// others. All rights reserved.                                                
//                                                                             
///////////////////////////////////////////////////////////////////////////////

package com.ibm.as400.vaccess;

import javax.swing.JTextArea;
import com.ibm.as400.access.AS400;
import com.ibm.as400.access.JavaApplicationCall;
import com.ibm.as400.access.Trace;

/**
 * The VJavaGetResult class runs the java application
 * and returns its results to the VJavaApplicationCall.
 */
class VJavaGetResult implements Runnable
{
  private static final String copyright = "Copyright (C) 1997-2000 International Business Machines Corporation and others.";

    // Private variable representing the object of VJavaApplicationCall.
    private VJavaApplicationCall vJavaAppCall_;

    // Private variable representing the object of JavaApplicationCall.
    private JavaApplicationCall javaAppCall_;

    // Private variable indicating when the java application is
    // complete.
    private boolean javaAppRunOver_ = false;

    // Private variable representing the thread that runs the method call
    // of JavaApplicationCall.
    private Thread runAppThread_;

    // Private variable representing the thread that gets the results
    // from the java application.
    private Thread outputThread_;

    // Private variable representing the thread that gets the error information.
    private Thread errorThread_;

    // This counter is used to make sure we don't close the sockets
    // before all output is out of the pipe.  The main thread (the
    // one just returned from the the program call) will wait to
    // close sockets until all data is out of the sockets.
    long readCounter_ = 0;                            // @D1A

    /**
     * Constructs a VJavaGetResult object.
     *
     * @param vJavaAppCall The VJavaApplicationCall object.
    **/
    public VJavaGetResult(VJavaApplicationCall vJavaAppCall)
    {
        vJavaAppCall_ = vJavaAppCall;
        javaAppCall_  = vJavaAppCall_.getJavaApplicationCall();
    }


    private void delay()                                     //@D1a
    {                                                        //@D1a
       try { Thread.sleep(100); }                            //@D1a
       catch (Exception e) {}                                //@D1a
    }                                                        //@D1a


    /**
     * Stops the threads.
    **/
    protected void finalize() throws Throwable
    {
        runAppThread_ = null;
        errorThread_  = null;
        outputThread_ = null;
        super.finalize();
    }

    /**
     * Starts the threads for running java application and gets the results.
    **/
    public void play()
    {
        javaAppRunOver_ = false;
        outputThread_ = new Thread(this);
        errorThread_  = new Thread(this);
        outputThread_.start();
        errorThread_.start();

        runAppThread_ = new Thread(this);
        runAppThread_.start();
    }

    /**
     * Runs the java application and gets the results.
     **/
    public void run()
    {

        if(Thread.currentThread() == runAppThread_)
        {
            vJavaAppCall_.setJavaAppRunOver(false);
            try
            {
                javaAppCall_.run();
            }
            catch(Exception e)
            {
                Trace.log(Trace.ERROR,e.toString());
                vJavaAppCall_.appendOutput(e.toString());
            }

            com.ibm.as400.access.AS400Message[] messageList = javaAppCall_.getMessageList();
            if ((messageList != null) && (messageList.length > 0 ))
            {
                for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy