001: /*
002: * Copyright (c) 2000 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.lib.aSocket;
026:
027: import seda.sandStorm.api.*;
028: import seda.sandStorm.api.internal.*;
029: import seda.sandStorm.core.*;
030: import seda.sandStorm.internal.*;
031: import java.util.*;
032:
033: /**
034: * Internal stage wrapper implementation for aSocket.
035: */
036: class aSocketStageWrapper implements StageWrapperIF {
037:
038: private String name;
039: private StageIF stage;
040: private EventHandlerIF handler;
041: private ConfigDataIF config;
042: private FiniteQueue eventQ;
043: private SelectSourceIF selsource;
044: private ThreadManagerIF tm;
045: private StageStatsIF stats;
046:
047: aSocketStageWrapper(String name, EventHandlerIF handler,
048: ConfigDataIF config, ThreadManagerIF tm) {
049: this .name = name;
050: this .handler = handler;
051: this .config = config;
052: this .tm = tm;
053: this .stats = new StageStats(this );
054:
055: int queuelen;
056: if ((queuelen = config.getInt("_queuelength")) <= 0) {
057: queuelen = -1;
058: }
059: if (queuelen == -1) {
060: eventQ = new FiniteQueue();
061: } else {
062: eventQ = new FiniteQueue();
063: QueueThresholdPredicate pred = new QueueThresholdPredicate(
064: eventQ, queuelen);
065: eventQ.setEnqueuePredicate(pred);
066: }
067: this .selsource = ((aSocketEventHandler) handler)
068: .getSelectSource();
069: this .stage = new Stage(name, this , (SinkIF) eventQ, config);
070: this .config.setStage(this .stage);
071: }
072:
073: /**
074: * Initialize this stage.
075: */
076: public void init() throws Exception {
077: handler.init(config);
078: tm.register(this );
079: }
080:
081: /**
082: * Destroy this stage.
083: */
084: public void destroy() throws Exception {
085: tm.deregister(this );
086: handler.destroy();
087: }
088:
089: /**
090: * Return the event handler associated with this stage.
091: */
092: public EventHandlerIF getEventHandler() {
093: return handler;
094: }
095:
096: /**
097: * Return the stage handle for this stage.
098: */
099: public StageIF getStage() {
100: return stage;
101: }
102:
103: /**
104: * Return the source from which events should be pulled to
105: * pass to this EventHandlerIF. <b>Note</b> that this method is not
106: * used internally.
107: */
108: public SourceIF getSource() {
109: return eventQ;
110: }
111:
112: /**
113: * Return the thread manager for this stage.
114: */
115: public ThreadManagerIF getThreadManager() {
116: return tm;
117: }
118:
119: // So aSocketTM can access it
120: SelectSourceIF getSelectSource() {
121: return selsource;
122: }
123:
124: // So aSocketTM can access it
125: SourceIF getEventQueue() {
126: return eventQ;
127: }
128:
129: public StageStatsIF getStats() {
130: return stats;
131: }
132:
133: /** Not implemented. */
134: public ResponseTimeControllerIF getResponseTimeController() {
135: return null;
136: }
137:
138: public String toString() {
139: return "ASOCKETSW[" + stage.getName() + "]";
140: }
141:
142: }
|