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.planning.ldm;
028:
029: import java.util.ArrayList;
030: import java.util.Collection;
031:
032: import org.cougaar.core.component.ServiceBroker;
033: import org.cougaar.core.domain.DomainAdapter;
034: import org.cougaar.core.domain.Factory;
035: import org.cougaar.core.domain.RootPlan;
036: import org.cougaar.core.mts.MessageAddress;
037: import org.cougaar.core.service.AgentIdentificationService;
038: import org.cougaar.core.service.AlarmService;
039: import org.cougaar.planning.ldm.lps.AssetTransferLP;
040: import org.cougaar.planning.ldm.lps.ComplainingLP;
041: import org.cougaar.planning.ldm.lps.DeletionLP;
042: import org.cougaar.planning.ldm.lps.NotificationLP;
043: import org.cougaar.planning.ldm.lps.ReceiveAssetLP;
044: import org.cougaar.planning.ldm.lps.ReceiveAssetRescindLP;
045: import org.cougaar.planning.ldm.lps.ReceiveAssetVerificationLP;
046: import org.cougaar.planning.ldm.lps.ReceiveDeletionLP;
047: import org.cougaar.planning.ldm.lps.ReceiveNotificationLP;
048: import org.cougaar.planning.ldm.lps.ReceiveRescindLP;
049: import org.cougaar.planning.ldm.lps.ReceiveTaskLP;
050: import org.cougaar.planning.ldm.lps.RemoteAllocationLP;
051: import org.cougaar.planning.ldm.lps.RescindLP;
052: import org.cougaar.planning.service.LDMService;
053:
054: /**
055: * This is the "planning" domain, which defines planning
056: * data types (Task, PlanElement, etc) and loads related LPs.
057: */
058: public class PlanningDomain extends DomainAdapter {
059: public static final String PLANNING_NAME = "planning";
060:
061: protected AgentIdentificationService agentIdService;
062: protected MessageAddress self;
063: private LDMService ldmService;
064: protected AlarmService alarmService;
065:
066: public String getDomainName() {
067: return PLANNING_NAME;
068: }
069:
070: public void setAgentIdentificationService(
071: AgentIdentificationService ais) {
072: this .agentIdService = ais;
073: if (ais == null) {
074: // Revocation
075: } else {
076: this .self = ais.getMessageAddress();
077: }
078: }
079:
080: public void setLDMService(LDMService ldmService) {
081: this .ldmService = ldmService;
082: }
083:
084: public void setAlarmService(AlarmService alarmService) {
085: this .alarmService = alarmService;
086: }
087:
088: public void load() {
089: super .load();
090: if (ldmService != null) {
091: LDMServesPlugin ldm = ldmService.getLDM();
092: LDMContextTable.setLDM(self, ldm);
093: }
094: }
095:
096: public void unload() {
097: ServiceBroker sb = getServiceBroker();
098: if (agentIdService != null) {
099: sb.releaseService(this , AgentIdentificationService.class,
100: agentIdService);
101: agentIdService = null;
102: }
103: if (ldmService != null) {
104: sb.releaseService(this , LDMService.class, ldmService);
105: ldmService = null;
106: LDMContextTable.setLDM(self, null);
107: }
108: if (alarmService != null) {
109: sb.releaseService(this , AlarmService.class, alarmService);
110: alarmService = null;
111: }
112: super .unload();
113: }
114:
115: public Collection getAliases() {
116: ArrayList l = new ArrayList(2);
117: l.add("planning");
118: l.add("log");
119: return l;
120: }
121:
122: protected void loadFactory() {
123: LDMServesPlugin ldm = ldmService.getLDM();
124: Factory f = new PlanningFactoryImpl(ldm);
125: setFactory(f);
126: }
127:
128: protected void loadXPlan() {
129: LogPlan logplan = new LogPlanImpl();
130: setXPlan(logplan);
131: }
132:
133: protected void loadLPs() {
134: RootPlan rootplan = (RootPlan) getXPlanForDomain("root");
135: if (rootplan == null) {
136: throw new RuntimeException("Missing \"root\" plan!");
137: }
138:
139: LogPlan logplan = (LogPlan) getXPlan();
140: PlanningFactory ldmf = (PlanningFactory) getFactory();
141:
142: // input LPs
143: addLogicProvider(new ReceiveAssetLP(rootplan, logplan, ldmf,
144: self));
145: addLogicProvider(new ReceiveAssetVerificationLP(rootplan,
146: logplan, ldmf));
147: addLogicProvider(new ReceiveAssetRescindLP(rootplan, logplan,
148: ldmf));
149: addLogicProvider(new ReceiveNotificationLP(rootplan, logplan,
150: ldmf));
151: addLogicProvider(new ReceiveDeletionLP(rootplan, logplan, ldmf,
152: self));
153: addLogicProvider(new ReceiveRescindLP(rootplan, logplan));
154: addLogicProvider(new ReceiveTaskLP(rootplan, logplan, self,
155: ldmf, alarmService));
156:
157: // output LPs (+ some input)
158: addLogicProvider(new AssetTransferLP(rootplan, logplan, ldmf,
159: self));
160: addLogicProvider(new NotificationLP(rootplan, logplan, ldmf,
161: self));
162: addLogicProvider(new DeletionLP(rootplan, ldmf, self));
163: addLogicProvider(new RemoteAllocationLP(rootplan, ldmf, self,
164: alarmService, logplan));
165: // Below also does some error detection
166: addLogicProvider(new RescindLP(rootplan, logplan, ldmf, self));
167:
168: // error detection LP
169: addLogicProvider(new ComplainingLP(rootplan, self));
170: }
171: }
|