1 package org.jacorb.transaction; 2 3 4 23 24 import org.apache.avalon.framework.logger.Logger; 25 26 import org.omg.CosTransactions.*; 27 import org.omg.CosNaming.*; 28 import java.io.*; 29 30 public class TransactionService 31 extends TransactionFactoryPOA 32 { 33 private static boolean initialized = false; 34 private static TransactionService factory; 35 private static TransactionFactory fact_ref; 36 private static CoordinatorImpl[] coordinators; 37 private static Timer timer; 38 private static int trans_id = 0; 39 private static org.omg.PortableServer.POA poa; 40 41 private static Logger logger; 42 43 static Timer get_timer(){ 44 return timer; 45 } 46 47 48 public static boolean is_initialized(){ 49 return initialized; 50 } 51 52 public static TransactionFactory get_reference(){ 53 return fact_ref; 54 } 55 56 static void release_coordinator(int hash_code) 57 { 58 coordinators[hash_code] = null; 59 } 60 61 private int find_free(){ 62 for (int i = 0;i < coordinators.length;i++){ 63 if (coordinators[i] == null){ 64 return i; 65 } 66 } 67 throw new org.omg.CORBA.INTERNAL (); 68 } 69 70 public Control create(int time_out) 71 { 72 trans_id++; 73 int ix; 74 synchronized(coordinators){ 75 ix = find_free(); 76 coordinators[ix] = new CoordinatorImpl(poa, trans_id, ix, time_out); 77 } 78 return coordinators[ix]._get_control(); 79 } 80 81 public Control recreate(PropagationContext ctx){ 82 throw new org.omg.CORBA.NO_IMPLEMENT (); 83 } 84 85 public static void start(org.omg.PortableServer.POA _poa, int max_of_trans) 86 { 87 if (initialized) 88 { 89 throw new org.omg.CORBA.INTERNAL (); 90 } 91 try 92 { 93 poa = _poa; 94 factory = new TransactionService(); 95 fact_ref = 96 TransactionFactoryHelper.narrow(poa.servant_to_reference(factory)); 97 98 coordinators = new CoordinatorImpl [max_of_trans]; 99 100 for (int i = 0;i < coordinators.length;i++) 101 { 102 coordinators[i] = null; 103 } 104 timer = new Timer(max_of_trans); 105 106 } 107 catch(Exception e) 108 { 109 e.printStackTrace(); 110 System.exit(1); 111 } 112 initialized = true; 113 } 114 115 116 public static void main( String [] args ) 117 { 118 org.omg.CORBA.ORB orb = 119 org.omg.CORBA.ORB.init(args, null); 120 logger = 121 ((org.jacorb.orb.ORB)orb).getConfiguration().getNamedLogger("jacorb.tx_service"); 122 try 123 { 124 org.omg.PortableServer.POA poa = 125 org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 126 poa.the_POAManager().activate(); 127 128 TransactionService transactionService = 129 new TransactionService(); 130 transactionService.start(poa,10); 131 132 if( args.length == 1 ) 133 { 134 136 PrintWriter ps = 137 new PrintWriter(new FileOutputStream(new File( args[0]))); 138 ps.println( orb.object_to_string( transactionService.get_reference() ) ); 139 ps.close(); 140 } 141 else 142 { 143 NamingContextExt nc = 144 NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService")); 145 NameComponent [] name = new NameComponent[1]; 146 name[0] = new NameComponent( "TransactionService", "service"); 147 nc.bind(name, transactionService.get_reference()); 148 } 149 if (logger.isInfoEnabled()) 150 logger.info("TransactionService up"); 151 } 152 catch ( Exception e ) 153 { 154 e.printStackTrace(); 155 } 156 orb.run(); 157 } 158 159 } 160 161 162 | Popular Tags |