01: /*
02: * <copyright>
03: *
04: * Copyright 2003-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: package org.cougaar.core.examples;
27:
28: import org.cougaar.core.blackboard.*;
29: import java.util.*;
30: import java.lang.reflect.*;
31: import org.cougaar.core.component.*;
32: import org.cougaar.util.*;
33: import org.cougaar.core.component.*;
34: import org.cougaar.core.agent.*;
35: import org.cougaar.core.mts.MessageAddress;
36:
37: import org.cougaar.util.log.*;
38:
39: /** DAB is a Dummy Agent Binder, an example wrapping binder for
40: * agents to be used as a trivial example to code writers.
41: * A node.ini recipe can load this as a wrapping binder as:
42: * <pre>
43: * Node.AgentManager.Binder = org.cougaar.core.examples.DAB
44: * </pre>
45: * Then when run, you'll see one message indicating that the DAB
46: * has been instantiated, and n+1 messages indicating that a DABber
47: * has, where n = number of agents (the extra one is the NodeAgent).
48: **/
49:
50: public class DAB extends ServiceFilter {
51: public int getPriority() {
52: return MAX_PRIORITY;
53: }
54:
55: Logger logger;
56:
57: public DAB() {
58: logger = Logging.getLogger(DAB.class);
59: logger.shout("DAB instantiated", new Throwable());
60: }
61:
62: public void setParameter(Object o) {
63: }
64:
65: protected Class getBinderClass(Object child) {
66: return DABber.class;
67: }
68:
69: // This is a "Wrapper" binder which installs a service filter for plugins
70: public static class DABber extends ServiceFilterBinder {
71: Logger logger;
72:
73: public DABber(BinderFactory bf, Object child) {
74: super (bf, child);
75: logger = Logging.getLogger(DAB.class);
76: logger.shout("DABber instantiated for", new Throwable());
77: }
78:
79: // this method specifies a binder proxy to use, so as to avoid exposing the binder
80: // itself to the lower level objects.
81: protected ContainerAPI createContainerProxy() {
82: return this ;
83: }
84:
85: // this method installs the "filtering" service broker
86: protected ServiceBroker createFilteringServiceBroker(
87: ServiceBroker sb) {
88: return sb;
89: }
90: }
91: }
|