1 26 27 package org.objectweb.ccm.hello.cif; 28 29 import org.objectweb.ccm.hello.*; 30 31 34 public class Install 35 { 36 39 public static void 40 usage() 41 { 42 System.err.println("usage: Install [<component_server_name> <NS_name>]"); 43 System.err.println(""); 44 System.err.println(" <component_server_name> " + 45 "The component server name on which the " + 46 "ServerHome will be deployed."); 47 System.err.println(" <NS_name> " + 48 "The name used to register the ServerHome " + 49 "instance."); 50 } 51 52 55 public static void 56 main(String [] args) 57 throws Exception 58 { 59 String _OTS = System.getProperties().getProperty("TRANSACTIONAL_PLUGIN","no").toLowerCase(); 60 61 System.out.println("Initializing the ORB..."); 63 64 69 args = org.objectweb.openccm.corba.TheORB.initialize(args); 71 72 org.objectweb.openccm.Components.Runtime.init(); 74 75 org.omg.CORBA.ORB orb = org.objectweb.openccm.corba.TheORB.getORB(); 77 78 if (args.length > 2) { 79 usage(); 80 System.exit(1); 81 } 82 83 String cs_name = (args.length >= 2)?args[0]:"ComponentServer1"; 84 String ns_name = (args.length >= 2)?args[1]:"MyHelloServerHome"; 85 86 System.out.println("Obtaining the Name Service..."); 88 org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService"); 89 org.omg.CosNaming.NamingContext nc = org.omg.CosNaming.NamingContextHelper.narrow(obj); 90 91 org.omg.CosTransactions.Current current = null; 92 if (_OTS.equals("yes")) { 93 System.out.println("Obtaining the Transaction Service..."); 94 org.omg.CORBA.Object objOTS = orb.resolve_initial_references("TransactionCurrent"); 95 current = org.omg.CosTransactions.CurrentHelper.narrow( objOTS ); 96 } 97 98 try { 99 if ((current!=null)&&(_OTS.equals("yes"))) { 100 System.out.println("Beginning the transaction..."); 101 current.begin(); 102 } 103 104 System.out.println("Obtaining Component Servers..."); 106 org.omg.CosNaming.NameComponent [] ncomp = new org.omg.CosNaming.NameComponent [1]; 107 ncomp[0] = new org.omg.CosNaming.NameComponent (cs_name, ""); 108 obj = nc.resolve(ncomp); 109 org.objectweb.openccm.Deployment.Server server = org.objectweb.openccm.Deployment.ServerHelper.narrow(obj); 110 111 org.omg.Components.Deployment.ComponentServer server_cs = server.provide_component_server(); 113 org.omg.Components.Deployment.ComponentInstallation server_inst = server.provide_install(); 114 115 System.out.println("Installing archives..."); 117 String demoPath = null; 119 try { 120 demoPath = new java.io.File (".").getCanonicalPath()+ java.io.File.separator ; 121 }catch(Exception e) { 122 e.printStackTrace(); 123 } 124 125 server_inst.install("hello","file:"+ demoPath + "./archives/hello.jar"); 126 server_inst.install("openccm_plugins","file:"+ demoPath + "./archives/OpenCCM_Plugins.jar"); 128 129 org.omg.Components.Deployment.Container server_cont = 131 server_cs.create_container(new org.omg.Components.ConfigValue[0]); 132 133 System.out.println("Instantiating home..."); 135 org.omg.Components.CCMHome h = 136 server_cont.install_home("hello", 137 "org.objectweb.ccm.hello.cif.ServerHomeImpl.create_home", 138 new org.omg.Components.ConfigValue[0]); 139 ServerHome sh = ServerHomeHelper.narrow(h); 140 141 ncomp[0] = new org.omg.CosNaming.NameComponent (ns_name, ""); 143 nc.rebind(ncomp, sh); 144 System.out.println("ServerHome instance register under \'" + 145 ns_name + " \' in the name service"); 146 147 } catch (Exception e) { 148 if ((current!=null)&&(_OTS.equals("yes"))) { 149 System.out.println("Error during deployment :"); 150 e.printStackTrace(); 151 System.out.print("Rolling Back ... "); 152 current.rollback(); 153 System.out.println("Done"); 154 System.exit(0); 156 } 157 } 158 159 if ((current!=null)&&(_OTS.equals("yes"))) { 160 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 161 162 java.io.BufferedReader _buffer 163 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 164 char _answer = (char) _buffer.read(); 165 166 if ((_answer=='n')||(_answer=='N')) 167 { 168 System.out.print("Rolling Back ... "); 169 current.rollback(); 170 System.out.println("Done"); 171 } else { 172 System.out.print("Committing ... "); 173 current.commit(false); 174 System.out.println("Done"); 175 System.out.println(ns_name + " is ready to be used..."); 176 } 177 } else { 178 System.out.println(ns_name + " is ready to be used..."); 179 } 180 181 System.exit(0); 182 } 183 } 184 185 186 187 188 189 190 | Popular Tags |