001: /*
002: * <copyright>
003: *
004: * Copyright 2000-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: package org.cougaar.core.examples;
027:
028: import java.util.*;
029: import org.cougaar.util.*;
030: import org.cougaar.core.agent.*;
031: import org.cougaar.core.component.*;
032: import org.cougaar.core.domain.*;
033: import org.cougaar.core.blackboard.*;
034: import org.cougaar.core.node.*;
035: import org.cougaar.core.mts.MessageAddress;
036:
037: /**
038: * A filter for agent-to-node services.
039: * <p>
040: * See core examples "PluginServiceFilter" for further details.
041: * <p>
042: * Add a line like the following to a cluster.ini file: <pre>
043: * Node.AgentManager.Binder = org.cougaar.core.agent.AgentServiceFilter
044: * </pre>
045: **/
046: public class AgentServiceFilter extends ServiceFilter {
047:
048: // This method specifies the Binder to use (defined later)
049: protected Class getBinderClass(Object child) {
050: return AgentServiceFilterBinder.class;
051: }
052:
053: // This is a "Wrapper" binder which installs a service filter for plugins
054: public static class AgentServiceFilterBinder extends
055: ServiceFilterBinder {
056: public AgentServiceFilterBinder(BinderFactory bf, Object child) {
057: super (bf, child);
058: }
059:
060: // this method specifies a binder proxy to use, so as to avoid exposing the binder
061: // itself to the lower level objects.
062: protected ContainerAPI createContainerProxy() {
063: return new AgentFilteringBinderProxy();
064: }
065:
066: // this method installs the "filtering" service broker
067: protected ServiceBroker createFilteringServiceBroker(
068: ServiceBroker sb) {
069: return new AgentFilteringServiceBroker(sb);
070: }
071:
072: // this class implements a simple proxy for a plugin wrapper binder
073: protected class AgentFilteringBinderProxy extends
074: ServiceFilterContainerProxy {
075: }
076:
077: // this class catches requests for blackboard services, and
078: // installs its own service proxy.
079: protected class AgentFilteringServiceBroker extends
080: FilteringServiceBroker {
081: public AgentFilteringServiceBroker(ServiceBroker sb) {
082: super (sb);
083: }
084:
085: protected Object getServiceProxy(Object service,
086: Class serviceClass, Object client) {
087: if (service instanceof NodeIdentificationService) {
088: return new NodeIdentificationServiceProxy(
089: (NodeIdentificationService) service, client);
090: }
091: return null;
092: }
093: }
094: }
095:
096: public static class NodeIdentificationServiceProxy implements
097: NodeIdentificationService {
098: private NodeIdentificationService nis;
099: private Object client;
100:
101: public NodeIdentificationServiceProxy(
102: NodeIdentificationService nis, Object client) {
103: this .nis = nis;
104: this .client = client;
105: }
106:
107: public MessageAddress getMessageAddress() {
108: MessageAddress ret = nis.getMessageAddress();
109: System.out.println("Agent wrapper: get node-id " + ret
110: + " for client " + client);
111: return ret;
112: }
113: }
114: }
|