001: /*
002: * Copyright (c) 2001 by Matt Welsh and The Regents of the University of
003: * California. All rights reserved.
004: *
005: * Permission to use, copy, modify, and distribute this software and its
006: * documentation for any purpose, without fee, and without written agreement is
007: * hereby granted, provided that the above copyright notice and the following
008: * two paragraphs appear in all copies of this software.
009: *
010: * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
011: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
012: * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
013: * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
014: *
015: * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
016: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
017: * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
018: * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
019: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
020: *
021: * Author: Matt Welsh <mdw@cs.berkeley.edu>
022: *
023: */
024:
025: package seda.sandStorm.main;
026:
027: import seda.sandStorm.api.*;
028: import seda.sandStorm.api.internal.*;
029: import seda.sandStorm.core.*;
030: import seda.sandStorm.internal.*;
031:
032: /**
033: * This is the top-level class which acts as the "wrapper" and
034: * external interface to the Sandstorm runtime. By creating a
035: * Sandstorm object one can embed a Sandstorm system in another
036: * application. If you wish to run a standalone Sandstorm, this
037: * can be done from the commandline using the
038: * <tt>seda.sandStorm.main.Main</tt> class.
039: *
040: * <p>In general it is a good idea to have just one Sandstorm instance
041: * per JVM; multiple instances may interfere with one another in terms
042: * of resource allocation and thread scheduling.
043: *
044: * @author Matt Welsh
045: * @see Main
046: * @see SandstormConfig
047: */
048: public class Sandstorm {
049:
050: private sandStormMgr mgr;
051: private static Sandstorm globalSandstorm = null;
052:
053: /**
054: * Create a new Sandstorm with the default configuration and no
055: * initial stages.
056: */
057: public Sandstorm() throws Exception {
058: this (new SandstormConfig());
059: }
060:
061: /**
062: * Create a new Sandstorm, reading the configuration from the given
063: * file.
064: */
065: public Sandstorm(String fname) throws Exception {
066: this (new SandstormConfig(fname));
067: }
068:
069: /**
070: * Create a new Sandstorm with the given configuration.
071: */
072: public Sandstorm(SandstormConfig config) throws Exception {
073: if (globalSandstorm != null) {
074: throw new RuntimeException(
075: "Sandstorm: Error: Only one Sandstorm instance can be running at a given time.");
076: }
077: globalSandstorm = this ;
078: mgr = new sandStormMgr(config);
079: mgr.start();
080: }
081:
082: /**
083: * Return a handler to the ManagerIF for the Sandstorm instance.
084: * This interface allows one to create and obtain handles to stages.
085: */
086: public ManagerIF getManager() {
087: return mgr;
088: }
089:
090: /**
091: * Return a handle to the SystemManagerIF for the Sandstorm instance.
092: * This interface allows one to create stages and thread managers.
093: */
094: public SystemManagerIF getSystemManager() {
095: return mgr;
096: }
097:
098: /**
099: * Returns the currently-running Sandstorm instance, if any.
100: * Returns null if no Sandstorm is currently running.
101: */
102: public static Sandstorm getSandstorm() {
103: return globalSandstorm;
104: }
105:
106: }
|