1 28 package org.objectweb.carol.rmi.jrmp.server; 29 30 import java.io.IOException ; 32 import java.io.ObjectInput ; 33 import java.io.ObjectOutput ; 34 import java.rmi.Remote ; 35 import java.rmi.RemoteException ; 36 import java.rmi.server.RemoteCall ; 37 import java.rmi.server.RemoteRef ; 38 39 import org.objectweb.carol.rmi.jrmp.interceptor.JClientRequestInterceptor; 40 import org.objectweb.carol.rmi.jrmp.interceptor.JInterceptorStore; 41 import org.objectweb.carol.rmi.jrmp.interceptor.JServerInterceptorHelper; 42 import org.objectweb.carol.rmi.jrmp.interceptor.JServerRequestInterceptor; 43 44 import sun.rmi.server.UnicastServerRef; 45 import sun.rmi.transport.LiveRef; 46 47 54 public class JUnicastServerRef extends UnicastServerRef { 55 56 59 protected JServerRequestInterceptor[] sis = null; 60 61 64 protected JClientRequestInterceptor[] cis = null; 65 66 private int localId = -2; 67 68 71 public JUnicastServerRef() { 72 } 73 74 80 public JUnicastServerRef(LiveRef ref, JServerRequestInterceptor[] sis, JClientRequestInterceptor[] cis) { 81 super(ref); 82 this.sis = sis; 83 this.cis = cis; 84 } 85 86 92 public JUnicastServerRef(int port, JServerRequestInterceptor[] sis, JClientRequestInterceptor[] cis) { 93 super(new LiveRef(port)); 94 this.sis = sis; 95 this.cis = cis; 96 } 97 98 102 public String getRefClass(ObjectOutput out) { 103 super.getRefClass(out); 104 return "org.objectweb.carol.rmi.jrmp.server.JUnicastServerRef"; 105 } 106 107 112 protected RemoteRef getClientRef() { 113 return new JUnicastRef(ref, cis, JInterceptorStore.getJRMPInitializers(), localId); 114 } 115 116 122 public Remote exportObject(Remote obj, Object object, int localId) throws RemoteException { 123 this.localId = localId; 124 return super.exportObject(obj, object); 125 } 126 127 132 protected void unmarshalCustomCallData(ObjectInput in) throws IOException , ClassNotFoundException { 133 JServerInterceptorHelper.receive_request(in, sis); 134 super.unmarshalCustomCallData(in); 135 } 136 137 142 public void dispatch(Remote obj, RemoteCall call) throws IOException { 143 JUnicastThreadFactory factory = JUnicastRemoteObject.getDefaultThreadFactory(); 144 if (factory == null) { 145 runDispatch(obj, call); 146 } else { 147 DispatchRunnable dr = new DispatchRunnable(obj, call); 148 factory.getThread(dr).run(); if (dr.getIOException() != null) throw dr.getIOException(); 150 } 151 } 152 153 159 private void runDispatch(Remote obj, RemoteCall call) throws IOException { 160 super.dispatch(obj, new JRemoteServerCall(call, sis)); 161 } 162 163 166 private class DispatchRunnable implements Runnable { 167 168 171 Remote obj; 172 173 176 RemoteCall call; 177 178 181 IOException e = null; 182 183 189 public DispatchRunnable(Remote obj, RemoteCall call) { 190 this.obj = obj; 191 this.call = call; 192 } 193 194 197 public void run() { 198 try { 199 runDispatch(obj, call); 200 } catch (IOException e) { 201 this.e = e; 202 } 203 } 204 205 208 public IOException getIOException() { 209 return e; 210 } 211 } 212 } | Popular Tags |