01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.planning.ldm.lps;
28:
29: import java.util.Collection;
30:
31: import org.cougaar.core.blackboard.Directive;
32: import org.cougaar.core.domain.LogicProvider;
33: import org.cougaar.core.domain.MessageLogicProvider;
34: import org.cougaar.core.domain.RootPlan;
35: import org.cougaar.core.util.UID;
36: import org.cougaar.planning.ldm.LogPlan;
37: import org.cougaar.planning.ldm.plan.Task;
38: import org.cougaar.planning.ldm.plan.TaskRescind;
39: import org.cougaar.util.log.Logger;
40: import org.cougaar.util.log.Logging;
41:
42: /**
43: * take an incoming Rescind Directive and
44: * perform Modification to the LOGPLAN
45: *
46: * 1. Rescind Task - removes the task and any plan elements which
47: * address the that task. Any cascade effect is then handled by
48: * RescindLP.
49: **/
50: public class ReceiveRescindLP implements LogicProvider,
51: MessageLogicProvider {
52: private static final Logger logger = Logging
53: .getLogger(ReceiveRescindLP.class);
54:
55: private final RootPlan rootplan;
56: private final LogPlan logplan;
57:
58: public ReceiveRescindLP(RootPlan rootplan, LogPlan logplan) {
59: this .rootplan = rootplan;
60: this .logplan = logplan;
61: }
62:
63: public void init() {
64: }
65:
66: /**
67: * perform updates -- per Rescind ALGORITHM --
68: *
69: **/
70: public void execute(Directive dir, Collection changes) {
71: // drop changes
72: if (dir instanceof TaskRescind) {
73: receiveTaskRescind((TaskRescind) dir);
74: }
75: }
76:
77: private void receiveTaskRescind(TaskRescind tr) {
78: UID tuid = tr.getTaskUID();
79: logger.printDot("R");
80:
81: // just rescind the task; let the RescindLP handle the rest
82: //
83: Task t = logplan.findTask(tuid);
84: if (t != null) {
85: if (logger.isDebugEnabled())
86: logger.debug("Rescinding task " + t);
87: rootplan.remove(t);
88: } else {
89: if (logger.isDebugEnabled()) {
90: logger.debug("Couldn't find task to rescind: " + tuid);
91: }
92: rootplan.add(new RescindLP.DeferredRescind(tr));
93: }
94: }
95: }
|