01: /*
02: * <copyright>
03: *
04: * Copyright 2002-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.examples;
28:
29: import org.cougaar.core.plugin.*;
30: import org.cougaar.core.component.*;
31: import org.cougaar.core.blackboard.*;
32: import org.cougaar.util.*;
33: import java.util.*;
34: import org.cougaar.core.service.*;
35: import org.cougaar.core.node.*;
36: import org.cougaar.core.agent.*;
37:
38: /** A very simple Component which can be plugged into just about any
39: * non-descriminating insertion points in the system. When loaded, it
40: * prints a short message describing the node and agent where it is loaded
41: * and then dumps a stack. <br>
42: * This class is very useful for debugging the component model and load process.
43: * It is here (in the core module) because it depends on core cougaar (identification) services,
44: **/
45: public class DummyComponent extends ComponentSupport {
46: String p = "unknown";
47:
48: public void setParameter(Object o) {
49: if (o instanceof Collection) {
50: Iterator it = ((Collection) o).iterator();
51: if (it.hasNext())
52: p = (String) it.next();
53: }
54: }
55:
56: public void load() {
57: ServiceBroker sb = getBindingSite().getServiceBroker();
58:
59: // what node are we in?
60: String nn = "?";
61: {
62: NodeIdentificationService nis = (NodeIdentificationService) sb
63: .getService(this , NodeIdentificationService.class,
64: null);
65: if (nis != null) {
66: nn = nis.getMessageAddress().toString();
67: }
68: }
69:
70: // what agent?
71: String an = "?";
72: {
73: AgentIdentificationService ais = (AgentIdentificationService) sb
74: .getService(this , AgentIdentificationService.class,
75: null);
76: if (ais != null) {
77: an = ais.getName();
78: }
79: }
80:
81: System.err.println("Loading DummyComponent(" + p + ") in " + nn
82: + "/" + an + ":");
83: Thread.dumpStack();
84: super.load();
85: }
86: }
|