1 5 package ve.luz.ica.jackass.instantiator; 6 7 import java.io.IOException ; 8 import java.io.InputStream ; 9 import java.util.Properties ; 10 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 14 import org.omg.CORBA.UserException ; 15 import org.omg.PortableServer.POAHelper ; 16 import org.omg.CORBA.Object ; 17 18 import ve.luz.ica.jackass.deploy.daemon.NodeDeployer; 19 import ve.luz.ica.jackass.deploy.daemon.NodeDeployerHelper; 20 import ve.luz.ica.jackass.util.ConfigurationManager; 21 22 28 public class InstantiatorServer 29 { 30 private static final Log LOG = LogFactory.getLog(InstantiatorServer.class); 31 32 private static final String NODE_DEPLOYER_REF_FILE = "node_deployer.ior"; 33 private static final String ROOT_POA = "RootPOA"; 34 37 private static final String INSTANTIATOR_ORB_PROPERTIES = "instantiator-orb.properties"; 38 private static final String ERROR_READING_INSTANTIATOR_ORB_PROPERTIES = "Error reading instantiator-orb.properties"; 39 40 private org.omg.CORBA.ORB orb = null; 41 private org.omg.PortableServer.POA poa = null; 42 43 48 public static void main(String [] args) 49 { 50 try 51 { 52 InstantiatorServer instantiatorServer = new InstantiatorServer(); 53 instantiatorServer.init(args); 54 instantiatorServer.run(); 55 } 56 catch (Exception e) 57 { 58 LOG.fatal("Error at system startup", e); 59 } 60 } 61 62 67 public void init(String [] args) throws Exception 68 { 69 Properties cf = ConfigurationManager.getConfigFile(); 70 71 Properties props = new Properties (); 72 try 73 { 74 InputStream in = ClassLoader.getSystemResourceAsStream(INSTANTIATOR_ORB_PROPERTIES); 75 props.load(in); 76 } 77 catch (Exception e) 78 { 79 if (LOG.isErrorEnabled()) LOG.error(ERROR_READING_INSTANTIATOR_ORB_PROPERTIES, e); 80 throw new IOException (ERROR_READING_INSTANTIATOR_ORB_PROPERTIES + e.getMessage()); 81 } 82 83 if (LOG.isDebugEnabled()) 84 { 85 LOG.debug(props.getProperty("OAPort")); 86 LOG.debug(props.getProperty("jacorb.implname")); 87 } 88 89 orb = org.omg.CORBA.ORB.init(args, props); 90 Object obj = orb.resolve_initial_references(ROOT_POA); 91 if (LOG.isDebugEnabled()) LOG.debug(obj); 92 93 poa = POAHelper.narrow(obj); 94 poa.the_POAManager().activate(); 95 this.createInstantiator(); 96 } 97 98 101 public void run() 102 { 103 LOG.info("Instantiator ready"); 104 orb.run(); 105 } 106 107 112 public void createInstantiator() throws UserException 113 { 114 try 115 { 116 JInstantiatorImpl instantiatorImpl = new JInstantiatorImpl(orb, poa); 118 org.omg.CORBA.Object obj = poa.servant_to_reference(instantiatorImpl); 119 JInstantiator instantiator = JInstantiatorHelper.narrow(obj); 120 121 java.io.FileInputStream file = new java.io.FileInputStream (NODE_DEPLOYER_REF_FILE); 124 java.io.BufferedReader myInput = new java.io.BufferedReader (new java.io.InputStreamReader (file)); 125 String stringTarget = myInput.readLine(); 126 org.omg.CORBA.Object dobj = orb.string_to_object(stringTarget); 127 NodeDeployer nodeDeployer = NodeDeployerHelper.narrow(dobj); 128 129 if (LOG.isDebugEnabled()) 130 { 131 LOG.debug("Node deployer reference resolved"); 132 } 133 134 nodeDeployer.addInstantiator(instantiator); 136 137 if (LOG.isDebugEnabled()) 138 { 139 LOG.debug("Instantiator registered"); 140 } 141 } 142 catch (java.io.IOException ex) 143 { 144 LOG.error("Unable to resolve the daemon reference"); 145 } 146 147 } 148 } 149 | Popular Tags |