⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workbean.java.svn-base

📁 通讯采集软件
💻 SVN-BASE
字号:
/*
 * workBean.java
 *
 * Created on 2003年12月31日, 上午9:50
 */

package pbs.application.iiop.GUI.huadong;

import java.util.*;
import java.io.*;
import javax.naming.*;
import javax.ejb.*;
import javax.rmi.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import pbs.sessionbean.ejb.*;
import pbs.service.function.*;
import pbs.service.struct.*;

public class workBean {
    private HuaDongHome hdHome = null;
    private ProcessFrontDataHome pfdHome = null;
    private int m_debug_no = 200;
    private boolean m_status_ok = false;
    /** Creates a new instance of workBean */
    public workBean(int server_no) {
        int ret;

        ret = init(server_no);
        if (ret < 0) {
            processDebug.writeDebug(m_debug_no+100,"Huadong workBean construct Error #1");
            m_status_ok = false;
        }
        else {
            processDebug.writeDebug(m_debug_no+100,"Huadong workBean construct OK !!!!");
            m_status_ok = true;
        }
    }

    public int init(int server_no) {
        String nameFac = null;
        String url = null;
        String jndinameHD = null;
        String jndinamePFD = null;
        Context initial;
        Object objref;
        String noStr = null;
        Properties config = new Properties();
        commonFunc cf = new commonFunc(m_debug_no);

        try{
            config.load(new FileInputStream(Config.CONFIG_FILE_NAME));
            if (server_no == Constant.SERVER_NO_SERVER1) {
                url = config.getProperty(Config.IIOP_URL1);
                if (url == null) {
                    url = "iiop://ibm13:2809/";
                }
            }

            else if (server_no == Constant.SERVER_NO_SERVER2) {
                url = config.getProperty(Config.IIOP_URL2);
                if (url == null) {
                    url = "iiop://ibm12:2809/";
                }
            }
            else {
                url = config.getProperty(Config.IIOP_URL);
                if (url == null) {
                    url = "iiop://ibm13:2809/";
                }
            }
            nameFac = config.getProperty(Config.NAMING_FACTORY);
            if (nameFac == null) {
                nameFac = "com.ibm.websphere.naming.WsnInitialContextFactory";
            }

            jndinameHD = config.getProperty(Config.HUADONG_JNDI);
            if (jndinameHD == null) {
                jndinameHD = "cell/clusters/JSDLCluster/ejb/HuaDong";
            }

            Properties m_Configure = new Properties();
            m_Configure.load(new FileInputStream("../sys/pbs.conf"));
            jndinamePFD = m_Configure.getProperty("INSERT_DATA_JNDI");
            if (jndinamePFD == null) {
                jndinamePFD = "cell/clusters/JSDLCluster/ejb/ProcessFrontData";
            }

            noStr = config.getProperty(Config.DEBUG_NO_OF_HUADONG);
            if (noStr == null) {
                m_debug_no = 121;
            }
            else {
                try{
                    m_debug_no = (Integer.parseInt(noStr));
                }
                catch(NumberFormatException ex) {
                    m_debug_no = 121;
                }
            }
        }
        catch(Exception ex) {
            nameFac = "com.ibm.websphere.naming.WsnInitialContextFactory";
            if (server_no == Constant.SERVER_NO_SERVER1) {
                url = "iiop://ibm12:2809/";
            }
            else if (server_no == Constant.SERVER_NO_SERVER2) {
                url = "iiop://ibm13:2809/";
            }
            else {
                url = "iiop://ibm12:2809/";
            }
            jndinamePFD = "cell/clusters/JSDLCluster/ejb/ProcessFrontData";
            jndinameHD = "cell/clusters/JSDLCluster/ejb/HuaDong";
            m_debug_no = 121;
        }
        try{
            Properties env = new Properties();
            env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, nameFac);
            env.put(javax.naming.InitialContext.PROVIDER_URL, url);
            pbs.service.util.Calendar cal1 = pbs.service.util.Calendar.getInstance();
            long nowTime1 = cal1.getTimeInMillis()/1000;
            processDebug.writeDebug(m_debug_no+100,"huadong workBean Begin to Connnect Server,Time:" + cf.getTimeString(nowTime1));
            initial = new InitialContext(env);
            System.out.println("jndinameHD = "+jndinameHD);
            objref = initial.lookup(jndinameHD);
            hdHome = (HuaDongHome)PortableRemoteObject.narrow(objref,HuaDongHome.class);
            objref = initial.lookup(jndinamePFD);
            System.out.println("lookup over");
            pfdHome = (ProcessFrontDataHome)PortableRemoteObject.narrow(objref,ProcessFrontDataHome.class);
            pbs.service.util.Calendar cal2 = pbs.service.util.Calendar.getInstance();
            long nowTime2 = cal2.getTimeInMillis()/1000;
            processDebug.writeDebug(m_debug_no+100,"huadong workBean Success to Connect Server,Time:" + cf.getTimeString(nowTime2));
        }
        catch(Exception ex) {
            processDebug.writeDebug(m_debug_no+100,"init in huadong workBean Error #2");
            DataOutputStream ds = processDebug.getDebugStream(m_debug_no+100);
            ex.printStackTrace(new PrintStream(ds));
            processDebug.closeDebugStream(ds);
            m_status_ok = false;
            return -1;
        }
        m_status_ok = true;
        return 1;
    }

    public boolean getStatusOK() {
        return m_status_ok;
    }

    public Collection getMeters() {
        Collection workCo = null;
        HuaDong hdBean = null;

        if (!m_status_ok) {
            processDebug.writeDebug(m_debug_no+100,"getCollection in huadong workBean Error #1");
            return null;
        }
        try {
            hdBean = (HuaDong)PortableRemoteObject.narrow(hdHome.create(),HuaDong.class);
            if (hdBean == null) {
                processDebug.writeDebug(m_debug_no + 100,
                "getCollection in huadong workBean Error #2");
                System.out.println("getCollection in huadong workBean Error #2");
                return null;
            }
            hdBean.setDebugNo(m_debug_no);
            workCo = hdBean.getMeters();
            System.out.println("workCo.size()  =  "+workCo.size());
            hdBean.remove();
        }
        catch(java.rmi.NoSuchObjectException ex) {
            System.out.println("getCollection in huadong workBean Error #3");
            processDebug.writeDebug(m_debug_no+100,"getCollection in huadong workBean Error #3");
            DataOutputStream ds = processDebug.getDebugStream(m_debug_no+100);
            ex.printStackTrace(new PrintStream(ds));
            processDebug.closeDebugStream(ds);
            m_status_ok = false;
            return null;
        }
        catch(java.rmi.MarshalException ex) {
            System.out.println("getCollection in huadong workBean Error #4");
            processDebug.writeDebug(m_debug_no+100,"getCollection in huadong workBean Error #4");
            DataOutputStream ds = processDebug.getDebugStream(m_debug_no+100);
            ex.printStackTrace(new PrintStream(ds));
            processDebug.closeDebugStream(ds);
            m_status_ok = false;
            return null;
        }
        catch(Exception ex) {
            System.out.println("getCollection in huadong workBean Error #5");
            processDebug.writeDebug(m_debug_no+100,"getCollection in huadong workBean Error #5");
            DataOutputStream ds = processDebug.getDebugStream(m_debug_no+100);
            ex.printStackTrace(new PrintStream(ds));
            processDebug.closeDebugStream(ds);
            return null;
        }
        return workCo;
    }

    public int work(SendDataClass sdc) {
        int ret;
        ProcessFrontData pfdBean = null;

        if (!m_status_ok) {
            processDebug.writeDebug(m_debug_no+100,"work in huadong workBean Error #1");
            return -1;
        }
        try {
            pfdBean = (ProcessFrontData) PortableRemoteObject.narrow(pfdHome.create(), ProcessFrontData.class);
            if (pfdBean == null) {
                processDebug.writeDebug(m_debug_no + 100,"work in huadong workBean Error #2");
                return -1;
            }
            pfdBean.setDebugNo(m_debug_no);
            ret = pfdBean.processData(sdc);
            pfdBean.remove();
        }
        catch (Exception ex) {
            processDebug.writeDebug(m_debug_no+100,"Error in insert huadong data");
            ex.printStackTrace();
            return -1;
        }
        try{
            Thread.sleep(500);
        }
        catch(InterruptedException ie) {
            processDebug.writeDebug(m_debug_no+100,"Sleep Error in insertD huadong ata");
        }
        return 1;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -