From: <pn...@hy...> - 2009-10-08 06:09:58
|
Author: pnguyen Date: 2009-10-07 23:09:43 -0700 (Wed, 07 Oct 2009) New Revision: 13839 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=13839 Modified: trunk/src/org/hyperic/hq/bizapp/server/session/EventsBossEJBImpl.java Log: [HHQ-3423] To reduce the number of session flushes to 1, the TransactionListener is now added at the end during the updateAlertDefinition() method when all triggers for all alert definitions are created. Modified: trunk/src/org/hyperic/hq/bizapp/server/session/EventsBossEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/server/session/EventsBossEJBImpl.java 2009-10-08 04:46:03 UTC (rev 13838) +++ trunk/src/org/hyperic/hq/bizapp/server/session/EventsBossEJBImpl.java 2009-10-08 06:09:43 UTC (rev 13839) @@ -523,7 +523,7 @@ // Create the triggers if (debug) childWatch.markTimeBegin("createTriggers"); - // HHQ-3423: Do not add the TriggersCreatedListener here. + // HHQ-3423: Do not add the TransactionListener here. // Add it at the end after all the triggers are created. rtm.createTriggers(subject, adval, false); if (debug) childWatch.markTimeEnd("createTriggers"); @@ -797,6 +797,10 @@ InvalidOptionValueException, AlertConditionCreateException, ActionCreateException, FinderException, RemoveException, SessionNotFoundException, SessionTimeoutException { + + final boolean debug = _log.isDebugEnabled(); + StopWatch watch = new StopWatch(); + AuthzSubject subject = manager.getSubject(sessionID); // Verify that there are some conditions to evaluate @@ -806,15 +810,33 @@ } AlertDefinitionManagerLocal adm = getADM(); - ArrayList triggers = new ArrayList(); + RegisteredTriggerManagerLocal rtm = getRTM(); + if (EventConstants.TYPE_ALERT_DEF_ID.equals(adval.getParentId()) || adval.getAppdefType() == AppdefEntityConstants.APPDEF_TYPE_GROUP) { // A little more work to do for group and type alert definition - adval = getADM().updateAlertDefinition(adval); + + if (debug) watch.markTimeBegin("updateParentAlertDefinition"); + + adval = adm.updateAlertDefinition(adval); + + if (debug) { + watch.markTimeEnd("updateParentAlertDefinition"); + watch.markTimeBegin("findAlertDefinitionChildren"); + } - List children = getADM().findAlertDefinitionChildren(adval.getId()); + List children = adm.findAlertDefinitionChildren(adval.getId()); + + if (debug) { + watch.markTimeEnd("findAlertDefinitionChildren"); + watch.markTimeBegin("updateChildAlertDefinitions[" + children.size() + "]"); + } + + List zevents = new ArrayList(children.size()); for (Iterator it = children.iterator(); it.hasNext();) { + StopWatch childWatch = new StopWatch(); + AlertDefinitionValue child = (AlertDefinitionValue) it.next(); AppdefEntityID id = new AppdefEntityID(child.getAppdefType(), @@ -842,27 +864,52 @@ child.setControlFiltered(adval.getControlFiltered()); // Triggers are deleted by the manager - getRTM().deleteAlertDefinitionTriggers(child.getId()); + if (debug) childWatch.markTimeBegin("deleteAlertDefinitionTriggers"); + rtm.deleteAlertDefinitionTriggers(child.getId()); + if (debug) childWatch.markTimeEnd("deleteAlertDefinitionTriggers"); + child.removeAllTriggers(); - createTriggers(subject, child); - triggers.addAll(Arrays.asList(adval.getTriggers())); + if (debug) childWatch.markTimeBegin("createTriggers"); + // HHQ-3423: Do not add the TransactionListener here. + // Add it at the end after all the triggers are created. + rtm.createTriggers(subject, child, false); + if (debug) childWatch.markTimeEnd("createTriggers"); + // Now update the alert definition - adm.updateAlertDefinition(child); + if (debug) childWatch.markTimeBegin("updateAlertDefinition"); + AlertDefinitionValue updatedChild = adm.updateAlertDefinition(child); + if (debug) { + childWatch.markTimeEnd("updateAlertDefinition"); + _log.debug("updateChildAlertDefinition[" + id + "]: time=" + childWatch); + } + zevents.add(new TriggersCreatedZevent(updatedChild.getId())); } + + if (debug) watch.markTimeEnd("updateChildAlertDefinitions[" + children.size() + "]"); + + // HHQ-3423: Add the TransactionListener after all the triggers are created + if (!zevents.isEmpty()) { + if (debug) watch.markTimeBegin("addTriggersCreatedTxListener"); + rtm.addTriggersCreatedTxListener(zevents); + if (debug) watch.markTimeEnd("addTriggersCreatedTxListener"); + } } else { // First, get rid of the current triggers - getRTM().deleteAlertDefinitionTriggers(adval.getId()); + rtm.deleteAlertDefinitionTriggers(adval.getId()); adval.removeAllTriggers(); // Now create the new triggers createTriggers(subject, adval); - triggers.addAll(Arrays.asList(adval.getTriggers())); // Now update the alert definition adm.updateAlertDefinition(adval); } + + if (debug) { + _log.debug("updateAlertDefinition: time=" + watch); + } } /** |