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.mobility.ldm;
028:
029: import java.util.Collection;
030: import java.util.Collections;
031:
032: import org.cougaar.core.blackboard.DirectiveMessage;
033: import org.cougaar.core.blackboard.EnvelopeTuple;
034: import org.cougaar.core.component.ServiceBroker;
035: import org.cougaar.core.domain.DomainAdapter;
036: import org.cougaar.core.mts.MessageAddress;
037: import org.cougaar.core.node.NodeIdentificationService;
038: import org.cougaar.core.service.AgentIdentificationService;
039: import org.cougaar.core.service.UIDService;
040:
041: /**
042: * This component is the mobility domain, which just has the
043: * {@link MobilityFactory} and no {@link
044: * org.cougaar.core.domain.LogicProvider}s.
045: * <p>
046: * The original idea was to add security by restricting access to
047: * the {@link MobilityFactory}, which is required to create a
048: * {@link AgentControl}.
049: */
050: public class MobilityDomain extends DomainAdapter {
051:
052: private static final String MOBILTY_NAME = "mobility";
053:
054: public String getDomainName() {
055: return MOBILTY_NAME;
056: }
057:
058: public Collection getAliases() {
059: return Collections.singleton(getDomainName());
060: }
061:
062: protected void loadFactory() {
063: UIDService uidService = getUIDService();
064: MessageAddress nodeId = getNodeId();
065: MessageAddress agentId = getAgentId();
066: MobilityFactory f = new MobilityFactoryImpl(uidService, nodeId,
067: agentId);
068:
069: setFactory(f);
070: }
071:
072: protected void loadXPlan() {
073: // no xplan
074: }
075:
076: private UIDService getUIDService() {
077: ServiceBroker sb = getServiceBroker();
078: UIDService uidService = (UIDService) sb.getService(this ,
079: UIDService.class, null);
080: if (uidService == null) {
081: throw new RuntimeException("Unable to obtain uid service");
082: }
083: return uidService;
084: }
085:
086: private MessageAddress getAgentId() {
087: // get the agentId
088: ServiceBroker sb = getServiceBroker();
089: AgentIdentificationService agentIdService = (AgentIdentificationService) sb
090: .getService(this , AgentIdentificationService.class,
091: null);
092: if (agentIdService == null) {
093: throw new RuntimeException(
094: "Unable to obtain node-id service");
095: }
096: MessageAddress agentId = agentIdService.getMessageAddress();
097: sb.releaseService(this , AgentIdentificationService.class,
098: agentIdService);
099: if (agentId == null) {
100: throw new RuntimeException("Unable to obtain agent id");
101: }
102: return agentId;
103: }
104:
105: private MessageAddress getNodeId() {
106: // get the nodeId
107: ServiceBroker sb = getServiceBroker();
108: NodeIdentificationService nodeIdService = (NodeIdentificationService) sb
109: .getService(this , NodeIdentificationService.class, null);
110: if (nodeIdService == null) {
111: throw new RuntimeException(
112: "Unable to obtain node-id service");
113: }
114: MessageAddress nodeId = nodeIdService.getMessageAddress();
115: sb.releaseService(this , NodeIdentificationService.class,
116: nodeIdService);
117: if (nodeId == null) {
118: throw new RuntimeException("Unable to obtain node id");
119: }
120: return nodeId;
121: }
122:
123: // zero LPs
124: protected void loadLPs() {
125: }
126:
127: public void invokeMessageLogicProviders(DirectiveMessage message) {
128: }
129:
130: public void invokeEnvelopeLogicProviders(EnvelopeTuple tuple,
131: boolean isPersistenceEnvelope) {
132: }
133:
134: public void invokeRestartLogicProviders(MessageAddress cid) {
135: }
136:
137: }
|