001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.planning.ldm.lps;
028:
029: import java.util.Collection;
030:
031: import org.cougaar.core.blackboard.EnvelopeTuple;
032: import org.cougaar.core.domain.EnvelopeLogicProvider;
033: import org.cougaar.core.domain.LogicProvider;
034: import org.cougaar.core.domain.RootPlan;
035: import org.cougaar.core.mts.MessageAddress;
036: import org.cougaar.core.util.UID;
037: import org.cougaar.planning.ldm.PlanningFactory;
038: import org.cougaar.planning.ldm.plan.NewDeletion;
039: import org.cougaar.planning.ldm.plan.Task;
040: import org.cougaar.util.log.Logger;
041: import org.cougaar.util.log.Logging;
042:
043: /** RescindLogicProvider class provides the logic to capture
044: * rescinded PlanElements (removed from collection)
045: *
046: *
047: **/
048:
049: public class DeletionLP implements LogicProvider, EnvelopeLogicProvider {
050: private static final Logger logger = Logging
051: .getLogger(DeletionLP.class);
052:
053: private final RootPlan rootplan;
054: private final PlanningFactory ldmf;
055: private final MessageAddress self;
056:
057: public DeletionLP(RootPlan rootplan, PlanningFactory ldmf,
058: MessageAddress self) {
059: this .rootplan = rootplan;
060: this .ldmf = ldmf;
061: this .self = self;
062: }
063:
064: public void init() {
065: }
066:
067: /**
068: * @param o an Envelope.Tuple.object is an ADDED
069: * PlanElement which contains an Allocation to an Organization.
070: * Do something if the test returned true i.e. it was an Allocation
071: **/
072: public void execute(EnvelopeTuple o, Collection changes) {
073: if (o.isRemove()) {
074: Object obj = o.getObject();
075: if (obj instanceof Task) {
076: Task task = (Task) obj;
077: if (task.isDeleted()) {
078: UID ptuid = task.getParentTaskUID();
079: if (ptuid != null) {
080: MessageAddress dst = task.getSource();
081: if (!dst.getPrimary().equals(self)) {
082: // Parent task is in another agent so we do our thing
083: NewDeletion nd = ldmf.newDeletion();
084: nd.setTaskUID(ptuid);
085: nd.setPlan(task.getPlan());
086: nd.setSource(self);
087: nd.setDestination(dst);
088: if (logger.isDebugEnabled()) {
089: logger.debug(self
090: + ": send Deletion to " + dst
091: + " for task " + ptuid);
092: }
093: rootplan.sendDirective(nd);
094: }
095: }
096: }
097: }
098: }
099: }
100: }
|