org.apache.jserv
Class JServSTMStore

java.lang.Object
  |
  +--org.apache.jserv.JServSTMStore

class JServSTMStore
extends java.lang.Object
implements JServLogChannels

This class is used to store a set of JServContexts for servlets which implement the javax.servlet.SingleThreadModel interface. It's a kind of pool designed to work with JServServletManager.

Version:
$Revision: 1.10 $ $Date: 1999/11/04 20:19:28 $

Field Summary
private  JServContext[] allContexts
          We need a copy of all the contexts, busy or free.
private  JServContext[] freeContexts
          The array of free contexts.
private  int incrementCapacity
          The increment capacity parameter.
private  int indexAll
          The index in the allContexts array.
private  int indexFree
          The index used in the array of free contexts.
private  int initialCapacity
          The initial capacity of this store
private  int maximumCapacity
          The maximum size of this pool.
private  JServServletManager servletManager
          The Servlet Manager which must create in behalf of us new servlet instances when needed.
private  java.lang.String servletName
          The name (or class name or ...) of the servlet stored here.
 
Constructor Summary
(package private) JServSTMStore(Configurations confs, JServServletManager servletManager, java.lang.String servletName, JServSendError sendError, JServContext firstInstance)
          Constructs a store fill it with contexts.
 
Method Summary
private  void addContext(JServSendError sendError)
          Add a new created context.
(package private)  JServContext[] clear()
          Return all the contexts stored here and clear the content of the pool.
(package private)  JServContext getContext(JServSendError sendError)
          Get a free context (servlet) from the pool.
(package private)  javax.servlet.Servlet[] getServlets()
          Return the servlets stored in this pool.
(package private)  void returnContext(JServContext context)
          Return a free context to the pool after it was used.
(package private)  int size()
          Return the number of total contexts stored in this poll.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

servletManager

private JServServletManager servletManager
The Servlet Manager which must create in behalf of us new servlet instances when needed.

servletName

private java.lang.String servletName
The name (or class name or ...) of the servlet stored here.

freeContexts

private JServContext[] freeContexts
The array of free contexts. We use this array like a stack, where the top of the stack is determined by indexFree.

indexFree

private int indexFree
The index used in the array of free contexts.

allContexts

private JServContext[] allContexts
We need a copy of all the contexts, busy or free. We must provide to the servlet manager the list of all instances in this set. We also need this copy when we check a returned context.

indexAll

private int indexAll
The index in the allContexts array. This index is incremented as new instances are added. It also shows how many instances we have in this pool.

initialCapacity

private int initialCapacity
The initial capacity of this store

incrementCapacity

private int incrementCapacity
The increment capacity parameter. It shows with how many elements to grow the array.

maximumCapacity

private int maximumCapacity
The maximum size of this pool.
Constructor Detail

JServSTMStore

JServSTMStore(Configurations confs,
              JServServletManager servletManager,
              java.lang.String servletName,
              JServSendError sendError,
              JServContext firstInstance)
        throws javax.servlet.ServletException
Constructs a store fill it with contexts.
Parameters:
confs - Configuration parameters for this class
servletManager -  
servletName -  
sendError -  
firstInstance - An already created and inited instance of the servlet
Throws:
javax.servlet.ServletException - if an error occurs.
Method Detail

addContext

private void addContext(JServSendError sendError)
                 throws javax.servlet.ServletException
Add a new created context.
Parameters:
sendError - The sendError handler to report errors.
Throws:
javax.servlet.ServletException - If an error occurs when creating the servlet.

getContext

JServContext getContext(JServSendError sendError)
                  throws javax.servlet.ServletException
Get a free context (servlet) from the pool. If no context is available and we have not reached the maximumCapacity we will first expand the store with new servlets.
Parameters:
sendError - The error handler used to report errors.
Returns:
A free context or null if no free context is available.
Throws:
javax.servlet.ServletException - if an error occurs when we create a new servlet.

returnContext

void returnContext(JServContext context)
Return a free context to the pool after it was used.
Parameters:
context - the context to free

size

int size()
Return the number of total contexts stored in this poll.
Returns:
The total number of contexts stored here.

getServlets

javax.servlet.Servlet[] getServlets()
Return the servlets stored in this pool.
Returns:
An array with all the servlets stored here.

clear

JServContext[] clear()
Return all the contexts stored here and clear the content of the pool.
Returns:
An array with all the contexts stored here.