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.lib.callback;
28:
29: import java.util.Enumeration;
30:
31: import org.cougaar.core.mts.MessageAddress;
32: import org.cougaar.planning.ldm.plan.Task;
33: import org.cougaar.util.UnaryPredicate;
34: import org.cougaar.util.log.Logger;
35:
36: /**
37: * For use with the record/playback system.
38: *
39: * Filters for tasks that came from outside (alien!) clusters.
40: * I.e. tasks expanded by the cluster will *not* show up here.
41: */
42:
43: public class UTILAlienTaskCallback extends UTILFilterCallbackAdapter {
44: public UTILAlienTaskCallback(UTILAlienListener listener,
45: Logger logger) {
46: super (listener, logger);
47: }
48:
49: protected UnaryPredicate getPredicate() {
50: return new UnaryPredicate() {
51: public boolean execute(Object o) {
52: if (o instanceof Task) {
53: Task aTask = (Task) o;
54: UTILAlienListener alienListener = (UTILAlienListener) myListener;
55: boolean fromOtherCluster = !(aTask.getSource()
56: .equals(MessageAddress
57: .getMessageAddress(alienListener
58: .getClusterName())));
59: return (fromOtherCluster && alienListener
60: .interestingTask(aTask));
61: }
62: return false;
63: }
64: };
65: }
66:
67: public void reactToChangedFilter() {
68: Enumeration newtasks = mySub.getAddedList();
69: UTILAlienListener alienListener = (UTILAlienListener) myListener;
70: while (newtasks.hasMoreElements()) {
71: Task t = (Task) newtasks.nextElement();
72: alienListener.handleTask(t);
73: }
74:
75: if (logger.isDebugEnabled()) {
76: if (mySub.getChangedList().hasMoreElements())
77: logger
78: .debug("UTILAlienTaskCallback : Alien tasks were changed.");
79: if (mySub.getRemovedList().hasMoreElements()) {
80: Enumeration removedtasks = mySub.getRemovedList();
81: while (removedtasks.hasMoreElements()) {
82: Task t = (Task) removedtasks.nextElement();
83: logger.info("UTILAlienTaskCallback : Alien task "
84: + t.getUID()
85: + " was removed from container.");
86: }
87: }
88: }
89: }
90: }
|