1 5 package ve.luz.ica.jackass.client; 6 7 import org.apache.commons.logging.Log; 8 import org.apache.commons.logging.LogFactory; 9 10 import org.omg.CORBA.COMM_FAILURE ; 11 import org.omg.CORBA.CompletionStatus ; 12 import org.omg.CORBA.LocalObject ; 13 import org.omg.CORBA.ORB ; 14 import org.omg.CORBA.Object ; 15 import org.omg.CORBA.SystemException ; 16 import org.omg.CORBA.SystemExceptionHelper ; 17 import org.omg.PortableInterceptor.ClientRequestInfo ; 18 import org.omg.PortableInterceptor.ClientRequestInterceptor ; 19 import org.omg.PortableInterceptor.ForwardRequest ; 20 import org.omg.PortableInterceptor.SYSTEM_EXCEPTION ; 21 22 import ve.luz.ica.jackass.ref.RefUtil; 23 24 29 public class Interceptor extends LocalObject implements ClientRequestInterceptor 30 { 31 private static final Log LOG = LogFactory.getLog(Interceptor.class); 32 private static final String NAME = "Jackass Client Interceptor"; 33 private static final String COMPONENT_FAULTED = "Component Faulted"; 34 private static final int COMPONENT_FAULTED_MINOR_CODE = 6; 35 36 private ORB orb; 37 private ProxyManager proxyMgr; 38 private RefUtil refUtil; 39 40 44 public String name() 45 { 46 return NAME; 47 } 48 49 55 public void send_request(ClientRequestInfo ri) throws ForwardRequest 56 { 57 init(); 58 Object ref = ri.target(); 59 LOG.debug("Effective target: " + ri.effective_target()); 60 LOG.debug("Target: " + ri.target()); 61 62 if (refUtil.isJackassComponent(ref)) 63 { 64 LOG.debug("IT IS a Jackass component: " + ref); 65 String compID = refUtil.getComponentID(ref); 66 LOG.debug("Component ID: " + compID); 67 Object proxy = proxyMgr.getProxy(compID); 68 LOG.debug("Forwarding request to target (Proxy) " + proxy); 69 throw new ForwardRequest (proxy); 70 } 71 else 72 { 73 LOG.debug("NOT a Jackass component: " + ref); 74 } 75 } 76 77 81 public void send_poll(ClientRequestInfo ri) 82 { 83 } 84 85 89 public void receive_reply(ClientRequestInfo ri) 90 { 91 } 92 93 102 public void receive_exception(ClientRequestInfo ri) throws ForwardRequest 103 { 104 init(); 106 if (LOG.isDebugEnabled()) LOG.debug("Exception Received. Reply status = " + ri.reply_status()); 107 if (ri.reply_status() == SYSTEM_EXCEPTION.value) 108 { 109 SystemException exception = SystemExceptionHelper.extract(ri.received_exception()); 110 if (LOG.isDebugEnabled()) LOG.debug("Received system exception " + exception); 111 Object efTarget = ri.effective_target(); 112 if (LOG.isDebugEnabled()) LOG.debug("Effective Target: " + efTarget); 113 114 if ((exception.completed == CompletionStatus.COMPLETED_NO) && (refUtil.isJackassComponent(efTarget))) 115 { 116 String compID = refUtil.getComponentID(efTarget); 117 if (proxyMgr.isComponentFaulted(compID)) 118 { 119 if (LOG.isWarnEnabled()) LOG.warn("Target faulted, throwing COMM_FAILURE"); 120 throw new COMM_FAILURE ( 121 COMPONENT_FAULTED, 122 COMPONENT_FAULTED_MINOR_CODE, 123 CompletionStatus.COMPLETED_NO); 124 } 125 else 126 { 127 Object proxy = proxyMgr.getProxy(compID); 128 if (LOG.isInfoEnabled()) LOG.info("Trying another proxy: " + proxy); 129 throw new ForwardRequest (proxy); 130 } 131 } 132 } 133 } 134 135 139 public void receive_other(ClientRequestInfo ri) { 141 } 142 143 147 public void destroy() 148 { 149 } 150 151 154 private void init() 155 { 156 initProxyManager(); 157 initRefUtil(); 158 } 159 160 163 private void initOrb() 164 { 165 if (orb == null) 166 { 167 orb = ORB.init((String []) null, null); 168 } 169 } 170 171 174 private void initProxyManager() 175 { 176 initOrb(); 177 if (proxyMgr == null) 178 { 179 proxyMgr = new SingleHostProxyManager(orb); 180 } 181 } 182 183 186 private void initRefUtil() 187 { 188 initOrb(); 189 if (refUtil == null) 190 { 191 refUtil = new RefUtil(orb); 192 } 193 } 194 195 } 196 | Popular Tags |