Package org.opennms.netmgt.alarmd.drools
Class DroolsAlarmContext
- java.lang.Object
-
- org.opennms.netmgt.alarmd.drools.ManagedDroolsContext
-
- org.opennms.netmgt.alarmd.drools.DroolsAlarmContext
-
- All Implemented Interfaces:
AlarmLifecycleListener
public class DroolsAlarmContext extends ManagedDroolsContext implements AlarmLifecycleListener
This class maintains the Drools context used to manage the lifecycle of the alarms. We drive the facts in the Drools context using callbacks provided by theAlarmLifecycleListener
. Atomic actions are used to update facts in working memory.- Author:
- jwhite
-
-
Field Summary
-
Fields inherited from class org.opennms.netmgt.alarmd.drools.ManagedDroolsContext
fireThreadId
-
-
Constructor Summary
Constructors Constructor Description DroolsAlarmContext()
DroolsAlarmContext(java.io.File rulesFolder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.io.File
getDefaultRulesFolder()
void
handleAlarmSnapshot(java.util.List<OnmsAlarm> alarms)
Called periodically with a complete set of alarms as present in the database at the given timestamp.void
handleDeletedAlarm(int alarmId, java.lang.String reductionKey)
Called when an alarm has been deleted.void
handleNewOrUpdatedAlarm(OnmsAlarm alarm)
Called when an alarm has been created or updated.void
onStart()
void
postHandleAlarmSnapshot()
Called afterAlarmLifecycleListener.handleAlarmSnapshot(java.util.List<org.opennms.netmgt.model.OnmsAlarm>)
has been called on all the listeners, and after the session & transaction used to perform the snapshot has been closed.void
preHandleAlarmSnapshot()
Called before the transaction is opened and the alarms are read for subsequent calls toAlarmLifecycleListener.handleAlarmSnapshot(java.util.List<org.opennms.netmgt.model.OnmsAlarm>)
.void
setAcknowledgmentDao(AcknowledgmentDao acknowledgmentDao)
void
setAlarmDao(AlarmDao alarmDao)
void
setAlarmService(AlarmService alarmService)
void
setAlarmTicketerService(AlarmTicketerService alarmTicketerService)
void
setTransactionTemplate(org.springframework.transaction.support.TransactionTemplate template)
protected static boolean
shouldUpdateAlarmForSnapshot(OnmsAlarm alarmInMem, OnmsAlarm alarmInDb)
Used to determine if an alarm that is presently in the working memory should be updated with the given alarm, when handling alarm snapshots.void
waitForInitialSeedToBeSubmitted()
-
Methods inherited from class org.opennms.netmgt.alarmd.drools.ManagedDroolsContext
getClock, getKieSession, getMetrics, isStarted, isUsePseudoClock, reload, setOnNewKiewSessionCallback, setUseManualTick, setUsePseudoClock, start, stop, tick
-
-
-
-
Method Detail
-
getDefaultRulesFolder
public static java.io.File getDefaultRulesFolder()
-
onStart
public void onStart()
- Overrides:
onStart
in classManagedDroolsContext
-
preHandleAlarmSnapshot
public void preHandleAlarmSnapshot()
Description copied from interface:AlarmLifecycleListener
Called before the transaction is opened and the alarms are read for subsequent calls toAlarmLifecycleListener.handleAlarmSnapshot(java.util.List<org.opennms.netmgt.model.OnmsAlarm>)
. This can be used to trigger any necessary state tracking to accurately handle the snapshot results.- Specified by:
preHandleAlarmSnapshot
in interfaceAlarmLifecycleListener
-
handleAlarmSnapshot
public void handleAlarmSnapshot(java.util.List<OnmsAlarm> alarms)
Description copied from interface:AlarmLifecycleListener
Called periodically with a complete set of alarms as present in the database at the given timestamp. This should be used to synchronize any state to ensure it matches what is currently in the database. Note that it is possible that the *current* state of alarms is different from the state at the time at which the snapshot was taken. Implementations should take this in consideration when performing any state synchronization. This method will be called while the related session & transaction that created the alarm are still open. All of the listeners are invoked serially, so the implementors should avoid blocking when possible.- Specified by:
handleAlarmSnapshot
in interfaceAlarmLifecycleListener
- Parameters:
alarms
- canonical set of alarms in the database
-
postHandleAlarmSnapshot
public void postHandleAlarmSnapshot()
Description copied from interface:AlarmLifecycleListener
Called afterAlarmLifecycleListener.handleAlarmSnapshot(java.util.List<org.opennms.netmgt.model.OnmsAlarm>)
has been called on all the listeners, and after the session & transaction used to perform the snapshot has been closed. This can be used to trigger any necessary post-processing of the results once the related session has been closed. This function may be called immediately after a call toAlarmLifecycleListener.preHandleAlarmSnapshot()
if an error occurred while preparing the snapshot i.e. when opening the transaction.- Specified by:
postHandleAlarmSnapshot
in interfaceAlarmLifecycleListener
-
shouldUpdateAlarmForSnapshot
protected static boolean shouldUpdateAlarmForSnapshot(OnmsAlarm alarmInMem, OnmsAlarm alarmInDb)
Used to determine if an alarm that is presently in the working memory should be updated with the given alarm, when handling alarm snapshots.- Parameters:
alarmInMem
- the alarm that is currently in the working memoryalarmInDb
- the alarm that is currently in the database- Returns:
- true if the alarm in the working memory should be updated, false otherwise
-
handleNewOrUpdatedAlarm
public void handleNewOrUpdatedAlarm(OnmsAlarm alarm)
Description copied from interface:AlarmLifecycleListener
Called when an alarm has been created or updated. This method will be called while the related session & transaction that created the alarm are still open. All of the listeners are invoked serially, so the implementors should avoid blocking when possible.- Specified by:
handleNewOrUpdatedAlarm
in interfaceAlarmLifecycleListener
- Parameters:
alarm
- a newly created or updated alarm
-
handleDeletedAlarm
public void handleDeletedAlarm(int alarmId, java.lang.String reductionKey)
Description copied from interface:AlarmLifecycleListener
Called when an alarm has been deleted. This method will be called while the related session & transaction that created the alarm are still open. All of the listeners are invoked serially, so the implementors should avoid blocking when possible.- Specified by:
handleDeletedAlarm
in interfaceAlarmLifecycleListener
- Parameters:
alarmId
- id of the alarm that was deletedreductionKey
- reduction key of the alarm that was deleted
-
setAlarmService
public void setAlarmService(AlarmService alarmService)
-
setAcknowledgmentDao
public void setAcknowledgmentDao(AcknowledgmentDao acknowledgmentDao)
-
setAlarmTicketerService
public void setAlarmTicketerService(AlarmTicketerService alarmTicketerService)
-
waitForInitialSeedToBeSubmitted
public void waitForInitialSeedToBeSubmitted() throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
setTransactionTemplate
public void setTransactionTemplate(org.springframework.transaction.support.TransactionTemplate template)
-
setAlarmDao
public void setAlarmDao(AlarmDao alarmDao)
-
-