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