php.java.bridge.http
Class SimpleContextFactory

java.lang.Object
  extended by php.java.bridge.http.SimpleContextFactory
All Implemented Interfaces:
IContextFactory, IContextFactoryVisitor, IJavaBridgeFactory
Direct Known Subclasses:
PhpScriptContextFactory, SimpleServletContextFactory

public class SimpleContextFactory
extends java.lang.Object
implements IContextFactoryVisitor

Base of a set of visitors which can extend the standard ContextFactory. Instances of this class are thrown away at the end of the request.

See Also:
ServletContextFactory, PhpScriptContextFactory

Method Summary
 void destroy()
          Destroy the factory
 void flushBuffer()
          Flush the response buffer
 JavaBridge getBridge()
          Return the JavaBridge.
 IContext getContext()
          Return a JSR223 context
 java.lang.String getId()
          Return the serializable ID of the context factory
 ISession getSession(java.lang.String name, short clientIsNew, int timeout)
          Return a session for the JavaBridge
 ISession getSimpleSession(java.lang.String name, short clientIsNew, int timeout)
          
 void initialize()
          Called when the context runner starts
 void invalidate()
          Hook is called at the end of the life cycle.
 boolean isNew()
          Return true if this factory has already created a bridge or not.
 void parseHeader(Request req, java.io.InputStream in)
          Called for the request header
 void recycle()
          Called by recycle at the end of the script
 void recycle(java.lang.String id)
           Update the context factory with the new JavaBridge obtained from the servlet
 void release()
          Releases the context factory.
 void releaseManaged()
          Wait for the context factory to finish, then release
 void setContext(IContext context)
          Set the Context into this factory.
 java.lang.String toString()
          
 void visit(IContextFactory visited)
          Called when a visitor has been attached.
 void waitFor(long timeout)
          Wait for the context factory to finish.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

recycle

public void recycle(java.lang.String id)

Update the context factory with the new JavaBridge obtained from the servlet

Specified by:
recycle in interface IContextFactory
Parameters:
id - The fresh id
See Also:
ContextFactory.recycle(), Request.setBridge(php.java.bridge.JavaBridge), Request.recycle()

destroy

public void destroy()
Destroy the factory

Specified by:
destroy in interface IJavaBridgeFactory

invalidate

public void invalidate()
Hook is called at the end of the life cycle. Either from destroy(), recycle() or from destroyOrphaned().

Specified by:
invalidate in interface IJavaBridgeFactory
See Also:
IJavaBridgeFactory.destroy(), IJavaBridgeFactory.recycle()

initialize

public void initialize()
Called when the context runner starts

Specified by:
initialize in interface IContextFactory
See Also:
IContextFactory.releaseManaged(), IJavaBridgeFactory.destroy()

releaseManaged

public void releaseManaged()
                    throws java.lang.InterruptedException
Wait for the context factory to finish, then release

Specified by:
releaseManaged in interface IContextFactory
Throws:
java.lang.InterruptedException
See Also:
ContextRunner

waitFor

public void waitFor(long timeout)
             throws java.lang.InterruptedException
Wait for the context factory to finish.

Specified by:
waitFor in interface IContextFactory
Parameters:
timeout - The timeout
Throws:
java.lang.InterruptedException
See Also:
ContextRunner

getId

public java.lang.String getId()
Return the serializable ID of the context factory

Specified by:
getId in interface IContextFactory
Returns:
The ID

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

getContext

public IContext getContext()
Return a JSR223 context

Specified by:
getContext in interface IContextFactory
Specified by:
getContext in interface IJavaBridgeFactory
Returns:
The context
See Also:
getContext(), Context

isNew

public boolean isNew()
Return true if this factory has already created a bridge or not.

Specified by:
isNew in interface IJavaBridgeFactory
Returns:
true if this factory is new, false otherwise

getBridge

public JavaBridge getBridge()
Return the JavaBridge.

Specified by:
getBridge in interface IJavaBridgeFactory
Returns:
Returns the bridge.

visit

public void visit(IContextFactory visited)
Called when a visitor has been attached.

Specified by:
visit in interface IContextFactoryVisitor
Parameters:
visited - The context factory

getSession

public ISession getSession(java.lang.String name,
                           short clientIsNew,
                           int timeout)
Return a session for the JavaBridge

Specified by:
getSession in interface IContextFactory
Specified by:
getSession in interface IJavaBridgeFactory
Parameters:
name - The session name. If name is null, the name PHPSESSION will be used.
clientIsNew - true if the client wants a new session
timeout - timeout in seconds. If 0 the session does not expire.
Returns:
The session
See Also:
ISession

getSimpleSession

public ISession getSimpleSession(java.lang.String name,
                                 short clientIsNew,
                                 int timeout)

Specified by:
getSimpleSession in interface IContextFactory
Parameters:
name - The session name. If name is null, the name PHPSESSION will be used.
clientIsNew - true if the client wants a new session
timeout - timeout in seconds. If 0 the session does not expire.
Returns:
The session
See Also:
ISession

setContext

public void setContext(IContext context)
Set the Context into this factory. Should be called by Context.addNew() only.

Specified by:
setContext in interface IContextFactory
See Also:
ContextFactory.addNew()

release

public void release()
Releases the context factory. This method should be called when the factory is not needed anymore. Implementations could then remove any unused context factory from the classloader's list of context factories.

Specified by:
release in interface IContextFactory

recycle

public void recycle()
Called by recycle at the end of the script

Specified by:
recycle in interface IJavaBridgeFactory

flushBuffer

public void flushBuffer()
                 throws java.io.IOException
Flush the response buffer

Specified by:
flushBuffer in interface IJavaBridgeFactory
Throws:
java.io.IOException

parseHeader

public void parseHeader(Request req,
                        java.io.InputStream in)
                 throws java.io.IOException
Called for the request header

Specified by:
parseHeader in interface IJavaBridgeFactory
Parameters:
req - the current request
in - the input stream
Throws:
java.io.IOException