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.plugin.legacy;
028:
029: import org.cougaar.util.StateModelException;
030:
031: /** @deprecated Use SimplePlugin: no modification needed.
032: **/
033:
034: public abstract class SimplifiedPlugin extends ThinPlugin {
035: /** */
036: public SimplifiedPlugin() {
037: }
038:
039: //
040: // final all the important state model functions.
041: //
042:
043: public final void initialize() throws StateModelException {
044: super .initialize();
045: }
046:
047: public void load(Object object) throws StateModelException {
048: super .load(object);
049: }
050:
051: public final void start() throws StateModelException {
052: super .start();
053: }
054:
055: public final void suspend() throws StateModelException {
056: super .suspend();
057: }
058:
059: public final void resume() throws StateModelException {
060: super .resume();
061: }
062:
063: public final void stop() throws StateModelException {
064: super .stop();
065: }
066:
067: /** call initialize within an open transaction. **/
068: protected final void prerun() {
069: try {
070: openTransaction();
071: setupSubscriptions();
072: } catch (Exception e) {
073: synchronized (System.err) {
074: System.err.println("Caught " + e);
075: e.printStackTrace();
076: }
077: } finally {
078: closeTransactionDontReset();
079: }
080: }
081:
082: /** Called during initialization to set up subscriptions.
083: * More precisely, called in the plugin's Thread of execution
084: * inside of a transaction before execute will ever be called.
085: **/
086: protected abstract void setupSubscriptions();
087:
088: /** Call execute in the right context.
089: * Note that this transaction boundary does NOT reset
090: * any subscription changes.
091: * @see #execute() documentation for details
092: **/
093: protected final void cycle() {
094: try {
095: openTransaction();
096: if (wasAwakened()
097: || (getBlackboardService().haveCollectionsChanged())) {
098: execute();
099: }
100: } catch (Exception e) {
101: synchronized (System.err) {
102: System.err.println("Caught " + e);
103: e.printStackTrace();
104: }
105: } finally {
106: closeTransaction();
107: }
108: }
109:
110: /**
111: * Called inside of an open transaction whenever the plugin was
112: * explicitly told to run or when there are changes to any of
113: * our subscriptions.
114: **/
115: protected abstract void execute();
116:
117: }
|