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.agent;
028:
029: import org.cougaar.core.component.Component;
030: import org.cougaar.core.component.ServiceBroker;
031: import org.cougaar.core.component.ServiceRevokedListener;
032: import org.cougaar.core.logging.LoggingServiceWithPrefix;
033: import org.cougaar.core.mts.MessageAddress;
034: import org.cougaar.core.service.AgentIdentificationService;
035: import org.cougaar.core.service.LoggingService;
036: import org.cougaar.util.GenericStateModelAdapter;
037:
038: /**
039: * This component is loaded late in the agent, to announce
040: * the agent Suspening/Stopping/<i>etc</i> state transitions.
041: * @see BeginLogger
042: */
043: public final class EndLogger extends GenericStateModelAdapter implements
044: Component {
045:
046: private ServiceBroker sb;
047:
048: private LoggingService log;
049:
050: public void setServiceBroker(ServiceBroker sb) {
051: this .sb = sb;
052: }
053:
054: public void load() {
055: super .load();
056:
057: // get our local agent's address
058: MessageAddress localAgent = null;
059: AgentIdentificationService ais = (AgentIdentificationService) sb
060: .getService(this , AgentIdentificationService.class,
061: null);
062: if (ais != null) {
063: localAgent = ais.getMessageAddress();
064: sb.releaseService(this , AgentIdentificationService.class,
065: ais);
066: }
067:
068: // get logging service
069: log = (LoggingService) sb.getService(this ,
070: LoggingService.class, null);
071:
072: // prefix with agent name
073: String prefix = localAgent + ": ";
074: log = LoggingServiceWithPrefix.add(log, prefix);
075:
076: if (log.isInfoEnabled()) {
077: log.info("Loaded");
078: }
079: }
080:
081: public void start() {
082: super .start();
083: if (log.isInfoEnabled()) {
084: log.info("Started");
085: }
086: }
087:
088: public void resume() {
089: super .resume();
090: if (log.isInfoEnabled()) {
091: log.info("Resumed");
092: }
093: }
094:
095: // the component model is "first loaded is last unload", so these
096: // are the begin-states (i.e. the "*ing" instead of "*ed").
097:
098: public void suspend() {
099: super .suspend();
100: if (log.isInfoEnabled()) {
101: log.info("Suspending");
102: }
103: }
104:
105: public void stop() {
106: super .stop();
107: if (log.isInfoEnabled()) {
108: log.info("Stopping");
109: }
110: }
111:
112: public void unload() {
113: super .unload();
114: if (log.isInfoEnabled()) {
115: log.info("Unloading");
116: }
117: }
118: }
|