1 17 18 package org.objectweb.jac.core.dist.rmi; 19 20 import java.io.File ; 21 import java.io.IOException ; 22 import java.lang.Runtime ; 23 import java.rmi.Naming ; 24 import java.rmi.RMISecurityManager ; 25 import java.rmi.RemoteException ; 26 import org.apache.log4j.Logger; 27 import org.objectweb.jac.core.dist.Distd; 28 import org.objectweb.jac.core.dist.RemoteContainer; 29 30 38 39 public class RMIDistd extends Distd { 40 static final Logger logger = Logger.getLogger("dist.rmi"); 41 42 45 public void init() { 46 47 48 49 if (System.getSecurityManager() == null) 50 System.setSecurityManager(new RMISecurityManager ()); 51 52 try { 53 File path; 54 File jar = new File (org.objectweb.jac.core.Jac.getJacRoot()+"jac.jar"); 55 logger.debug("$JAC_ROOT/jac.jar = "+jar.getPath()); 56 if (jar.exists()) { 57 path = jar; 58 } else { 59 path = new File (org.objectweb.jac.core.Jac.getJacRoot()+"classes"); 60 } 61 logger.debug("Launching rmiregistry with CLASSPATH="+path.getPath()); 62 rmiProcess = Runtime.getRuntime().exec( 63 new String [] { "rmiregistry", 64 "-J-classpath", 65 "-J"+path.getPath()}); 66 } catch (IOException e) { 67 logger.error("Could not start rmiregistry",e); 68 } 69 } 70 71 static Process rmiProcess = null; 72 73 static { 74 Runtime.getRuntime().addShutdownHook( 75 new Thread () { 76 public void run() { 77 if (rmiProcess!=null) { 78 logger.info("Stopping rmiregistry..."); 79 rmiProcess.destroy(); 80 } 81 } 82 } 83 ); 84 } 85 86 92 protected RemoteContainer newContainer(String name) throws Exception { 93 94 RMIRemoteContainer remCont = null; 95 96 try { 97 remCont = new RMIRemoteContainer(verbose); 98 } catch(Exception e) { 99 logger.error("newContainer("+name+ 100 "): Instantiation of RMIRemoteContainer failed",e); 101 return null; 102 } 103 104 registerContainer(remCont, name); 106 113 remCont.getDelegate().setName(getFullHostName(name)); 114 115 return remCont.getDelegate(); 116 } 117 118 119 127 protected RemoteContainer newContainer(String name, String className) 128 throws Exception 129 { 130 RMIRemoteContainer remCont = null; 131 132 try { 133 remCont = new RMIRemoteContainer(className,verbose); 134 } catch( Exception e ) { 135 e.printStackTrace(); 136 return null; 137 } 138 139 registerContainer(remCont, name); 140 141 remCont.getDelegate().setName(getFullHostName(name)); 142 143 return remCont.getDelegate(); 144 } 145 146 147 153 protected void registerContainer( 154 RMIRemoteContainer container, 155 String name) 156 throws java.rmi.RemoteException 157 { 158 159 String fullName = getFullHostName(name); 160 161 try { 162 Naming.rebind(fullName, container); 163 } catch( java.net.MalformedURLException e ) { 164 logger.error("registerContainer("+container+","+name+")",e); 165 } 166 167 logger.info( 168 "--- JAC Distd (RMI): new container " + fullName + " ---" 169 ); 170 logger.info( 171 "--- Default class repository: " + referenceContainerName + " ---" 172 ); 173 174 } 175 176 180 public void run() { 181 logger.info( "--- JAC Distd (RMI) is running ---" ); 182 } 183 184 189 public RMIDistd(String [] args) { 190 super(args); 191 } 192 193 public static void main(String [] args) { 194 new RMIDistd(args); 195 } 196 197 } 198 | Popular Tags |