001: /*
002: * PipelineHandlerFactory.java February 2001
003: *
004: * Copyright (C) 2001, Niall Gallagher <niallg@users.sf.net>
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General
016: * Public License along with this library; if not, write to the
017: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
018: * Boston, MA 02111-1307 USA
019: */
020:
021: package simple.http;
022:
023: /**
024: * The <code>PipelineHandlerFactory</code> is used to hide a specific
025: * implementation of the <code>PipelineHandler</code> used. This allows
026: * a user of this to get access to a <code>PipelineHandler</code> using
027: * an implementation of a <code>ProtocolHandler</code>.
028: * <p>
029: * This will create an instance of a <code>PipelineHandler</code> to
030: * process any incomming <code>Pipeline</code>'s from a user. This will
031: * will multiplex <code>Pipeline</code>'s and read requests from the
032: * <code>Pipeline</code>'s generating <code>Request</code> objects and
033: * <code>Response</code> objects which will then be passed to the
034: * <code>ProtocolHandler</code> implementation provided.
035: *
036: * @author Niall Gallagher
037: */
038: public final class PipelineHandlerFactory {
039:
040: /**
041: * The default number of polling threads for a handler object.
042: */
043: private static final int DEFAULT_POLLERS = 20;
044:
045: /**
046: * The default maximum waiting time between polls of the input.
047: */
048: private static final int DEFAULT_WAIT = 1000;
049:
050: /**
051: * This will create an instance of a <code>PipelineHandler</code>
052: * object for processing <code>Pipeline</code> objects using an
053: * instance of the <code>ProtocolHandler</code>. This uses defaults
054: * for the <code>PipelineHandler</code> created. Specifics can be
055: * specified by using the overloaded getinstance method. The job
056: * of the <code>PipelineHandler</code> once it has been created is
057: * to read HTTP requests from <code>Pipeline</code>'s passed to it.
058: * These transactions will be used to generate <code>Request</code>
059: * and <code>Resposne</code> objects.
060: * <p>
061: * This will create a <code>PipelineHandler</code> to handle any
062: * connected <code>Pipeline</code>'s. This handler will poll the
063: * <code>Pipeline</code>'s <code>InputStream</code> so that there
064: * is no blocking, this will use an exponential backoff so that if
065: * the socket is not producing data it is polled less frequently.
066: *
067: * @param handler this will recive the requests from the
068: * <code>Pipeline</code>
069: */
070: public static PipelineHandler getInstance(ProtocolHandler handler) {
071: return getInstance(handler, DEFAULT_POLLERS, DEFAULT_WAIT);
072: }
073:
074: /**
075: * This will create an instance of a <code>PipelineHandler</code>
076: * object for processing <code>Pipeline</code> objects using an
077: * instance of the <code>ProtocolHandler</code>. This uses defaults
078: * for the <code>PipelineHandler</code> created. Specifics can be
079: * specified by using the overloaded getinstance method. The job
080: * of the <code>PipelineHandler</code> once it has been created is
081: * to read HTTP requests from <code>Pipeline</code>'s passed to it.
082: * These transactions will be used to generate <code>Request</code>
083: * and <code>Resposne</code> objects.
084: * <p>
085: * This will create a <code>PipelineHandler</code> to handle any
086: * connected <code>Pipeline</code>'s. This handler will poll the
087: * <code>Pipeline</code>'s <code>InputStream</code> so that there
088: * is no blocking, this will use an exponential backoff so that if
089: * the socket is not producing data it is polled less frequently.
090: * The <code>wait</code> parameter identifies a maximum that the
091: * <code>Pipeline</code>'s <code>InputStream</code> will be queued
092: * before the next poll.
093: *
094: * @param handler this will recive the requests from the
095: * <code>Pipeline</code>
096: *
097: * @param pollers this is the number of threads used for polling
098: * the <code>Pipeline</code>'s, this will not effect the number
099: * of <code>Pipeline</code>'s that can be polled
100: *
101: * @param wait this is the maximum waiting time for the polling
102: * of the <code>Pipeline</code>, there is an exponential backoff
103: * when polling the <code>Pipeline</code> this limits the wait
104: */
105: public static PipelineHandler getInstance(ProtocolHandler handler,
106: int pollers, int wait) {
107: return new PipelineProcessor(handler, pollers, wait);
108: }
109:
110: }
|