Package org.apache.jasper.compiler
Class JspRuntimeContext
- java.lang.Object
-
- org.apache.jasper.compiler.JspRuntimeContext
-
- All Implemented Interfaces:
java.lang.Runnable
public final class JspRuntimeContext extends java.lang.Object implements java.lang.RunnableClass for tracking JSP compile time file dependencies when the &060;%@include file="..."%&062; directive is used. A background thread periodically checks the files a JSP page is dependent upon. If a dpendent file changes the JSP page which included it is recompiled. Only used if a web application context is a directory.- Version:
- $Revision: 1.13 $
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.Long>bytecodeBirthTimesprivate java.util.Map<java.lang.String,byte[]>bytecodesMaps class names to in-memory bytecodesprivate java.lang.Stringclasspathprivate java.security.CodeSourcecodeSourceprivate javax.servlet.ServletContextcontextThis web applications ServletContextprivate java.util.concurrent.atomic.AtomicIntegerjspReloadCountprivate java.util.Map<java.lang.String,JspServletWrapper>jspsMaps JSP pages to their JspServletWrapper'sprivate static java.util.logging.Loggerlogprivate Optionsoptionsprivate java.util.Map<java.lang.String,java.util.Map<java.lang.String,javax.tools.JavaFileObject>>packageMapMaps classes in packages compiled by the JSP compiler.private java.security.PermissionCollectionpermissionCollectionprivate java.lang.ThreadthreadThe background thread.private booleanthreadDoneThe background thread completion semaphore.private java.lang.StringthreadNameName to register for the background thread.
-
Constructor Summary
Constructors Constructor Description JspRuntimeContext(javax.servlet.ServletContext context, Options options)Create a JspRuntimeContext for a web application context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddWrapper(java.lang.String jspUri, JspServletWrapper jsw)Add a new JspServletWrapper.voidadjustBytecodeTime(java.lang.String name, long reference)private voidcheckCompile()Method used by background thread to check the JSP dependencies registered with this class for JSP's.voiddestroy()Process a "destory" event for this web application context.byte[]getBytecode(java.lang.String name)Retrieve the bytecode associated with the classlonggetBytecodeBirthTime(java.lang.String name)Retrieve the time the bytecode for a class was createdjava.util.Map<java.lang.String,byte[]>getBytecodes()Get the class-name to bytecode mapjava.lang.StringgetClassPath()The classpath that is passed off to the Java compiler.java.security.CodeSourcegetCodeSource()Get the SecurityManager Policy CodeSource for this web applicaiton context.intgetJspCount()Returns the number of JSPs for which JspServletWrappers exist, i.e., the number of JSPs that have been loaded into the webapp.intgetJspReloadCount()Gets the current value of the JSP reload counter.java.util.Map<java.lang.String,java.util.Map<java.lang.String,javax.tools.JavaFileObject>>getPackageMap()The packageMap keeps track of the bytecode files in a package generated by a java compiler.java.lang.ClassLoadergetParentClassLoader()Get the parent class loader.java.security.PermissionCollectiongetPermissionCollection()Get the SecurityManager PermissionCollection for this web application context.JspServletWrappergetWrapper(java.lang.String jspUri)Get an already existing JspServletWrapper.voidincrementJspReloadCount()Increments the JSP reload counter.private voidinitClassPath()Method used to initialize classpath for compiles.private voidinitSecurity()Method used to initialize SecurityManager data.voidremoveWrapper(java.lang.String jspUri)Remove a JspServletWrapper.voidrun()The background thread that checks for changes to files included by a JSP and flags that a recompile is required.voidsaveBytecode(java.lang.String className, java.lang.String classFileName)Save the bytecode for a class to disk.voidsetBytecode(java.lang.String name, byte[] bytecode)Save the bytecode for the class in a map.voidsetJspReloadCount(int count)Resets the JSP reload counter.protected voidthreadSleep()Sleep for the duration specified by thecheckIntervalproperty.protected voidthreadStart()Start the background thread that will periodically check for changes to compile time included files in a JSP.protected voidthreadStop()Stop the background thread that is periodically checking for changes to compile time included files in a JSP.
-
-
-
Field Detail
-
log
private static java.util.logging.Logger log
-
jspReloadCount
private java.util.concurrent.atomic.AtomicInteger jspReloadCount
-
context
private javax.servlet.ServletContext context
This web applications ServletContext
-
options
private Options options
-
permissionCollection
private java.security.PermissionCollection permissionCollection
-
codeSource
private java.security.CodeSource codeSource
-
classpath
private java.lang.String classpath
-
jsps
private java.util.Map<java.lang.String,JspServletWrapper> jsps
Maps JSP pages to their JspServletWrapper's
-
bytecodes
private java.util.Map<java.lang.String,byte[]> bytecodes
Maps class names to in-memory bytecodes
-
bytecodeBirthTimes
private java.util.Map<java.lang.String,java.lang.Long> bytecodeBirthTimes
-
packageMap
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,javax.tools.JavaFileObject>> packageMap
Maps classes in packages compiled by the JSP compiler. Used only by Jsr199Compiler.
-
thread
private java.lang.Thread thread
The background thread.
-
threadDone
private boolean threadDone
The background thread completion semaphore.
-
threadName
private java.lang.String threadName
Name to register for the background thread.
-
-
Constructor Detail
-
JspRuntimeContext
public JspRuntimeContext(javax.servlet.ServletContext context, Options options)Create a JspRuntimeContext for a web application context. Loads in any previously generated dependencies from file.- Parameters:
context- ServletContext for web application
-
-
Method Detail
-
addWrapper
public void addWrapper(java.lang.String jspUri, JspServletWrapper jsw)Add a new JspServletWrapper.- Parameters:
jspUri- JSP URIjsw- Servlet wrapper for JSP
-
getWrapper
public JspServletWrapper getWrapper(java.lang.String jspUri)
Get an already existing JspServletWrapper.- Parameters:
jspUri- JSP URI- Returns:
- JspServletWrapper for JSP
-
removeWrapper
public void removeWrapper(java.lang.String jspUri)
Remove a JspServletWrapper.- Parameters:
jspUri- JSP URI of JspServletWrapper to remove
-
getJspCount
public int getJspCount()
Returns the number of JSPs for which JspServletWrappers exist, i.e., the number of JSPs that have been loaded into the webapp.- Returns:
- The number of JSPs that have been loaded into the webapp
-
getCodeSource
public java.security.CodeSource getCodeSource()
Get the SecurityManager Policy CodeSource for this web applicaiton context.- Returns:
- CodeSource for JSP
-
getParentClassLoader
public java.lang.ClassLoader getParentClassLoader()
Get the parent class loader.- Returns:
- ClassLoader parent
-
getPermissionCollection
public java.security.PermissionCollection getPermissionCollection()
Get the SecurityManager PermissionCollection for this web application context.- Returns:
- PermissionCollection permissions
-
destroy
public void destroy()
Process a "destory" event for this web application context.
-
incrementJspReloadCount
public void incrementJspReloadCount()
Increments the JSP reload counter.
-
setJspReloadCount
public void setJspReloadCount(int count)
Resets the JSP reload counter.- Parameters:
count- Value to which to reset the JSP reload counter
-
getJspReloadCount
public int getJspReloadCount()
Gets the current value of the JSP reload counter.- Returns:
- The current value of the JSP reload counter
-
setBytecode
public void setBytecode(java.lang.String name, byte[] bytecode)Save the bytecode for the class in a map. The current time is noted.- Parameters:
name- The name of the classbytecode- The bytecode in byte array
-
adjustBytecodeTime
public void adjustBytecodeTime(java.lang.String name, long reference)
-
getBytecodes
public java.util.Map<java.lang.String,byte[]> getBytecodes()
Get the class-name to bytecode map
-
getBytecode
public byte[] getBytecode(java.lang.String name)
Retrieve the bytecode associated with the class
-
getBytecodeBirthTime
public long getBytecodeBirthTime(java.lang.String name)
Retrieve the time the bytecode for a class was created
-
getPackageMap
public java.util.Map<java.lang.String,java.util.Map<java.lang.String,javax.tools.JavaFileObject>> getPackageMap()
The packageMap keeps track of the bytecode files in a package generated by a java compiler. This is in turn loaded by the java compiler during compilation. This is gets around the fact that JSR199 API does not provide a way for the compiler use current classloader.
-
saveBytecode
public void saveBytecode(java.lang.String className, java.lang.String classFileName)Save the bytecode for a class to disk.
-
checkCompile
private void checkCompile()
Method used by background thread to check the JSP dependencies registered with this class for JSP's.
-
getClassPath
public java.lang.String getClassPath()
The classpath that is passed off to the Java compiler.
-
initClassPath
private void initClassPath()
Method used to initialize classpath for compiles.
-
initSecurity
private void initSecurity()
Method used to initialize SecurityManager data.
-
threadStart
protected void threadStart()
Start the background thread that will periodically check for changes to compile time included files in a JSP.- Throws:
java.lang.IllegalStateException- if we should not be starting a background thread now
-
threadStop
protected void threadStop()
Stop the background thread that is periodically checking for changes to compile time included files in a JSP.
-
threadSleep
protected void threadSleep()
Sleep for the duration specified by thecheckIntervalproperty.
-
run
public void run()
The background thread that checks for changes to files included by a JSP and flags that a recompile is required.- Specified by:
runin interfacejava.lang.Runnable
-
-