1 package org.jacorb.poa; 2 3 22 23 import org.jacorb.poa.gui.*; 24 25 import org.apache.avalon.framework.logger.Logger; 26 import org.apache.avalon.framework.configuration.*; 27 28 29 36 37 public class POAManagerMonitorImpl 38 implements POAManagerMonitor, POAManagerMonitorController, Configurable 39 { 40 private POAManager model = null; 41 private POAManagerMonitorView view = null; 42 43 44 private org.jacorb.config.Configuration configuration = null; 45 private Logger logger; 46 47 public void configure(Configuration myConfiguration) 48 throws ConfigurationException 49 { 50 this.configuration = (org.jacorb.config.Configuration)myConfiguration; 51 logger = configuration.getNamedLogger("jacorb.poa.manager_monitor"); 52 } 53 54 55 public void actionClosePOAMonitor(String name) 56 { 57 if (model != null) 58 { 59 try 60 { 61 printMessage("invoke \"closeMonitor()\" on POAMonitor "+name); 62 model.getRegisteredPOA(reducePOAName(name)).getMonitor().closeMonitor(); 63 printMessage("closeMonitor() on POAMonitor "+name+" is returned successfully"); 64 } 65 catch (Throwable e) 66 { 67 printMessage("exception ocurred: "+e); 68 } 69 } 70 } 71 72 public void actionCloseView() 73 { 74 closeMonitor(); 75 } 76 77 public void actionDestroyPOA(String name) 78 { 79 if (model != null) 80 { 81 try 82 { 83 printMessage("invoke \"destroy()\" on POA "+name); 84 model.getRegisteredPOA(reducePOAName(name)).destroy(true, true); 85 printMessage("destroy() on POA "+name+" is returned successfully"); 86 } 87 catch (Throwable e) 88 { 89 printMessage("exception ocurred: "+e); 90 } 91 } 92 } 93 public void actionOpenPOAMonitor(String name) { 94 if (model != null) { 95 try { 96 printMessage("invoke \"openMonitor()\" on POAMonitor "+name); 97 model.getRegisteredPOA(reducePOAName(name)).getMonitor().openMonitor(); 98 printMessage("openMonitor() on POAMonitor "+name+" is returned successfully"); 99 } catch (Throwable e) { 100 printMessage("exception ocurred: "+e); 101 } 102 } 103 } 104 public void actionSetToActive() { 105 if (model != null) { 106 try { 107 printMessage("invoke \"activate()\" on POAManager"); 108 model.activate(); 109 printMessage("activate() on POAManager is returned successfully"); 110 } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive e) { 111 printMessage("exception ocurred: "+e); 112 resetState(); 113 } 114 } 115 } 116 public void actionSetToDiscarding(boolean wait) { 117 if (model != null) { 118 try { 119 printMessage("invoke \"discard_requests("+wait+")\" on POAManager"); 120 model.discard_requests(wait); 121 printMessage("discard_requests("+wait+") on POAManager is returned successfully"); 122 } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive e) { 123 printMessage("exception ocurred: "+e); 124 resetState(); 125 } 126 } 127 } 128 public void actionSetToHolding(boolean wait) { 129 if (model != null) { 130 try { 131 printMessage("invoke \"hold_requests("+wait+")\" on POAManager"); 132 model.hold_requests(wait); 133 printMessage("hold_requests("+wait+") on POAManager is returned successfully"); 134 } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive e) { 135 printMessage("exception ocurred: "+e); 136 resetState(); 137 } 138 } 139 } 140 public void actionSetToInactive(boolean wait, boolean etherialize) 141 { 142 if (model != null) 143 { 144 try { 145 printMessage("invoke \"deactivate("+etherialize+", "+wait+")\" on POAManager"); 146 model.deactivate(etherialize, wait); 147 printMessage("deactivate("+etherialize+", "+wait+") on POAManager is returned successfully"); 148 } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive e) { 149 printMessage("exception ocurred: "+e); 150 resetState(); 151 } 152 } 153 } 154 155 public synchronized void addPOA(String name) 156 { 157 if (view != null) 158 { 159 try 160 { 161 view._addPOA(expandPOAName(name)); 162 } 163 catch (Throwable exception) 164 { 165 if (logger.isErrorEnabled()) 166 { 167 logger.error( "Exception in addPOA()" + exception.getMessage()); 168 } 169 } 170 printMessage("register POA "+name); 171 } 172 } 173 174 public synchronized void closeMonitor() 175 { 176 if (view != null) 177 { 178 try 179 { 180 POAManagerMonitor newMonitor = 181 (POAManagerMonitor)Class.forName("org.jacorb.poa.POAManagerMonitorImpl").newInstance(); 182 newMonitor.init(model); 183 newMonitor.configure(configuration); 184 model.setMonitor(newMonitor); 185 POAManagerMonitorView tmp = view; 186 view = null; 187 tmp._destroy(); 188 } 189 catch (Throwable exception) 190 { 191 if (logger.isErrorEnabled()) 192 { 193 logger.error( "Exception in closeMonitor" + exception.getMessage()); 194 } 195 } 196 } 197 } 198 private String expandPOAName(String name) 199 { 200 return name.equals("") ? 201 POAConstants.ROOT_POA_NAME : 202 POAConstants.ROOT_POA_NAME+POAConstants.OBJECT_KEY_SEPARATOR+name; 203 } 204 205 public void init(POAManager poaManager) 206 { 207 model = poaManager; 208 } 209 210 public synchronized void openMonitor() 211 { 212 try 213 { 214 view = new org.jacorb.poa.gui.pm.POAManagerFrame(this); 215 view._setVisible(true); 216 } 217 catch (Throwable exception) 218 { 219 if (logger.isErrorEnabled()) 220 { 221 logger.error( "Exception in openMonitor" + exception.getMessage()); 222 } 223 } 224 } 225 226 public synchronized void printMessage(String str) 227 { 228 if (view != null) { 229 try 230 { 231 view._printMessage(str); 232 } 233 catch (Throwable exception) 234 { 235 if (logger.isErrorEnabled()) 236 { 237 logger.error( "Exception int printMessage(): " + exception.getMessage()); 238 } 239 } 240 } 241 } 242 243 private String reducePOAName(String name) 244 { 245 return name.equals(POAConstants.ROOT_POA_NAME) ? 246 "" : 247 name.substring(POAConstants.ROOT_POA_NAME.length()+1); 248 } 249 250 public synchronized void removePOA(String name) 251 { 252 if (view != null) 253 { 254 try 255 { 256 view._removePOA(expandPOAName(name)); 257 } 258 catch (Throwable exception) 259 { 260 if (logger.isErrorEnabled()) 261 { 262 logger.error( "Exception in printMessage(): " + exception.getMessage()); 263 } 264 } 265 printMessage("unregister POA "+name); 266 } 267 } 268 269 protected synchronized void resetState() { 270 if (view != null) 271 { 272 try 273 { 274 view._resetState(); 275 } 276 catch (Throwable exception) 277 { 278 if (logger.isErrorEnabled()) 279 { 280 logger.error( "Exception in resetState(): " + exception.getMessage()); 281 } 282 } 283 } 284 } 285 public synchronized void setToActive() 286 { 287 if (view != null) 288 { 289 try 290 { 291 view._setToActive(); 292 } 293 catch (Throwable exception) 294 { 295 if (logger.isErrorEnabled()) 296 { 297 logger.error( "Exception in setToActive(): " + exception.getMessage()); 298 } 299 } 300 printMessage("POAManager is set to \"active\""); 301 } 302 } 303 304 public synchronized void setToDiscarding(boolean wait) 305 { 306 if (view != null) 307 { 308 try 309 { 310 view._setToDiscarding(wait); 311 } 312 catch (Throwable exception) 313 { 314 if (logger.isErrorEnabled()) 315 { 316 logger.error( "Exception in setToActive(): " + exception.getMessage()); 317 } 318 } 319 printMessage("POAManager is set to \"discarding\""); 320 } 321 } 322 323 public synchronized void setToHolding(boolean wait) 324 { 325 if (view != null) 326 { 327 try 328 { 329 view._setToHolding(wait); 330 } 331 catch (Throwable exception) 332 { 333 if (logger.isErrorEnabled()) 334 { 335 logger.error( "Exception in setToHolding(): " + exception.getMessage()); 336 } 337 } 338 printMessage("POAManager is set to \"holding\""); 339 } 340 } 341 public synchronized void setToInactive(boolean wait, boolean etherialize) 342 { 343 if (view != null) 344 { 345 try 346 { 347 view._setToInactive(wait, etherialize); 348 } 349 catch (Throwable exception) 350 { 351 if (logger.isErrorEnabled()) 352 { 353 logger.error( "Exception in setToInactive(): " + exception.getMessage()); 354 } 355 } 356 printMessage("POAManager is set to \"inactive\""); 357 } 358 } 359 } 360 | Popular Tags |