2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.eventmanager;
23 import org.drools.core.WorkingMemory;
24 import org.kie.api.runtime.rule.FactHandle;
25 import org.onap.policy.controlloop.ControlLoopException;
26 import org.onap.policy.controlloop.VirtualControlLoopEvent;
27 import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
30 * Manager for a single control loop event. Once this has been created, the event can be
31 * retracted from working memory. Once this has been created, {@link #start()} should be
32 * invoked, and then {@link #nextStep()} should be invoked continually until
33 * {@link #isActive()} returns {@code false}, indicating that all steps have completed.
35 public class ControlLoopEventManager2Drools extends ControlLoopEventManager2 {
36 private static final long serialVersionUID = 1L;
38 private final transient WorkingMemory workMem;
39 private transient FactHandle factHandle;
42 * Constructs the object.
44 * @param params control loop parameters
45 * @param event event to be managed by this object
46 * @param workMem working memory to update if this changes
47 * @throws ControlLoopException if the event is invalid or if a YAML processor cannot
50 public ControlLoopEventManager2Drools(ControlLoopParams params, VirtualControlLoopEvent event,
51 WorkingMemory workMem) throws ControlLoopException {
54 this.workMem = workMem;
58 * This is a hook added to 'ControlLoopEventManager2.start()' --
59 * here, we add an additional check.
62 protected void startHook() {
63 if ((factHandle = workMem.getFactHandle(this)) == null) {
64 throw new IllegalStateException("manager is not in working memory");
69 * This is a hook added to 'ControlLoopEventManager2.updated(...)' --
70 * here, we mark it as updated in Drools memory.
73 protected void notifyUpdate() {
74 workMem.update(factHandle, this);