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.logistics.servlet;
028:
029: import org.cougaar.core.mts.MessageAddress;
030:
031: import org.cougaar.planning.ldm.PlanningFactory;
032: import org.cougaar.planning.ldm.LDMServesPlugin;
033:
034: import org.cougaar.core.service.BlackboardService;
035: import org.cougaar.core.service.BlackboardQueryService;
036: import org.cougaar.core.service.LoggingService;
037: import org.cougaar.core.service.SchedulerService;
038: import org.cougaar.core.service.wp.WhitePagesService;
039:
040: import org.cougaar.planning.servlet.BlackboardServletSupport;
041:
042: import org.cougaar.util.ConfigFinder;
043:
044: /**
045: * <pre>
046: * This support class offers additional services on top of the
047: * SimpleServletSupport class, including access to the blackboard,
048: * config finder, root factory, ldm serves plugin, and scheduler service.
049: *
050: * Publishes a condition that must be in the range 0.0-1.0.
051: *
052: * The name is a parameter to the component. If none is provided, the name
053: * is "DoubleCondition".
054: * </pre>
055: */
056: public class ConditionSupport extends BlackboardServletSupport {
057: public ConditionSupport(String path, MessageAddress agentId,
058: BlackboardQueryService blackboardQuery,
059: LoggingService logger, BlackboardService blackboard,
060: ConfigFinder configFinder, PlanningFactory ldmf,
061: LDMServesPlugin ldm, SchedulerService scheduler,
062: WhitePagesService wp, String conditionName) {
063: super (path, agentId, blackboardQuery, logger, blackboard,
064: configFinder, ldmf, ldm, scheduler);
065: this .wp = wp;
066: this .conditionName = conditionName;
067:
068: publishCondition();
069: }
070:
071: public WhitePagesService getWhitePagesService() {
072: return wp;
073: }
074:
075: /** publishes the condition to blackboard, if the condition service is available. */
076: public void publishCondition() {
077: ConditionServlet.DoubleCondition doubleCondition = new ConditionServlet.DoubleCondition(
078: conditionName);
079:
080: try {
081: getBlackboardService().openTransaction();
082: getBlackboardService().publishAdd(doubleCondition);
083: setCondition(doubleCondition);
084: if (getLog().isInfoEnabled())
085: getLog().info(
086: getAgentIdentifier()
087: + " - published condition "
088: + doubleCondition);
089: } catch (Exception exc) {
090: getLog()
091: .error("Could not publish double condition???", exc);
092: } finally {
093: getBlackboardService().closeTransactionDontReset();
094: }
095: }
096:
097: protected void setCondition(
098: ConditionServlet.DoubleCondition condition) {
099: this .condition = condition;
100: }
101:
102: /** not usually needed */
103: public ConditionServlet.DoubleCondition getCondition() {
104: return condition;
105: }
106:
107: protected String getConditionName() {
108: return conditionName;
109: }
110:
111: protected ConditionServlet.DoubleCondition condition;
112: protected WhitePagesService wp;
113: protected String conditionName;
114: }
|