#/** # Apartment threaded web server. Creates and maintains a pool of WebClient # apartment threaded objects. Permits application specific content and session # handler objects. #
# Copyright© 2006, Dean Arnold, Presicient Corp., USA
# All rights reserved.
#
# Licensed under the Academic Free License version 2.1, as specified in the # License.txt file included in this software package, or at # OpenSource.org. # # @author D. Arnold # @since 2006-08-21 # @self $self # @see HTTP::Daemon::Threaded::Listener # @see HTTP::Daemon::Threaded::Logable # @see HTTP::Daemon::Threaded::Logger # @see HTTP::Daemon::Threaded::WebClient # @see HTTP::Daemon::Threaded::Content # @see HTTP::Daemon::Threaded::ContentParams # @see HTTP::Daemon::Threaded::SessionCache # @see HTTP::Daemon::Threaded::Session # #*/ package HTTP::Daemon::Threaded; use threads; use Thread::Apartment; use base qw(Thread::Apartment); use strict; use warnings; our $VERSION = '0.90'; our $container; our $timeout; #/** # Set TQD timeout. # # @static # @param $timeout TQD timeout in seconds # # @return none #*/ sub setTimeout { $timeout = ($_[0] eq 'HTTP::Daemon::Threaded') ? $_[1] : $_[0]; } #/** # Constructor. Provides facade for Thread::Apartment::new, # to create a TAS for HTTP::Daemon::Threaded::Listener. # Allocates or creates a thread, and installs a Listener in it. #
# Note that the following parameters are recognized by
# HTTP::Daemon::Threaded, HTTP::Daemon::Threaded::Listener, and/or
# HTTP::Daemon::Threaded::WebClient, but
# applications may supply additional parameter key/value pairs
# which will be provided to the constructor for any specified
# HTTP::Daemon::Threaded::ContentParams class.
#
# @param AptTimeout (optional) Thread::Apartment proxy return timeout
# @param Port (optional) TCP listen port; default 80.
# @param MaxClients (optional) max number of client handlers to spawn;
# default 5
# @param LogLevel (optional) logging level; 1 => errors only; 2 => errors and warnings only; 3 => errors, warnings,
# and info messages; default 1
# @param EventLogger (optional) Instance of a HTTP::Daemon::Threaded::Logger to receive
# event notifications (except for web requests)
# @param WebLogger (optional) Instance of a HTTP::Daemon::Threaded::Logger to receive
# web request notifications
# @param Handlers (required) URI handler map; arrayref mapping URI regex's to handler package names
# @param UserAuth (optional) instance of a subclass of HTTP::Daemon::Threaded::Auth (not yet supported)
# @param SessionCache (optional) instance of a subclass of HTTP::Daemon::Threaded::SessionCache
# to be used to create/manage sessions
# @param InactivityTimer (optional) number of seconds a WebClient waits before disconnecting
# an idle connection; default 10 minutes
# @param ContentParams (optional) name of concrete implementation of HTTP::Daemon::Threaded::ContentParams
# @param DocRoot (optional) root directory for default file based content handler
# @param ProductTokens (optional) product token string to return to client; default
# is 'HTTP::Daemon::Threaded/
# MediaTypes => { 'text/css' => 'css' }. Used to
# add media types for LWP::MediaTypes::guess_media_type()
#
# @return TAC proxy for HTTP::Daemon::Threaded::Listener object
# @see LWP::MediaTypes
#*/
sub new {
#
# overrides T::A new, returning the container object
#
my ($class, %args) = @_;
$args{AptClass} = 'HTTP::Daemon::Threaded::Listener';
$args{AptTimeout} = $timeout
unless exists $args{AptTimeout};
$container = Thread::Apartment->new( %args )
|| die "Could not install into an apartment: $@.";
return $container;
}
1;