|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--org.locomotive.loco.servlet.ServletFactory
This class is the Thread subclass that makes Servlets for another
Object (like ServletEntry or ServletPool) that needs new servlet
instances. ServletFactory has the job of instantiating and
initializing servlets, and not doing so when a servlet signals
that new servlets from its class are temporarily or permanently
unavailable. Once a ServletFactory instantiates and initializes
a servlet, the ServletFactory distributes that servlet by
encapsulating it in a ServletFactoryEvent and firing the event
off to each of the ServletFactoryListeners.
During initialization, the servlet instance can signal that
it is not to be placed into active service by throwing an
UnavailableException or ServletException. If a servlet
instance throws an exception of this type, it must not be
placed into active service, and the instance must be
immediately released by the servlet container. The
servlet's destroy() method is not called in this case as
initialization was not considered to be successful.
After the instance of the failed servlet is released, a
new instance may be instantiated and initialized by the
container at any time. The only exception to this rule is
if the UnavailableException thrown by the failed servlet
which indicates the minimum time of unavailability. In
this case, the container must wait for the minimum time of
unavailablity to pass before creating and initializing a
new servlet instance.
Field Summary | |
protected int |
availability
This member variable holds the current creation availability status of this ServletFactory's class of servlets. |
static int |
AVAILABLE
If the instance member availability is set to
AVAILABLE , that means that servlets of the
class servlet_class can be created and initialized. |
protected int |
cur_pool_size
This member variable stores the current number of servlets that this ServletFactory's primary listener currently has. |
static int |
default_wait_retries
The default number of retries that ServletFactories will attempt when trying to instantiate and initialize servlets of any given class. |
static int |
default_waiting_period
This is the default waiting period that ServletFactories will wait before continuing to instantiate, initialize, and offer new servlet instances after a servlet throws a ServletException while the servlet is either being instantiated or initialized. |
protected boolean |
finished
This ServletFactory Thread will keep looping (running) as long as nothing has called our shutdown() method. |
protected int |
max_pool_size
This member variable stores the maximum number of servlets that this ServletFactory's primary listener can hold or use. |
protected int |
min_pool_size
This member variable stores the minimum number of servlets that this ServletFactory's primary listener needs to keep on hand. |
protected int |
need_more_servlets
This member variable is used when we've created the minimum number of servlets and they're all in use, and more requests come in needing more servlets. |
static int |
PERMANENTLY_UNAVAILABLE
If the instance member availability is set to
PERMANENTLY_UNAVAILABLE , that means that a
ServletFactory won't try to create servlets of the class
servlet_class . |
protected ServletFactoryListener |
primary_listener
This member variable stores a reference to this ServletFactory's "primary listener" -- an instance of an Object (like ServletEntry or ServletPool) that this ServletFactory gives the ready-to-serve servlets to. |
protected java.lang.Class |
servlet_class
This is the Class of servlet(s) that this ServletFactory is responsible for instantiating, initializing, and handing out. |
protected java.util.Vector |
servlet_factory_listeners
A collection of Objects listening for ServletFactoryEvents. |
protected java.lang.Thread |
servlet_factorys_thread
This member variable simply holds a reference to this ServletFactory's own Thread instance. |
static int |
SHUTDOWN
If the instance member availability is set to
SHUTDOWN , that means that this ServletFactory
has been shut down. |
protected java.lang.String |
unavailability_reason
This member variable stores the text reason for the unavailability of these servlets. |
static int |
UNAVAILABLE_AND_WAITING
If the instance member availability is set to
UNAVAILABLE_AND_WAITING , that means that a
ServletFactory won't try to create servlets of the class
servlet_class until unavailable_seconds
have elapsed. |
protected int |
unavailable_seconds
If this instance member is non-zero and availability
has the value UNAVAILABLE_AND_WAITING ,
ServletFactory will sleep for unavailable_seconds
seconds before trying again to make a new servlet. |
static int |
UNLIMITED_RETRIES
If the instance member default_wait_retries is
set to UNLIMITED_RETRIES , that means that a
ServletFactory will never stop trying to make servlets. |
protected int |
wait_count
This variable is used to count how many times this ServletFactory has waited after trying unsuccessfully to instantiate and initialize a servlet. |
protected int |
wait_retries
Each class's ServletFactory tries to create servlets this number of times before finally giving up. |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY,
MIN_PRIORITY,
NORM_PRIORITY |
Constructor Summary | |
protected |
ServletFactory(ServletFactoryListener listener,
java.lang.Class servlet_class,
javax.servlet.ServletConfig servlet_config)
Creates a new ServletFactory Object (not yet started, though). |
Method Summary | |
void |
addServletFactoryListener(ServletFactoryListener listener)
Adds the specified ServletFactoryListener to the list of listeners to which this ServletFactory will broadcast events. |
void |
fireServletFactoryEvent(ServletFactoryEvent servlet_factory_event)
Broadcasts the specified ServletFactoryEvent to all of the known ServletFactoryListener Objects. |
int |
getAvailability()
Returns the availability status of new, initialized instances of servlets whose Class is servlet_class . |
protected void |
getCounts()
This method calls some ServletFactoryListener methods on our primary listener to find out the current values for the minimum number of servlets we should keep on hand, the maximum number of servlets we should keep on hand, and the current number of servlets that are in service. |
int |
getCurPoolSize()
Returns this ServletFactory's copy of the value of the primary ServletFactoryListener's current pool size. |
int |
getMaxPoolSize()
Returns this ServletFactory's copy of the value of the primary ServletFactoryListener's maximum pool size. |
int |
getMinPoolSize()
Returns this ServletFactory's copy of the value of the primary ServletFactoryListener's minimum pool size. |
java.lang.Class |
getServletClass()
Returns the Class of servlets that this ServletFactory is managing. |
java.lang.String |
getUnavailabilityReason()
Returns the reason for the unavailability. |
int |
getUnavailableSeconds()
Gets the number of seconds that this ServletFactory will wait (or is currently waiting) before trying to make more servlets. |
protected void |
initializeServlet(javax.servlet.Servlet servlet_to_init)
Initializes the servlet by calling the init method of the servlet, passing in this ServletFactory's servlet_config Object. |
protected javax.servlet.Servlet |
instantiateServlet()
Instantiates a new servlet and returns a reference to it. |
void |
makeAndFireStatusEvent()
Regardless of the current availability status of the servlets, this method instantiates a new ServletFactoryEvent with the servlet_class, availability, unavailable_seconds, and unavailability_reason values, and then fires that event to the listeners. |
protected javax.servlet.Servlet |
makeServlet()
Tries to instantiate and initialize a servlet. |
void |
needMoreServlets()
Increments the need_more_servlets int member
variable, and then notifies the ServletFactory's Thread that the value
has changed. |
void |
removeServletFactoryListener(ServletFactoryListener listener)
Removes the specified ServletFactoryListener from the list of listeners to which this ServletFactory will broadcast events. |
void |
run()
After another Object calls the ServletFactory.start() method, this class's run() method is called. |
void |
setAvailability(int availability)
Sets the availability code for this ServletFactory's class of servlets. |
void |
setCurPoolSize(int new_size)
Sets the ServletFactory's copy of the value of the primary ServletFactoryListener's current pool size. |
void |
setMaxPoolSize(int new_size)
Sets the ServletFactory's copy of the value of the primary ServletFactoryListener's maximum pool size. |
void |
setMinPoolSize(int new_size)
Sets the ServletFactory's copy of the value of the primary ServletFactoryListener's minimum pool size. |
void |
setUnavailabilityReason(java.lang.String reason)
Sets the reason for the unavailability. |
void |
setUnavailableSeconds(int unavailable_seconds)
Sets the number of seconds that this ServletFactory should wait before trying to make more servlets. |
void |
shutdown()
Call this method to shut down the ServletFactory (it can't be restarted.. |
void |
triggerUnavailability(javax.servlet.ServletException servlet_exception)
This method takes a ServletException or an UnavailableException and changes the state of the ServletFactory to an unavailable state (as specified by the exception), and creates and fires an event about the state change to the ServletFactoryListeners. |
Methods inherited from class java.lang.Thread |
activeCount,
checkAccess,
countStackFrames,
currentThread,
destroy,
dumpStack,
enumerate,
getContextClassLoader,
getName,
getPriority,
getThreadGroup,
interrupt,
interrupted,
isAlive,
isDaemon,
isInterrupted,
join,
join,
join,
resume,
setContextClassLoader,
setDaemon,
setName,
setPriority,
sleep,
sleep,
start,
stop,
stop,
suspend,
toString,
yield |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final int AVAILABLE
availability
is set to
AVAILABLE
, that means that servlets of the
class servlet_class
can be created and initialized.public static final int UNAVAILABLE_AND_WAITING
availability
is set to
UNAVAILABLE_AND_WAITING
, that means that a
ServletFactory won't try to create servlets of the class
servlet_class
until unavailable_seconds
have elapsed.public static final int PERMANENTLY_UNAVAILABLE
availability
is set to
PERMANENTLY_UNAVAILABLE
, that means that a
ServletFactory won't try to create servlets of the class
servlet_class
.public static final int SHUTDOWN
availability
is set to
SHUTDOWN
, that means that this ServletFactory
has been shut down.public static final int UNLIMITED_RETRIES
default_wait_retries
is
set to UNLIMITED_RETRIES
, that means that a
ServletFactory will never stop trying to make servlets.public static int default_waiting_period
default_waiting_period.
default_waiting_period
before trying again to instantiate and initialize any
more servlets from the class for which the ServletFactory is
responsible. The same thing happens when a servlet throws an
instance of ServletException during initialization, since there's
nothing in the ServletException to tell the servlet container when
to try again.
default_waiting_period
can be specified
in the Locomotive's configuration information.public static int default_wait_retries
protected int wait_retries
protected int wait_count
protected int unavailable_seconds
availability
has the value UNAVAILABLE_AND_WAITING
,
ServletFactory will sleep for unavailable_seconds
seconds before trying again to make a new servlet.protected java.lang.String unavailability_reason
protected java.util.Vector servlet_factory_listeners
protected java.lang.Class servlet_class
protected int availability
ServletFactory.AVAILABLE,
ServletFactory.UNAVAILABLE_AND_WAITING,
ServletFactory.PERMANENTLY_UNAVAILABLE
. By default,
this field is set to ServletFactory.AVAILABLE
.protected ServletFactoryListener primary_listener
primary_listener
Object.protected int min_pool_size
protected int max_pool_size
protected int cur_pool_size
protected java.lang.Thread servlet_factorys_thread
protected int need_more_servlets
protected boolean finished
Constructor Detail |
protected ServletFactory(ServletFactoryListener listener, java.lang.Class servlet_class, javax.servlet.ServletConfig servlet_config)
listener
- the Object that this ServletFactory is
making servlets for. As of this writing,
this listener should either be a
ServletPool Object, or a ServletEntry
Object. It's usually the Object that
instantiated this ServletFactory.servlet_class
- the Class object for the servlet we're
supposed to create. It should implement
the javax.servlet.Servlet interface.servlet_config
- a reference to the ServletConfig -- used
for configuration information and for
looking up some request information.Method Detail |
public void run()
protected void getCounts()
protected javax.servlet.Servlet makeServlet()
protected javax.servlet.Servlet instantiateServlet() throws java.lang.ClassCastException, java.lang.InstantiationException, java.lang.IllegalAccessException
protected void initializeServlet(javax.servlet.Servlet servlet_to_init) throws javax.servlet.ServletException
servlet_to_init
- the servlet that this method should
initialize.public int getMinPoolSize()
public void setMinPoolSize(int new_size)
new_size
- the new minimum size of the pool.public int getMaxPoolSize()
public void setMaxPoolSize(int new_size)
new_size
- the new maximum size of the pool.public int getCurPoolSize()
public void setCurPoolSize(int new_size)
new_size
- the new current size of the pool.public void addServletFactoryListener(ServletFactoryListener listener)
public void removeServletFactoryListener(ServletFactoryListener listener)
public void triggerUnavailability(javax.servlet.ServletException servlet_exception)
servlet_exception
- either a ServletException or an
UnavailableException that contains information about
the unavailability.public void fireServletFactoryEvent(ServletFactoryEvent servlet_factory_event)
public void makeAndFireStatusEvent()
public java.lang.Class getServletClass()
public int getUnavailableSeconds()
public void setUnavailableSeconds(int unavailable_seconds)
setAvailability(ServletFactory.UNAVAILABLE_AND_WAITING)
.public int getAvailability()
servlet_class
.public void setAvailability(int availability)
availability
- The new availability state, should be one
of the following: ServletFactory.AVAILABLE,
ServletFactory.UNAVAILABLE_AND_WAITING,
ServletFactory.PERMANENTLY_UNAVAILABLE,
ServletFactory.SHUTDOWN.
public java.lang.String getUnavailabilityReason()
public void setUnavailabilityReason(java.lang.String reason)
reason
- the text reason to use.public void needMoreServlets()
need_more_servlets
int member
variable, and then notifies the ServletFactory's Thread that the value
has changed. The ServletFactory will then create another servlet,
and then decrement the need_more_servlets
member
variable.public void shutdown()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |