1 package org.jacorb.trading.test; 2 3 import org.omg.CosTrading.*; 4 import org.omg.CosTrading.RegisterPackage.*; 5 import org.omg.CosTrading.LookupPackage.*; 6 import org.omg.CosTradingRepos.*; 7 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*; 8 import org.omg.CORBA.*; 9 import java.util.*; 10 15 16 public class ImportThread extends Thread { 17 private static final int TOTAL_QUERIES = 100; 18 private static final int MAX_SLEEP = 10; 19 20 private static long m_received_queries = 0; 21 private static Random m_rand = new Random(); 22 23 private Lookup[] m_lookup; 24 private String m_type; 25 private org.omg.CORBA.ORB m_orb; 26 27 public int m_correct_results = 0; 28 public int m_incorrect_results = 0; 29 30 public ImportThread(String name, Lookup[] lookup, String type, org.omg.CORBA.ORB orb){ 31 super(name); 32 m_lookup = lookup; 33 m_type = type; 34 m_orb = orb; 35 36 start(); 37 } 38 39 public void run (){ 40 org.omg.CosTrading.Policy[] _policies = new org.omg.CosTrading.Policy[3]; 42 _policies[0] = new org.omg.CosTrading.Policy(); 43 _policies[0].name = "exact_type_match"; 44 _policies[0].value = m_orb.create_any(); 45 _policies[0].value.insert_boolean(false); 46 _policies[1] = new org.omg.CosTrading.Policy(); 47 _policies[1].name = "use_dynamic_properties"; 48 _policies[1].value = m_orb.create_any(); 49 _policies[1].value.insert_boolean(false); 50 _policies[2] = new org.omg.CosTrading.Policy(); 51 _policies[2].name = "use_proxy_offers"; 52 _policies[2].value = m_orb.create_any(); 53 _policies[2].value.insert_boolean(false); 54 55 for (int _i = 0; _i < TOTAL_QUERIES; _i++){ 56 try { 57 String _constraint = "TRUE"; 59 String _preference = ""; 60 61 SpecifiedProps _desired_props = new SpecifiedProps(); 62 64 OfferSeqHolder _offers = new OfferSeqHolder(); 65 OfferIteratorHolder _iter = new OfferIteratorHolder(); 66 PolicyNameSeqHolder _limits = new PolicyNameSeqHolder(); 67 68 int n = Math.abs(m_rand.nextInt() % 4); 70 m_lookup[n].query(m_type, _constraint, _preference, _policies, _desired_props, 20, 71 _offers, _iter, _limits); 72 73 boolean[] _offer_ok = new boolean[8]; 74 if (_offers.value != null && _offers.value.length == 8){ 75 76 for (int _j = 0; _j < 8; _j++) 78 _offer_ok[_j] = false; 79 80 for (int _j = 0; _j < 8; _j++){ 82 String _name = _offers.value[_j].properties[0].value.extract_string(); 83 _offer_ok[Integer.parseInt(_name)] = true; 84 } 85 86 boolean _result = true; 88 for (int _j = 0; _j < 8; _j++) 89 _result &= _offer_ok[_j]; 90 91 System.out.println("(" + m_received_queries++ + " / " + _i + ") Thread " + getName() + 92 " received a correct result"); 93 m_correct_results++; 94 } 95 else { 96 System.out.println("(" + m_received_queries++ + " / " + _i + ") Thread " + getName() + 97 " received an incorrect result"); 98 System.out.println("Reason: only " + _offers.value.length + " offers instead of 8 received"); 99 m_incorrect_results++; 100 } 101 102 sleep(Math.abs(m_rand.nextInt() % MAX_SLEEP)); 103 104 } catch (Exception _e){ 105 System.out.println("(" + m_received_queries++ + " / " + _i + ") Thread " + getName() + 106 " caught an exception"); 107 _e.printStackTrace(); 108 m_incorrect_results++; 109 } 110 } 111 System.out.println("(" + getName() + ") Finished querying. Received " + m_correct_results + 112 "correct results and " + m_incorrect_results + " incorrect results"); 113 114 } 115 } 117 118 119 | Popular Tags |