php.java.servlet
Class ContextLoaderListener

java.lang.Object
  extended by php.java.servlet.ContextLoaderListener
All Implemented Interfaces:
java.util.EventListener, javax.servlet.ServletContextListener, IFCGIProcessFactory

public class ContextLoaderListener
extends java.lang.Object
implements javax.servlet.ServletContextListener, IFCGIProcessFactory

Register the PHP/Java Bridge when the web context starts. Used by java_context()->onShutdown(proc). The WEB-INF/web.xml contains a listener attribute:

<listener>   <listener-class>php.java.servlet.ContextLoaderListener</listener-class> </listener>


Field Summary
static java.lang.String CGI_DIR
           
static java.lang.String CONTEXT_LOADER_LISTENER
          The key used to store the ContextLoaderListener in the servlet context
static java.lang.String PEAR_DIR
           
static java.lang.String WEB_INF_DIR
           
 
Constructor Summary
ContextLoaderListener()
           
 
Method Summary
 boolean canStartFCGI()
          Used for debugging only.
 void contextDestroyed(javax.servlet.ServletContextEvent event)
          
 void contextInitialized(javax.servlet.ServletContextEvent event)
          
 IFCGIProcess createFCGIProcess(java.lang.String[] args, boolean includeJava, java.io.File home, java.util.Map env)
          Create a FastCGI Process
 void destroyCloseables(javax.servlet.ServletContext ctx)
          Only for internal use
 java.lang.String getCgiDir()
          The full path to the pear dir.
 FCGIConnectionFactory getChannelName()
           
 java.util.List getCloseables()
           
 FCGIConnectionPool getConnectionPool()
           
static ContextLoaderListener getContextLoaderListener(javax.servlet.ServletContext ctx)
           
 ContextServer getContextServer()
           
 java.util.HashMap getEnvironment()
          Get the process environment map used for PHP.
 ILogger getLogger()
           
 java.lang.String getPearDir()
          The full path to the pear dir.
 java.lang.String getPhp()
          Get the path to the PHP binary.
 java.lang.String getPhpConnectionPoolSize()
          Get the connection pool size, usually FCGIUtil#PHP_FCGI_CONNECTION_POOL_SIZE
 boolean getPhpIncludeJava()
          Get the value of the php_include_java option from the WEB-INF/web.xml.
 java.lang.String getPhpMaxRequests()
          Get the max requests value, usually FCGIUtil.PHP_FCGI_MAX_REQUESTS
 ThreadPool getThreadPool()
           
 java.lang.String getWebInfDir()
          The full path to the web-inf dir.
 void log(java.lang.String msg)
          Log message through preferred log mechanism, for example servlet.log()
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PEAR_DIR

public static final java.lang.String PEAR_DIR
See Also:
Constant Field Values

CGI_DIR

public static final java.lang.String CGI_DIR
See Also:
Constant Field Values

WEB_INF_DIR

public static final java.lang.String WEB_INF_DIR
See Also:
Constant Field Values

CONTEXT_LOADER_LISTENER

public static final java.lang.String CONTEXT_LOADER_LISTENER
The key used to store the ContextLoaderListener in the servlet context

Constructor Detail

ContextLoaderListener

public ContextLoaderListener()
Method Detail

destroyCloseables

public void destroyCloseables(javax.servlet.ServletContext ctx)
Only for internal use

Parameters:
ctx - The servlet context

contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent event)

Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent event)

Specified by:
contextInitialized in interface javax.servlet.ServletContextListener

getThreadPool

public ThreadPool getThreadPool()

getContextServer

public ContextServer getContextServer()

getLogger

public ILogger getLogger()

getChannelName

public FCGIConnectionFactory getChannelName()

getCloseables

public java.util.List getCloseables()

getConnectionPool

public FCGIConnectionPool getConnectionPool()

getContextLoaderListener

public static ContextLoaderListener getContextLoaderListener(javax.servlet.ServletContext ctx)

createFCGIProcess

public IFCGIProcess createFCGIProcess(java.lang.String[] args,
                                      boolean includeJava,
                                      java.io.File home,
                                      java.util.Map env)
                               throws java.io.IOException
Create a FastCGI Process

Specified by:
createFCGIProcess in interface IFCGIProcessFactory
Parameters:
args - The PHP arguments
includeJava - automatically include Java.inc in each script
home - The PHP home dir or null
env - The process environment
Returns:
a FastCGI process object
Throws:
java.io.IOException

getPhpConnectionPoolSize

public java.lang.String getPhpConnectionPoolSize()
Get the connection pool size, usually FCGIUtil#PHP_FCGI_CONNECTION_POOL_SIZE

Specified by:
getPhpConnectionPoolSize in interface IFCGIProcessFactory
Returns:
The connection pool size

getPhpMaxRequests

public java.lang.String getPhpMaxRequests()
Get the max requests value, usually FCGIUtil.PHP_FCGI_MAX_REQUESTS

Specified by:
getPhpMaxRequests in interface IFCGIProcessFactory
Returns:
The connection pool size

getPhp

public java.lang.String getPhp()
Get the path to the PHP binary. For example "/usr/bin/php-cgi".

Specified by:
getPhp in interface IFCGIProcessFactory
Returns:
The path or the name of the PHP FastCGI binary or null (defaults to php-cgi or php-cgi.exe on the PATH)

getPhpIncludeJava

public boolean getPhpIncludeJava()
Get the value of the php_include_java option from the WEB-INF/web.xml. Should return true in most cases.

Specified by:
getPhpIncludeJava in interface IFCGIProcessFactory
Returns:
the php_include_java option

getEnvironment

public java.util.HashMap getEnvironment()
Get the process environment map used for PHP.

Specified by:
getEnvironment in interface IFCGIProcessFactory
Returns:
the process environment.

canStartFCGI

public boolean canStartFCGI()
Used for debugging only. Should always return true.

Specified by:
canStartFCGI in interface IFCGIProcessFactory
Returns:
true

getCgiDir

public java.lang.String getCgiDir()
The full path to the pear dir. Defaults to WEB-INF/cgi. Use TMPDIR for a standalone runner.

Specified by:
getCgiDir in interface IFCGIProcessFactory
Returns:
the full path to the cgi dir

getPearDir

public java.lang.String getPearDir()
The full path to the pear dir. Defaults to WEB-INF/pear. Use TMPDIR for a standalone runner.

Specified by:
getPearDir in interface IFCGIProcessFactory
Returns:
the full path to the pear dir

getWebInfDir

public java.lang.String getWebInfDir()
The full path to the web-inf dir. Defaults to WEB-INF. Use TMPDIR for a standalone runner.

Specified by:
getWebInfDir in interface IFCGIProcessFactory
Returns:
the full path to the WEB-INF dir

log

public void log(java.lang.String msg)
Log message through preferred log mechanism, for example servlet.log()

Specified by:
log in interface IFCGIProcessFactory
Parameters:
msg - The message to log