001: /*
002: * <copyright>
003: *
004: * Copyright 1997-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:
027: package org.cougaar.core.qos.gossip;
028:
029: import org.cougaar.core.component.ServiceBroker;
030: import org.cougaar.core.component.ServiceProvider;
031: import org.cougaar.core.node.NodeIdentificationService;
032: import org.cougaar.core.qos.metrics.Constants;
033: import org.cougaar.core.qos.metrics.CredibilityQualifier;
034: import org.cougaar.core.qos.metrics.DeltaValueQualifier;
035: import org.cougaar.core.qos.metrics.MetricNotificationQualifier;
036: import org.cougaar.mts.base.BoundComponent;
037:
038: /**
039: * Default Gossip Qualifier implementation which specifies the
040: * restrictions on keys and values being sent to neighbors
041: */
042: public class SimpleGossipQualifierComponent extends BoundComponent {
043: public void load() {
044: super .load();
045:
046: ServiceBroker sb = getServiceBroker();
047: NodeIdentificationService nis = (NodeIdentificationService) sb
048: .getService(this , NodeIdentificationService.class, null);
049: String node = nis.getMessageAddress().getAddress();
050:
051: ServiceProvider sp = new Provider(node);
052: sb.addService(GossipQualifierService.class, sp);
053: }
054:
055: private static class Provider implements ServiceProvider {
056: private GossipQualifierService impl;
057:
058: Provider(String node) {
059: impl = new Impl(node);
060: }
061:
062: public Object getService(ServiceBroker sb, Object requestor,
063: Class serviceClass) {
064: if (serviceClass == GossipQualifierService.class) {
065: return impl;
066: } else {
067: return null;
068: }
069: }
070:
071: public void releaseService(ServiceBroker sb, Object requestor,
072: Class serviceClass, Object service) {
073: }
074: }
075:
076: private static class Impl implements GossipQualifierService,
077: Constants {
078: String my_addr;
079: String host_key;
080: String ipflow_key;
081: String node;
082: String node_key;
083:
084: Impl(String node) {
085: this .node = node;
086: try {
087: my_addr = java.net.InetAddress.getLocalHost()
088: .getHostAddress();
089: } catch (java.net.UnknownHostException ex) {
090: my_addr = "127.0.0.1";
091: }
092: host_key = "Host_" + my_addr;
093: ipflow_key = "Ip_Flow_" + my_addr;
094: node_key = "Node_" + node;
095: }
096:
097: public MetricNotificationQualifier getNotificationQualifier(
098: String key) {
099: if (key.matches("^Agent_.*_((Spoke)|(Heard))Time$")) {
100: // These values are milliseconds.
101: return new DeltaValueQualifier(5000.0);
102: } else {
103: return new CredibilityQualifier(SYS_DEFAULT_CREDIBILITY);
104: }
105: }
106:
107: public boolean shouldForwardRequest(String key) {
108: return !key.startsWith(host_key)
109: && !key.startsWith("Site_Flow")
110: && !key.startsWith("Service")
111: && !key.startsWith("AgentFlow")
112: && !key.startsWith(node_key)
113: && key.indexOf("169.0.0.1") == -1;
114: }
115:
116: }
117:
118: }
|