1 39 package org.objectweb.jotm.ots; 40 41 import java.util.Collections ; 43 import java.util.HashMap ; 44 import java.util.Map ; 45 46 import org.objectweb.jotm.Current; 47 import org.objectweb.jotm.InternalTransactionContext; 48 import org.objectweb.jotm.TransactionContext; 49 import org.omg.IOP.ServiceContext ; 50 import org.omg.PortableInterceptor.ForwardRequest ; 51 import org.omg.PortableInterceptor.ORBInitInfo ; 52 import org.omg.PortableInterceptor.ServerRequestInfo ; 53 import org.omg.PortableInterceptor.ServerRequestInterceptor ; 54 55 63 public class OTSServerTransactionInterceptor extends OTSInterceptor implements ServerRequestInterceptor { 64 65 68 private static Current current = null; 69 70 73 private Map contexts = Collections.synchronizedMap(new HashMap ()); 74 76 79 private String interceptorName = "OTSServerTransactionInteceptor"; 80 81 84 public OTSServerTransactionInterceptor(ORBInitInfo info) { 85 super(info); 86 } 87 88 92 public String name() { 93 return interceptorName; 94 } 95 96 101 public void receive_request_service_contexts(ServerRequestInfo jri) throws ForwardRequest { 102 try { 103 TransactionContext txCtx = decodeCorbaPropagationContext(jri.get_request_service_context(TX_CTX_ID)) ; 104 105 if ( txCtx != null ) { 106 Object key = new Integer (jri.request_id()); 107 contexts.put (key, txCtx); 108 } 109 } catch (org.omg.CORBA.BAD_PARAM b) { 110 } catch (Exception e) { 112 throw new ForwardRequest (); 113 } 114 } 115 116 121 public void receive_request(ServerRequestInfo jri) throws ForwardRequest { 122 if (current == null) { 123 current = Current.getCurrent(); 124 } 125 126 if (current != null) { 127 Object key = new Integer (jri.request_id()); 128 InternalTransactionContext txCtx = (InternalTransactionContext) contexts.remove(key); 129 130 current.setPropagationContext(txCtx, false); 132 } 133 } 134 135 140 public void send_reply(ServerRequestInfo jri) { 141 142 if (current == null) { 143 current = Current.getCurrent(); 144 } 145 146 if (current != null) { 147 try { 148 TransactionContext txCtx = current.getPropagationContext(true); 150 ServiceContext pContext = null ; 151 152 if (txCtx != null) { 153 154 pContext = buildCorbaPropagationContext(txCtx); 156 jri.add_reply_service_context(pContext, true); 157 current.setPropagationContext(null, false); 158 } else { 159 160 } 163 } catch (Exception e) { 164 } 165 } 166 } 167 168 public void send_exception(ServerRequestInfo jri) throws ForwardRequest { 169 if (current == null) { 170 current = Current.getCurrent(); 171 } 172 173 if (current != null) { 174 try { 175 TransactionContext txCtx = current.getPropagationContext(true); 177 ServiceContext pContext = null ; 178 179 if (txCtx != null) { 180 181 pContext = buildCorbaPropagationContext(txCtx); 183 jri.add_reply_service_context(pContext, true); 184 current.setPropagationContext(null, false); 185 } else { 186 187 } 190 } catch (Exception e) { 191 } 192 } 193 } 194 195 public void send_other(ServerRequestInfo jri) throws ForwardRequest { 196 } 197 198 public void destroy() { 199 } 200 201 } 202 | Popular Tags |