1 22 package org.jboss.tm.iiop; 23 24 import org.omg.CORBA.Any ; 25 import org.omg.CORBA.LocalObject ; 26 import org.omg.CORBA.TCKind ; 27 import org.omg.CosTransactions.PropagationContext; 28 import org.omg.CosTransactions.PropagationContextHelper; 29 import org.omg.IOP.Codec ; 30 import org.omg.IOP.CodecPackage.InvalidTypeForEncoding ; 31 import org.omg.IOP.ServiceContext ; 32 import org.omg.PortableInterceptor.ClientRequestInfo ; 33 import org.omg.PortableInterceptor.ClientRequestInterceptor ; 34 import org.omg.PortableInterceptor.InvalidSlot ; 35 36 import org.jboss.iiop.CorbaORB; 37 import org.jboss.logging.Logger; 38 39 47 public class TxClientInterceptor 48 extends LocalObject 49 implements ClientRequestInterceptor 50 { 51 52 static final long serialVersionUID = -8021933521763745659L; 53 54 56 private static final int txContextId = org.omg.IOP.TransactionService.value; 57 private static int slotId; 58 private static Codec codec; 59 private static org.omg.PortableInterceptor.Current piCurrent; 60 private static Any emptyAny = null; 61 private static final Logger log = 62 Logger.getLogger(TxClientInterceptor.class); 63 private static final boolean traceEnabled = log.isTraceEnabled(); 64 65 67 static void init(int slotId, Codec codec, 68 org.omg.PortableInterceptor.Current piCurrent) 69 { 70 TxClientInterceptor.slotId = slotId; 71 TxClientInterceptor.codec = codec; 72 TxClientInterceptor.piCurrent = piCurrent; 73 } 74 75 79 public static void setOutgoingPropagationContext(PropagationContext pc) 80 { 81 Any any = CorbaORB.getInstance().create_any(); 82 PropagationContextHelper.insert(any, pc); 83 try 84 { 85 piCurrent.set_slot(slotId, any); 86 } 87 catch (InvalidSlot e) 88 { 89 throw new RuntimeException ("Exception setting propagation context: " 90 + e); 91 } 92 } 93 94 98 public static void unsetOutgoingPropagationContext() 99 { 100 try 101 { 102 piCurrent.set_slot(slotId, getEmptyAny()); 103 } 104 catch (InvalidSlot e) 105 { 106 throw new RuntimeException ("Exception unsetting propagation context: " 107 + e); 108 } 109 } 110 111 114 private static Any getEmptyAny() 115 { 116 if (emptyAny == null) 117 emptyAny = CorbaORB.getInstance().create_any(); 118 return emptyAny; 119 } 120 121 123 public TxClientInterceptor() 124 { 125 } 127 128 130 public String name() 131 { 132 return "TxClientInterceptor"; 133 } 134 135 public void destroy() 136 { 137 } 139 140 142 public void send_request(ClientRequestInfo ri) 143 { 144 if (traceEnabled) 145 log.trace("send_request: " + ri.operation()); 146 try 147 { 148 Any any = ri.get_slot(slotId); 149 if (any.type().kind().value() != TCKind._tk_null) 150 { 151 ServiceContext sc = new ServiceContext (txContextId, 152 codec.encode_value(any)); 153 ri.add_request_service_context(sc, 154 true ); 155 } 156 } 157 catch (InvalidSlot e) 158 { 159 throw new RuntimeException ("Exception getting slot in " + 160 "TxServerInterceptor: " + e); 161 } 162 catch (InvalidTypeForEncoding e) 163 { 164 throw new RuntimeException (e); 165 } 166 } 167 168 public void send_poll(ClientRequestInfo ri) 169 { 170 } 172 173 public void receive_reply(ClientRequestInfo ri) 174 { 175 } 177 178 public void receive_exception(ClientRequestInfo ri) 179 { 180 } 182 183 public void receive_other(ClientRequestInfo ri) 184 { 185 } 187 188 } 189 | Popular Tags |