1 28 package org.objectweb.carol.rmi.jrmp.interceptor; 29 30 import java.io.IOException ; 32 import java.io.ObjectInput ; 33 import java.io.ObjectOutput ; 34 import java.util.Collection ; 35 import java.util.Iterator ; 36 37 import org.objectweb.carol.util.configuration.TraceCarol; 38 39 46 public class JClientInterceptorHelper extends JInterceptorHelper { 47 48 56 public static void send_request(ObjectOutput out, JClientRequestInterceptor[] cis, boolean localRef) 57 throws IOException { 58 if ((cis == null) || (cis.length == 0)) { 59 if (TraceCarol.isDebugRmiCarol()) { 60 TraceCarol.debugRmiCarol("JClientInterceptorHelper send request without interceptors"); 61 } 62 out.writeInt(NO_CTX); 64 } else { 65 JClientRequestInfo jrc = new JRMPClientRequestInfoImpl(); 66 for (int i = 0; i < cis.length; i++) { 67 cis[i].send_request(jrc); 68 } 69 setClientContextInOutput(out, jrc, localRef); 70 } 71 out.flush(); 73 } 74 75 81 public static void send_poll(ObjectOutput out, JClientRequestInterceptor[] cis, boolean localRef) 82 throws IOException { 83 } 84 85 91 public static void receive_reply(ObjectInput in, JClientRequestInterceptor[] cis) throws IOException { 92 try { 93 int ctxValue = in.readInt(); 94 JClientRequestInfo jrc = new JRMPClientRequestInfoImpl(); 95 if ((cis == null) || (cis.length == 0)) { 96 if (TraceCarol.isDebugRmiCarol()) { 98 TraceCarol.debugRmiCarol("JClientInterceptorHelper receive reply without interceptors"); 99 } 100 getClientRequestContextFromInput(in, ctxValue, jrc); 101 } else { 102 if (TraceCarol.isDebugRmiCarol()) { 104 TraceCarol.debugRmiCarol("JClientInterceptorHelper receive reply contexts"); 105 } 106 JClientRequestInfo ri = getClientRequestContextFromInput(in, ctxValue, jrc); 107 for (int i = 0; i < cis.length; i++) { 108 cis[i].receive_reply(ri); 109 } 110 } 111 } catch (ClassNotFoundException cnfe) { 112 throw new IOException ("" + cnfe); 113 } 114 } 115 116 122 public static void receive_exception(ObjectInput in, JClientRequestInterceptor[] cis) throws IOException { 123 try { 124 int ctxValue = in.readInt(); 125 JClientRequestInfo jrc = new JRMPClientRequestInfoImpl(); 126 if ((cis == null) || (cis.length == 0)) { 127 if (TraceCarol.isDebugRmiCarol()) { 129 TraceCarol.debugRmiCarol("JClientInterceptorHelper receive exception without interceptors"); 130 } 131 getClientRequestContextFromInput(in, ctxValue, jrc); 132 } else { 133 if (TraceCarol.isDebugRmiCarol()) { 135 TraceCarol.debugRmiCarol("JClientInterceptorHelper receive exception contexts"); 136 } 137 JClientRequestInfo ri = getClientRequestContextFromInput(in, ctxValue, jrc); 138 for (int i = 0; i < cis.length; i++) { 139 cis[i].receive_exception(ri); 140 } 141 } 142 } catch (ClassNotFoundException cnfe) { 143 throw new IOException ("" + cnfe); 144 } 145 } 146 147 153 public static void receive_other(ObjectInput in, JClientRequestInterceptor[] cis) throws IOException { 154 try { 155 int ctxValue = in.readInt(); 156 JClientRequestInfo jrc = new JRMPClientRequestInfoImpl(); 157 if ((cis == null) || (cis.length == 0)) { 158 if (TraceCarol.isDebugRmiCarol()) { 160 TraceCarol.debugRmiCarol("JClientInterceptorHelper receive other without interceptors"); 161 } 162 getClientRequestContextFromInput(in, ctxValue, jrc); 163 } else { 164 if (TraceCarol.isDebugRmiCarol()) { 166 TraceCarol.debugRmiCarol("JClientInterceptorHelper receive other contexts"); 167 } 168 JClientRequestInfo ri = getClientRequestContextFromInput(in, ctxValue, jrc); 169 for (int i = 0; i < cis.length; i++) { 170 cis[i].receive_other(ri); 171 } 172 } 173 } catch (ClassNotFoundException cnfe) { 174 throw new IOException ("" + cnfe); 175 } 176 } 177 178 185 public static JClientRequestInfo getClientRequestContextFromInput(ObjectInput in, int ctxValue, 186 JClientRequestInfo jrc) throws ClassNotFoundException , IOException { 187 if (ctxValue == NO_CTX) { 188 if (TraceCarol.isDebugRmiCarol()) { 189 TraceCarol.debugRmiCarol("JClientInterceptorHelper getObjectFromInput no context"); 190 } 191 return jrc; 192 } else if (ctxValue == REMOTE_CTX) { 193 if (TraceCarol.isDebugRmiCarol()) { 194 TraceCarol.debugRmiCarol("JClientInterceptorHelper getObjectFromInput remote"); 195 } 196 int sz = in.readInt(); 197 for (int i = 0; i < sz; i++) { 198 jrc.add_request_service_context((JServiceContext) in.readObject()); 199 } 200 return jrc; 201 } else if (ctxValue == LOCAL_CTX) { 202 int id = in.readInt(); 204 if (TraceCarol.isDebugRmiCarol()) { 206 TraceCarol.debugRmiCarol("JClientInterceptorHelper getObjectFromInput local id(" + id + ")"); 207 } 208 jrc.add_all_request_service_context((Collection ) JContextStore.getObject(id)); 209 return jrc; 210 } else { 211 throw new IOException ("Unknow context type:" + ctxValue); 212 } 213 } 214 215 221 public static void setClientContextInOutput(ObjectOutput out, JClientRequestInfo ri, boolean locRef) 222 throws IOException { 223 if (!ri.hasContexts()) { 224 if (TraceCarol.isDebugRmiCarol()) { 225 TraceCarol.debugRmiCarol("JClientInterceptorHelper send request without contexts"); 226 } 227 out.writeInt(NO_CTX); 229 } else if (locRef) { 230 Object ctx = ri.get_all_request_service_context(); 231 int k = JContextStore.storeObject(ctx); 232 out.writeInt(LOCAL_CTX); 233 out.writeInt(k); 234 if (TraceCarol.isDebugRmiCarol()) { 235 TraceCarol.debugRmiCarol("JClientInterceptorHelper send request with local contexts id(" + k + ")"); 236 for (Iterator i = ((Collection ) ctx).iterator(); i.hasNext();) { 238 TraceCarol.debugRmiCarol("ctx:" + i.next()); 239 } 240 } 241 } else { 242 out.writeInt(REMOTE_CTX); 244 Collection allCtx = ri.get_all_request_service_context(); 245 out.writeInt(allCtx.size()); 246 for (Iterator i = allCtx.iterator(); i.hasNext();) { 247 out.writeObject(i.next()); 248 } 249 if (TraceCarol.isDebugRmiCarol()) { 250 TraceCarol.debugRmiCarol("JClientInterceptorHelper send request with remote contexts"); 251 for (Iterator i = allCtx.iterator(); i.hasNext();) { 253 TraceCarol.debugRmiCarol("ctx:" + i.next()); 254 } 255 } 256 } 257 } 258 } | Popular Tags |