001: /* ====================================================================
002: The Jicarilla Software License
003:
004: Copyright (c) 2003 Leo Simons.
005: All rights reserved.
006:
007: Permission is hereby granted, free of charge, to any person obtaining
008: a copy of this software and associated documentation files (the
009: "Software"), to deal in the Software without restriction, including
010: without limitation the rights to use, copy, modify, merge, publish,
011: distribute, sublicense, and/or sell copies of the Software, and to
012: permit persons to whom the Software is furnished to do so, subject to
013: the following conditions:
014:
015: The above copyright notice and this permission notice shall be
016: included in all copies or substantial portions of the Software.
017:
018: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025: ==================================================================== */
026: package org.jicarilla.webserver.plumbing;
027:
028: import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
029: import org.jicarilla.lang.Assert;
030: import org.jicarilla.lang.RecyclingObjectFactory;
031: import org.jicarilla.net.Event;
032: import org.jicarilla.plumbing.NoopSink;
033: import org.jicarilla.plumbing.PostProcessor;
034: import org.jicarilla.plumbing.Stage;
035:
036: /**
037: *
038: *
039: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
040: * @version $Id: BeanshellHTTPChannelFactory.java,v 1.1 2004/03/31 12:11:00 lsimons Exp $
041: */
042: public class BeanshellHTTPChannelFactory extends RecyclingObjectFactory {
043: //private Stage m_stage;
044:
045: public synchronized Object makeObject() throws Exception {
046: //if( m_stage == null )
047: //{
048: /*Interpreter i = new Interpreter();
049: i.source( "create-pipeline.bsh" );
050:
051: m_stage = (Stage)i.get( "pipeline" );*/
052:
053: // m_stage = createPipeline();
054: //}
055: //return m_stage;
056: return createPipeline();
057: }
058:
059: public Stage createPipeline() {
060: final PostProcessor processor = new PostProcessor(
061: new LinkedQueue(), new NoopSink()) {
062: public void put(final Object o) throws InterruptedException {
063: final HTTPEvent e = getEvent(o);
064: super .put(e);
065: }
066:
067: public boolean offer(final Object o, final long l)
068: throws InterruptedException {
069: final HTTPEvent e = getEvent(o);
070: return super .offer(e, l);
071: }
072:
073: protected HTTPEvent getEvent(final Object o) {
074: Assert.assertTrue(o instanceof Event);
075:
076: if (o instanceof HTTPEvent)
077: return (HTTPEvent) o;
078:
079: final Event ev = (Event) o;
080: final HTTPEvent e = new HTTPEvent();
081: e.setChannel(ev.getChannel());
082: e.setContext(ev.getContext());
083: return e;
084: }
085: };
086:
087: processor.addStage(new BenchmarkStage( // start
088: new LinkedQueue(), new NoopSink()));
089: processor.addStage(new ParsingStage(new LinkedQueue(),
090: new NoopSink()));
091: processor.addStage(new EchoStage(new LinkedQueue(),
092: new NoopSink()));
093: /*processor.addStage(
094: new FilesystemStage(
095: new LinkedQueue(),
096: new NoopSink(),
097: new FilesystemImpl(".")
098: )
099: );*/
100: processor.addStage(new BenchmarkStage( // finish
101: new LinkedQueue(), new NoopSink()));
102: processor.addStage(new WritingStage(new LinkedQueue(),
103: new NoopSink()));
104:
105: return processor;
106: }
107: }
|