1 28 package org.objectweb.carol.rmi.jrmp.server; 29 30 import java.rmi.NoSuchObjectException ; 31 import java.rmi.Remote ; 32 import java.rmi.RemoteException ; 33 import java.rmi.server.RMIClientSocketFactory ; 34 import java.rmi.server.RMIServerSocketFactory ; 35 import java.rmi.server.RemoteServer ; 36 import java.rmi.server.RemoteStub ; 37 import java.rmi.server.ServerCloneException ; 38 39 import org.objectweb.carol.rmi.jrmp.interceptor.JClientRequestInterceptor; 40 import org.objectweb.carol.rmi.jrmp.interceptor.JServerRequestInterceptor; 41 import org.objectweb.carol.util.configuration.CarolDefaultValues; 42 43 import sun.rmi.transport.ObjectTable; 44 45 52 public class JUnicastRemoteObject extends RemoteServer { 53 54 protected RMIClientSocketFactory csf = null; 55 56 protected RMIServerSocketFactory ssf = null; 57 58 private static JUnicastThreadFactory defaultThreadFactory = null; 59 60 private static boolean localO; 62 63 static { 64 localO = new Boolean (System.getProperty(CarolDefaultValues.LOCAL_JRMP_PROPERTY, "false")).booleanValue(); 65 } 66 67 protected JUnicastRemoteObject(JServerRequestInterceptor[] sis, JClientRequestInterceptor[] cis) 68 throws RemoteException { 69 this(0, sis, cis); 71 } 72 73 protected JUnicastRemoteObject(int p, JServerRequestInterceptor[] sis, JClientRequestInterceptor[] cis) 74 throws RemoteException { 75 JUnicastRemoteObject.exportObject(this, p, sis, cis); 76 } 77 78 protected JUnicastRemoteObject(int p, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, 79 JServerRequestInterceptor[] sis, JClientRequestInterceptor[] cis) throws RemoteException { 80 this.csf = csf; 81 this.ssf = ssf; 82 JUnicastRemoteObject.exportObject(this, p, csf, ssf, sis, cis); 83 } 84 85 protected void exportObject(JServerRequestInterceptor[] sis, JClientRequestInterceptor[] cis) 87 throws RemoteException { 88 if (csf == null && ssf == null) { 89 JUnicastRemoteObject.exportObject(this, 0, sis, cis); 90 } else { 91 JUnicastRemoteObject.exportObject(this, 0, csf, ssf, sis, cis); 92 } 93 } 94 95 public static RemoteStub exportObject(Remote obj, JServerRequestInterceptor[] sis, JClientRequestInterceptor[] cis) 96 throws RemoteException { 97 return (RemoteStub ) JUnicastRemoteObject.exportObject(obj, 0, sis, cis); 98 } 99 100 public static Remote exportObject(Remote obj, int p, JServerRequestInterceptor[] sis, 101 JClientRequestInterceptor[] cis) throws RemoteException { 102 103 return JUnicastRemoteObject.exportObjectR(obj, new JUnicastServerRef(p, sis, cis)); 104 } 105 106 public static Remote exportObject(Remote obj, int p, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, 107 JServerRequestInterceptor[] sis, JClientRequestInterceptor[] cis) throws RemoteException { 108 109 return JUnicastRemoteObject.exportObjectR(obj, new JUnicastServerRefSf(p, csf, ssf, sis, cis)); 110 } 111 112 120 protected static Remote exportObjectR(Remote obj, JUnicastServerRef serverRef) throws RemoteException { 121 int localId = -2; 122 if (localO) { 123 localId = JLocalObjectStore.storeObject(obj); 124 } 125 if (obj instanceof JUnicastRemoteObject) ((JUnicastRemoteObject) obj).ref = serverRef; 126 Remote rob = serverRef.exportObject(obj, null, localId); 127 return rob; 128 } 129 130 136 public static boolean unexportObject(Remote obj, boolean force) throws NoSuchObjectException { 137 if (localO) { 138 JUnicastRef remoteref = (JUnicastRef) ((RemoteStub ) ObjectTable.getStub(obj)).getRef(); 139 JLocalObjectStore.removeObject(remoteref.getLocalId()); 140 } 141 return ObjectTable.unexportObject(obj, force); 142 } 143 144 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException , ClassNotFoundException { 145 in.defaultReadObject(); 146 exportObject(null, null); 147 } 148 149 public Object clone() throws CloneNotSupportedException { 150 try { 151 JUnicastRemoteObject cloned = (JUnicastRemoteObject) super.clone(); 152 cloned.exportObject(null, null); 153 return cloned; 154 } catch (RemoteException e) { 155 throw new ServerCloneException ("Clone failed", e); 156 } 157 } 158 159 163 public static void setDefaultThreadFactory(JUnicastThreadFactory factory) { 164 defaultThreadFactory = factory; 165 } 166 167 170 public static JUnicastThreadFactory getDefaultThreadFactory() { 171 return defaultThreadFactory; 172 } 173 } 174 175 | Popular Tags |