Java tutorial
package com.dc.tes.adapter.startup.remote; import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.dc.tes.adapter.IReplyAdapter; import com.dc.tes.adapter.framework.DefaultReplyAdapterEnvContext; import com.dc.tes.adapter.remote.DefaultReplyAdapterHelper; import com.dc.tes.adapter.util.ConfigHelper; /** * ?"?"(?) * * @author * */ public class StartUpRemoteForReply extends Thread { private static final Log log = LogFactory.getLog(StartUpRemoteForReply.class); private DefaultReplyAdapterHelper m_adpterHelper = null; private Properties m_props = null; IReplyAdapter m_replyAdapterInstance = null; public StartUpRemoteForReply(Properties prop) throws Exception { if (!((String) prop.get("adapterType")).toUpperCase().equals("REPLY")) throw new Exception("??" + prop.get("adapterType") + "?!"); m_props = prop; } public void run() { startAdapter(m_props); // ?? try { while (!Thread.currentThread().isInterrupted()) { Thread.sleep(500); } } catch (InterruptedException e) { log.debug("?"); shutdownAdapter(); } } private void shutdownAdapter() { // ?? if (null != m_replyAdapterInstance) { // if (m_adpterHelper != null) m_adpterHelper.unReg2TES(); m_replyAdapterInstance.Stop(); } log.info("??" + m_props.getProperty("CHANNELNAME") + "."); } /** * "?"?,??? * @param props ???(ComLayer.config.xml) */ public void startAdapter(Properties props) { String adapterName = props.getProperty("CHANNELNAME"); try { String clsName = "com.dc.tes.adapterlib." + (String) props.get("adapterPlugIn"); m_replyAdapterInstance = (IReplyAdapter) ConfigHelper.class.getClassLoader().loadClass(clsName) .newInstance(); System.out.println("???" + clsName); log.error("???" + clsName); // License m_props.setProperty("SIMTYPE", m_replyAdapterInstance.AdapterType()); m_adpterHelper = new DefaultReplyAdapterHelper(m_props); // byte[] config = m_adpterHelper.reg2TES(); // ? if (m_replyAdapterInstance.Init(new DefaultReplyAdapterEnvContext(config, m_adpterHelper))) { m_adpterHelper.SetConfigProperty(m_replyAdapterInstance.GetAdapterConfigProperties()); System.out.println("??" + adapterName + "?Init?."); log.info("??" + adapterName + "?Init?."); // ??? m_replyAdapterInstance.Start(); } else { m_adpterHelper.unReg2TES(); // ?m_replyAdapterInstance.Stop() System.out.println("??" + adapterName + "?Init."); log.error("??" + adapterName + "?Init."); } } catch (InstantiationException e) { log.error("??!?"); System.out.println("??!?"); } catch (IllegalAccessException e) { log.error("??!?[" + e.getMessage() + "]"); System.out.println( "??!?[" + e.getMessage() + "]"); } catch (ClassNotFoundException e) { log.error("???!?[" + e.getMessage() + "]"); System.out.println( "???!?[" + e.getMessage() + "]"); } catch (Exception e) { log.error("??[" + e.getMessage()); System.out.println("??[" + e.getMessage()); } System.out.println("??" + adapterName + "??."); log.info("??" + adapterName + "??."); } }