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(File rulesFolder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FilegetDefaultRulesFolder()voidhandleAlarmSnapshot(List<OnmsAlarm> alarms)Called periodically with a complete set of alarms as present in the database at the given timestamp.voidhandleDeletedAlarm(int alarmId, String reductionKey)Called when an alarm has been deleted.voidhandleNewOrUpdatedAlarm(OnmsAlarm alarm)Called when an alarm has been created or updated.voidonStart()voidpostHandleAlarmSnapshot()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.voidpreHandleAlarmSnapshot()Called before the transaction is opened and the alarms are read for subsequent calls toAlarmLifecycleListener.handleAlarmSnapshot(java.util.List<org.opennms.netmgt.model.OnmsAlarm>).voidsetAcknowledgmentDao(AcknowledgmentDao acknowledgmentDao)voidsetAlarmDao(AlarmDao alarmDao)voidsetAlarmService(AlarmService alarmService)voidsetAlarmTicketerService(AlarmTicketerService alarmTicketerService)voidsetTransactionTemplate(org.springframework.transaction.support.TransactionTemplate template)protected static booleanshouldUpdateAlarmForSnapshot(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.voidwaitForInitialSeedToBeSubmitted()-
Methods inherited from class org.opennms.netmgt.alarmd.drools.ManagedDroolsContext
getClock, getKieSession, getMetrics, isStarted, isUsePseudoClock, reload, setOnNewKiewSessionCallback, setUseManualTick, setUsePseudoClock, start, stop, tick
-
-
-
-
Constructor Detail
-
DroolsAlarmContext
public DroolsAlarmContext()
-
DroolsAlarmContext
public DroolsAlarmContext(File rulesFolder)
-
-
Method Detail
-
getDefaultRulesFolder
public static File getDefaultRulesFolder()
-
onStart
public void onStart()
- Overrides:
onStartin classManagedDroolsContext
-
preHandleAlarmSnapshot
public void preHandleAlarmSnapshot()
Description copied from interface:AlarmLifecycleListenerCalled 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:
preHandleAlarmSnapshotin interfaceAlarmLifecycleListener
-
handleAlarmSnapshot
public void handleAlarmSnapshot(List<OnmsAlarm> alarms)
Description copied from interface:AlarmLifecycleListenerCalled 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:
handleAlarmSnapshotin interfaceAlarmLifecycleListener- Parameters:
alarms- canonical set of alarms in the database
-
postHandleAlarmSnapshot
public void postHandleAlarmSnapshot()
Description copied from interface:AlarmLifecycleListenerCalled 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:
postHandleAlarmSnapshotin 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:AlarmLifecycleListenerCalled 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:
handleNewOrUpdatedAlarmin interfaceAlarmLifecycleListener- Parameters:
alarm- a newly created or updated alarm
-
handleDeletedAlarm
public void handleDeletedAlarm(int alarmId, String reductionKey)Description copied from interface:AlarmLifecycleListenerCalled 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:
handleDeletedAlarmin 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 InterruptedException- Throws:
InterruptedException
-
setTransactionTemplate
public void setTransactionTemplate(org.springframework.transaction.support.TransactionTemplate template)
-
setAlarmDao
public void setAlarmDao(AlarmDao alarmDao)
-
-