📄 vericlient.java
字号:
/** * VeriClient.java */import com.sap.mw.jco.*;import java.io.*;import java.util.*;/** * @version 1.0 * @author Bernd Follmeg *///******************************************************************************public class VeriClient implements JCO.PoolChangedListener {//****************************************************************************** public void poolChanged(JCO.Pool pool) { //StringBuffer sb = new StringBuffer("poolChanged: ").append(pool.getName()) // .append("#allocated connections: ").append(pool.getNumUsed()).append(", ") // .append("#connections in pool: ").append(pool.getCurrentPoolSize() - pool.getNumUsed()); //System.out.println(sb.toString()); } protected static String properties_filename = "./vericlient.properties"; protected static Properties login_properties = null; protected static Test[] tests = null; static { tests = new Test[4]; tests[0] = new TestConnections(); tests[1] = new TestContainers(); tests[2] = new TestRepository(); tests[3] = new TestFunctionCalls(); } public static void setLoginProperties(Properties props) { login_properties = props; } /** * Returns the login properties */ public static Properties getLoginProperties() { if (login_properties == null) { login_properties = new Properties(); try { login_properties.load(new FileInputStream(properties_filename)); } catch (IOException ex) { System.out.println(ex); System.exit(1); }//try } return login_properties; } public static void printMethod(String method) { System.out.print(" " + method); int istart = 60 - method.length(); for (int i = istart; i > 0; i--) System.out.print('.'); } public static void printStatus(Exception ex) { String status = (ex == null ? "ok" : "failed"); System.out.println(status); if (ex != null) { System.out.println(); System.out.println(); ex.printStackTrace(); System.exit(1); }//if } public static void printProlog() { String [] localArgs = {"-stdout"}; new com.sap.mw.jco.About().show(localArgs); // this code was replaced by info from About.java /* String libjrfc_version = JCO.getMiddlewareProperty("jco.middleware.libjrfc_version"); String libjrfc_path = JCO.getMiddlewareProperty("jco.middleware.libjrfc_path"); String librfc_version = JCO.getMiddlewareProperty("jco.middleware.librfc_numversion"); String jversion = System.getProperty("java.version"); String jvendor = System.getProperty("java.vendor"); String osname = System.getProperty("os.name") + " " + System.getProperty("os.version") + " for " + System.getProperty("os.arch"); */ System.out.println("--------------------------------------------------------------------------------------"); System.out.println("----------------------------- Jayco TestSuite ----------------------------------------"); System.out.println("--------------------------------------------------------------------------------------"); /* System.out.println(" Java Version: " + jversion + " " + jvendor); System.out.println(" Operating System: " + osname); System.out.println(" JCo API Version: " + JCO.getVersion()); System.out.println(" JCo Middleware Version: " + JCO.getMiddlewareVersion()); if (librfc_version != null) { System.out.println(" JCo librfc Version: " + librfc_version); }//if if (libjrfc_version != null) { System.out.println(" JCo libjRFC Version: " + libjrfc_version); }//if if (libjrfc_path != null) { System.out.println(" JCo libjRFC Path: " + libjrfc_path); }//if try { String remote = "???"; JCO.Client client = JCO.createClient(getLoginProperties()); client.connect(); JCO.Attributes a = client.getAttributes(); if (a.getPartnerType() == '2' || a.getPartnerType() == '3') { remote = "R/" + a.getPartnerType() + " " + a.getPartnerRelease(); } else { remote = a.getPartnerType() + " " + a.getPartnerRelease(); }//if System.out.println(" Remote System: " + remote); System.out.println(" Own codepage: " + a.getOwnCodepage()); System.out.println(" Remote codepage: " + a.getPartnerCodepage()); client.disconnect(); } catch (Exception ex) {} */ System.out.println(" Date: " + new Date()); System.out.println("--------------------------------------------------------------------------------------"); System.out.println("------------------------- Connection Parameters --------------------------------------"); System.out.println("--------------------------------------------------------------------------------------"); Properties p = getLoginProperties(); for (Enumeration e = p.keys(); e.hasMoreElements(); ) { String key = (String)e.nextElement(); String val = (String)p.get(key); System.out.print(" " + key + ": "); int istart = 22 - key.length(); for (int i = istart; i > 0; i--) System.out.print(' '); System.out.println(val); }//for System.out.println("--------------------------------------------------------------------------------------"); System.out.println(" Test ------------------------------------------------------ Status ------------------"); System.out.println("--------------------------------------------------------------------------------------"); } public static void printEpilog() { System.out.println("--------------------------------------------------------------------------------------"); System.out.println("---------------------------------- Done ----------------------------------------------"); System.out.println("--------------------------------------------------------------------------------------"); } /** * Base class for all test classes */ protected static abstract class Test { public abstract void run(); } /** * Test the opening, closing of connections */ public static class TestConnections extends Test { /** * Test opening, closing, attributes of a * simple non-pooled connection */ public void testSimpleConnection() { JCO.Client client = null; try { printMethod("JCO.createClient()"); client = JCO.createClient(getLoginProperties()); printStatus(null); printMethod("client.connect()"); client.connect(); printStatus(null); printMethod("client.getAttributes()"); client.getAttributes(); printStatus(null); printMethod("client.disconnect()"); client.disconnect(); printStatus(null); } catch (Exception ex) { printStatus(ex); }//try } /** * Test creating, deletion of a client pool. */ public void testPooledConnection() { JCO.Client client1, client2; try { printMethod("JCO.addClientPool() single-threaded"); JCO.addClientPool("BF",10,getLoginProperties()); printStatus(null); printMethod("JCO.getClient() single-threaded"); client1 = JCO.getClient("BF"); //client2 = JCO.getClient("BF"); printStatus(null); printMethod("JCO.releaseClient() single-threaded"); JCO.releaseClient(client1); //JCO.releaseClient(client2); printStatus(null); printMethod("JCO.removeClientPool() single-threaded"); JCO.removeClientPool("BF"); printStatus(null); } catch (JCO.Exception ex) { printStatus(ex); JCO.removeClientPool("BF"); }//try try { printMethod("JCO.addClientPool() multi-threaded"); JCO.addClientPool("BF",1,getLoginProperties()); printStatus(null); //System.out.println("Main.Thread: " + Thread.currentThread().getName()); ClientProcess p1 = new ClientProcess("T1"), p2 = new ClientProcess("T2"), p3 = new ClientProcess("T3"); p1.start(); try { Thread.currentThread().sleep(200); } catch (InterruptedException ex) {} p2.start(); try { Thread.currentThread().sleep(500); } catch (InterruptedException ex) {} p3.start(); try { p1.join(); p2.join(); p3.join();} catch (InterruptedException ex) {} printMethod("JCO.removeClientPool() multi-threaded"); JCO.removeClientPool("BF"); printStatus(null); } catch (JCO.Exception ex) { printStatus(ex); JCO.removeClientPool("BF"); }//try try { printMethod("JCO.addClientPool() limit = 50"); JCO.addClientPool("BF",50,getLoginProperties()); printStatus(null); printMethod("JCO.getClient() limit = 50"); JCO.Client[] clients = new JCO.Client[50]; for (int i = 0; i < clients.length; i++) clients[i] = JCO.getClient("BF"); printStatus(null); printMethod("JCO.releaseClient() limit = 50"); for (int i = 0; i < clients.length; i++) JCO.releaseClient(clients[i]); printStatus(null); printMethod("JCO.removeClientPool() limit = 100"); JCO.removeClientPool("BF"); printStatus(null); } catch (JCO.Exception ex) { printStatus(ex); JCO.removeClientPool("BF"); }//try } protected static class ClientProcess extends Thread { public ClientProcess(String name) { super(name); } public void run() { //System.out.println("Starting thread " + this.getName()); try { //printMethod("JCO.getClient("+ getName() +") multi-threaded"); //System.out.println("Thread " + this.getName() + " calls getClient()"); JCO.Client client = JCO.getClient("BF"); //printStatus(null); try { sleep(2000); } catch (InterruptedException ex) {} //printMethod("JCO.releaseClient("+ getName() +") multi-threaded"); //System.out.println("Thread " + this.getName() + " calls releaseClient()"); JCO.releaseClient(client); //printStatus(null); } catch (JCO.Exception ex) { printStatus(ex); }//try } } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -