1 package org.jacorb.poa; 2 3 22 23 import org.apache.avalon.framework.logger.Logger; 24 import org.apache.avalon.framework.configuration.*; 25 26 import org.jacorb.poa.except.*; 27 import org.jacorb.poa.util.*; 28 import org.jacorb.poa.gui.*; 29 30 import org.jacorb.orb.dsi.ServerRequest; 31 32 import org.omg.PortableServer.*; 33 import org.omg.PortableServer.POAManagerPackage.State ; 34 35 import java.util.Enumeration ; 36 37 44 45 public class POAMonitorImpl 46 extends POAAdapter 47 implements POAMonitor, POAMonitorController, Configurable 48 { 49 private POA poaModel; 50 private AOM aomModel; 51 private RequestQueue queueModel; 52 private RPPoolManager pmModel; 53 54 private POAMonitorView view; 55 private String prefix; 56 57 private int aomSize; 58 private int queueSize; 59 private int poolCount; 60 private int poolSize; 61 62 private boolean terminate; 63 private boolean aomChanged; 64 private boolean queueChanged; 65 private boolean pmChanged; 66 67 68 private org.jacorb.config.Configuration configuration = null; 69 private Logger logger; 70 private int threadPoolMin = 0; 71 private int threadPoolMax = 0; 72 73 74 public void configure(Configuration myConfiguration) 75 throws ConfigurationException 76 { 77 this.configuration = (org.jacorb.config.Configuration)myConfiguration; 78 logger = configuration.getNamedLogger("jacorb.poa.monitor"); 79 80 threadPoolMin = 81 configuration.getAttributeAsInteger("jacorb.poa.thread_pool_min", 5); 82 83 threadPoolMax = 84 configuration.getAttributeAsInteger("jacorb.poa.thread_pool_max", 20); 85 86 } 87 88 89 public void actionCloseView() { 90 closeMonitor(); 91 } 92 93 public void actionDeactivateObject(String oidStr) { 94 95 if (poaModel != null) { 96 try { 97 poaModel.deactivate_object( oidStr.getBytes() ); 98 } catch (Throwable e) { 99 printMessage("Exception occurred in deactivateObject() of POAMonitor: "+e); 100 } 101 } 102 } 103 104 public void actionRemoveRequestFromQueue(String ridStr) { 105 106 if (queueModel != null && poaModel != null) { 107 try { 108 ServerRequest request = queueModel.getElementAndRemove(Integer.parseInt(ridStr)); 109 if (request == null) throw new ApplicationError("error: rid " + ridStr + " is not contained in queue"); 110 poaModel.getRequestController().rejectRequest(request, new org.omg.CORBA.OBJ_ADAPTER ()); 111 } catch (Throwable e) { 112 printMessage("Exception occurred in removeRequestFromQueue() of POAMonitor: "+e); 113 } 114 } 115 } 116 117 public StringPair[] actionRetrieveAOMContent() { 118 119 if (aomModel != null) { 120 try { 121 return aomModel != null ? aomModel.deliverContent() : null; 122 } catch (Throwable e) { 123 printMessage("Exception occurred in retrieveAOMContent() of POAMonitor: "+e); 124 } 125 } 126 return null; 127 } 128 129 public StringPair[] actionRetrieveQueueContent() 130 { 131 if (queueModel != null) 132 { 133 try 134 { 135 return queueModel.deliverContent(); 136 } 137 catch (Throwable e) 138 { 139 printMessage("Exception during retrieveQueueContent() of POAMonitor: "+e); 140 } 141 } 142 return null; 143 } 144 145 146 public synchronized void changeState(String state) 147 { 148 if (view != null) 149 { 150 try 151 { 152 view._setState(state); 153 } 154 catch (Throwable exception) 155 { 156 if (logger.isWarnEnabled()) 157 { 158 logger.warn("Exception during changeState() of POAMonitor" + 159 exception.getMessage()); 160 } 161 } 162 } 163 } 164 165 166 public synchronized void closeMonitor() 167 { 168 if (view != null) 169 { 170 try 171 { 172 terminate = true; 173 poaModel._removePOAEventListener(this); 174 POAMonitor newMonitor = 175 (POAMonitor)Class.forName("org.jacorb.poa.POAMonitorLightImpl").newInstance(); 176 newMonitor.init(poaModel, aomModel, queueModel, pmModel, prefix ); 177 newMonitor.configure(configuration); 178 poaModel.setMonitor(newMonitor); 179 POAMonitorView tmp = view; 180 view = null; 181 tmp._destroy(); 182 183 } 184 catch (Throwable exception) 185 { 186 if (logger.isWarnEnabled()) 187 { 188 logger.warn("Exception during closeMonitor() of POAMonitorImpl" + 189 exception.getMessage()); 190 } 191 } 192 } 193 } 194 195 196 public void init(POA poa, AOM aom, 197 RequestQueue queue, RPPoolManager pm, 198 String _prefix ) 199 { 200 poaModel = poa; 201 aomModel = aom; 202 queueModel = queue; 203 pmModel = pm; 204 prefix = prefix; 205 } 206 207 208 private void initView() 209 { 210 if (view != null) 211 { 212 try 213 { 214 String name = poaModel._getQualifiedName(); 215 view._setName(name.equals("") ? POAConstants.ROOT_POA_NAME : 216 POAConstants.ROOT_POA_NAME+POAConstants.OBJECT_KEY_SEPARATOR+name); 217 218 view._setState(POAUtil.convert(poaModel.getState())); 219 220 view._setPolicyThread(POAUtil.convert(poaModel.threadPolicy, THREAD_POLICY_ID.value)); 221 view._setPolicyLifespan(POAUtil.convert(poaModel.lifespanPolicy, LIFESPAN_POLICY_ID.value)); 222 view._setPolicyIdUniqueness(POAUtil.convert(poaModel.idUniquenessPolicy, ID_UNIQUENESS_POLICY_ID.value)); 223 view._setPolicyIdAssignment(POAUtil.convert(poaModel.idAssignmentPolicy, ID_ASSIGNMENT_POLICY_ID.value)); 224 view._setPolicyServantRetention(POAUtil.convert( 225 poaModel.servantRetentionPolicy, SERVANT_RETENTION_POLICY_ID.value)); 226 view._setPolicyRequestProcessing(POAUtil.convert( 227 poaModel.requestProcessingPolicy, REQUEST_PROCESSING_POLICY_ID.value)); 228 view._setPolicyImplicitActivation(POAUtil.convert( 229 poaModel.implicitActivationPolicy, IMPLICIT_ACTIVATION_POLICY_ID.value)); 230 231 view._initAOMBar(aomModel != null ? 10 : 0, true); 232 233 view._initQueueBar(10, true); 234 235 view._initActiveRequestsBar(poaModel.isSingleThreadModel() ? 1 : threadPoolMin, 236 poaModel.isSingleThreadModel() ? 1 : threadPoolMax); 237 view._initThreadPoolBar(0); 238 239 } 240 catch (Throwable exception) 241 { 242 if (logger.isWarnEnabled()) 243 { 244 logger.warn("Exception during initView() of POAMonitor" + 245 exception.getMessage()); 246 } 247 } 248 } 249 } 250 251 252 public void objectActivated(byte[] oid, Servant servant, int aom_size) 253 { 254 aomSize = aom_size; 255 aomChanged = true; 256 refreshAOM(); 257 } 258 259 260 public void objectDeactivated(byte[] oid, Servant servant, int aom_size) 261 { 262 aomSize = aom_size; 263 aomChanged = true; 264 refreshAOM(); 265 } 266 267 268 public synchronized void openMonitor() 269 { 270 if (view == null) 271 { 272 try 273 { 274 aomSize = aomModel != null ? aomModel.size() : 0; 275 queueSize = queueModel.size(); 276 poolCount = pmModel.getPoolCount(); 277 poolSize = pmModel.getPoolSize(); 278 279 view = new org.jacorb.poa.gui.poa.POAFrame(this); 280 281 initView(); 282 refreshView(); 283 284 poaModel._addPOAEventListener(this); 285 286 view._setVisible(true); 287 288 } 289 catch (Throwable exception) 290 { 291 if (logger.isWarnEnabled()) 292 { 293 logger.warn("Exception occurred in openMonitor() of POAMonitor" + 294 exception.getMessage() ); 295 } 296 } 297 } 298 } 299 300 301 private synchronized void printException(Throwable e) 302 { 303 if (view != null) 304 { 305 try { 306 view._printMessage("####################################################################"); 307 view._printMessage("\t"+e); 308 view._printMessage("####################################################################"); 309 } 310 catch (Throwable exception) 311 { 312 System.err.println("Exception occurred in _printException() of POAMonitor"); 313 } 314 } 315 } 316 317 318 319 private synchronized void printMessage(String str) 320 { 321 if (view != null) 322 { 323 try 324 { 325 view._printMessage(str); 326 } 327 catch (Throwable exception) 328 { 329 System.err.println("Exception occurred in _printMessage() of POAMonitor"); 330 } 331 } 332 } 333 334 335 public void processorAddedToPool(RequestProcessor processor, 336 int pool_count, 337 int pool_size) 338 { 339 poolCount = pool_count; 340 poolSize = pool_size; 341 pmChanged = true; 342 refreshPM(); 343 } 344 345 346 public void processorRemovedFromPool(RequestProcessor processor, 347 int pool_count, 348 int pool_size) 349 { 350 poolCount = pool_count; 351 poolSize = pool_size; 352 pmChanged = true; 353 refreshPM(); 354 } 355 356 357 private void refreshAOM() 358 { 359 if (view != null) 360 { 361 try 362 { 363 view._setValueAOMBar(aomSize); 364 } 365 catch (Throwable exception) 366 { 367 if (logger.isWarnEnabled()) 368 { 369 logger.warn("Exception during refreshAOM() of POAMonitor" + 370 exception.getMessage()); 371 } 372 } 373 } 374 } 375 376 377 private void refreshPM() 378 { 379 if (view != null) 380 { 381 try 382 { 383 view._setValueActiveRequestsBar(poolSize-poolCount); 384 view._setMaxThreadPoolBar(poolSize); 385 view._setValueThreadPoolBar(poolCount); 386 } 387 catch (Throwable exception) 388 { 389 if (logger.isWarnEnabled()) 390 { 391 logger.warn("Exception occurred in refreshPM() of POAMonitor" + 392 exception.getMessage()); 393 } 394 } 395 } 396 } 397 398 399 private void refreshQueue() 400 { 401 if (view != null) 402 { 403 try 404 { 405 view._setValueQueueBar(queueSize); 406 } 407 catch (Throwable exception) 408 { 409 if (logger.isWarnEnabled()) 410 { 411 logger.warn("Exception occurred in refreshQueue() of POAMonitor: " + 412 exception.getMessage()); 413 } 414 } 415 } 416 } 417 418 419 private void refreshView() 420 { 421 refreshAOM(); 422 refreshQueue(); 423 refreshPM(); 424 } 425 426 427 public void requestAddedToQueue(ServerRequest request, int queue_size) { 428 queueSize = queue_size; 429 queueChanged = true; 430 refreshQueue(); 431 } 432 433 434 public void requestRemovedFromQueue(ServerRequest request, int queue_size) { 435 queueSize = queue_size; 436 queueChanged = true; 437 refreshQueue(); 438 } 439 440 441 } 442 | Popular Tags |