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.core.relay;
28:
29: import java.util.ArrayList;
30: import java.util.Collection;
31: import java.util.Set;
32:
33: import org.cougaar.core.blackboard.ChangeReport;
34:
35: /**
36: * A {@link ChangeReport} to change the targets of a relay.
37: * <p>
38: * This ChangeReport must be used used when publishing changes to the
39: * <b>target</b> set of a Relay (as opposed to the relay's content).
40: * Failure to do so will cause dangling relay targets in agents that
41: * are no longer in the target set.
42: * <p>
43: * Usage is:<pre>
44: * Collection changes = Collections.singleton(new RelayChangeReport(relay));
45: * relay.setTargets(newTargets);
46: * blackboard.publishChange(relay, changes);
47: * <pre>
48: * The details of how you change the targets of your relay
49: * implementation are, of course, your responsibility, but whatever
50: * method you use, it is critical that the RelayChangeReport be
51: * created before you change the targets since the change report
52: * carries a copy of the old set to the RelayLP which uses it to
53: * insure that the old targets are correctly reconciled with the new
54: * targets.
55: */
56: public class RelayChangeReport implements ChangeReport {
57: private Collection oldTargets;
58:
59: /**
60: * Constructor from a Relay.Source. The about-to-become-old targets
61: * are recorded.
62: */
63: public RelayChangeReport(Relay.Source rs) {
64: Set targets = rs.getTargets();
65: oldTargets = new ArrayList(targets.size());
66: oldTargets.addAll(targets);
67: }
68:
69: /**
70: * Get the recorded list of old target addresses. For use by the
71: * RelayLP.
72: */
73: Collection getOldTargets() {
74: return oldTargets;
75: }
76: }
|