1 26 27 package DiningPhilosophers.cif; 28 29 import DiningPhilosophers.*; 30 31 50 51 public class Run 52 { 53 56 public static void 57 main(String [] args) 58 throws Exception 59 { 60 String _OTS = System.getProperties(). 61 getProperty("TRANSACTIONAL_PLUGIN","no").toLowerCase(); 62 63 System.out.println("Initializing the ORB..."); 65 66 72 org.omg.CORBA.ORB orb = 74 org.objectweb.openccm.Components.Runtime.init(args); 75 76 System.out.println("Obtaining the Name Service..."); 78 org.omg.CORBA.Object obj = 79 orb.resolve_initial_references("CommonNameService"); 80 org.omg.CosNaming.NamingContext ns = 81 org.omg.CosNaming.NamingContextHelper.narrow(obj); 82 83 org.omg.CosTransactions.Current current = null; 84 if (_OTS.equals("yes")) 85 { 86 System.out.println("Obtaining the Transaction Service..."); 87 org.omg.CORBA.Object objOTS = orb.resolve_initial_references("TransactionCurrent"); 88 current = org.omg.CosTransactions.CurrentHelper.narrow( objOTS ); 89 } 90 91 try 92 { 93 if ((current!=null)&&(_OTS.equals("yes"))) 94 { 95 System.out.println("Beginning the transaction..."); 96 current.begin(); 97 } 98 99 org.omg.CosNaming.NameComponent [] nc = 101 new org.omg.CosNaming.NameComponent [1]; 102 nc[0] = new org.omg.CosNaming.NameComponent (); 103 nc[0].id = System.getProperty("org.objectweb.ccm.DiningPhilosophers.name");; 104 nc[0].kind = ""; 105 106 ns = org.omg.CosNaming.NamingContextHelper.narrow(ns.resolve(nc)); 107 108 nc[0].id = "PhilosopherHome"; 110 obj = ns.resolve(nc); 111 PhilosopherHome ph = PhilosopherHomeHelper.narrow(obj); 112 113 nc[0].id = "ForkHome"; 114 obj = ns.resolve(nc); 115 ForkHome fh = ForkHomeHelper.narrow(obj); 116 117 nc[0].id = "ObserverHome"; 118 obj = ns.resolve(nc); 119 ObserverHome oh = ObserverHomeHelper.narrow(obj); 120 121 System.out.println("Creating components..."); 123 Philosopher p1 = ph._new("Mathieu"); 124 Philosopher p2 = ph._new("Raphael"); 125 Philosopher p3 = ph._new("Philippe"); 126 Philosopher p4 = ph._new("Sylvain"); 127 ForkManager f1 = fh.create(); 128 ForkManager f2 = fh.create(); 129 ForkManager f3 = fh.create(); 130 ForkManager f4 = fh.create(); 131 Observer o = oh.create(); 132 133 System.out.println("Configuring components..."); 135 136 System.out.println("Interconnecting components..."); 138 139 Fork fork = f1.provide_the_fork(); 140 p1.connect_right(fork); 141 p2.connect_left(fork); 142 143 fork = f2.provide_the_fork(); 144 p2.connect_right(fork); 145 p3.connect_left(fork); 146 147 fork = f3.provide_the_fork(); 148 p3.connect_right(fork); 149 p4.connect_left(fork); 150 151 fork = f4.provide_the_fork(); 152 p4.connect_right(fork); 153 p1.connect_left(fork); 154 155 StatusInfoConsumer consumer = o.get_consumer_info(); 156 p1.subscribe_info(consumer); 157 p2.subscribe_info(consumer); 158 p3.subscribe_info(consumer); 159 p4.subscribe_info(consumer); 160 161 System.out.println("Configuration completion..."); 163 f1.configuration_complete(); 164 f2.configuration_complete(); 165 f3.configuration_complete(); 166 f4.configuration_complete(); 167 o.configuration_complete(); 168 p1.configuration_complete(); 169 p2.configuration_complete(); 170 p3.configuration_complete(); 171 p4.configuration_complete(); 172 173 } catch (Exception e) { 174 if ((current!=null)&&(_OTS.equals("yes"))) 175 { 176 System.out.println("Error during deployment :"); 177 e.printStackTrace(); 178 System.out.print("Rolling Back ... "); 179 current.rollback(); 180 System.out.println("Done"); 181 System.exit(0); 183 } 184 throw e; 185 } 186 187 if ((current!=null)&&(_OTS.equals("yes"))) 188 { 189 System.out.print("Do you want to commit the Deployment ? [Y/n] "); 190 191 java.io.BufferedReader _buffer 192 = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)); 193 char _answer = (char) _buffer.read(); 194 195 if ((_answer=='n')||(_answer=='N')) 196 { 197 System.out.print("Rolling Back ... "); 198 current.rollback(); 199 System.out.println("Done"); 200 } else { 201 System.out.print("Committing ... "); 202 current.commit(false); 203 System.out.println("Done"); 204 } 205 } 206 207 System.exit(0); 208 } 209 } 210 | Popular Tags |