|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectphp.java.bridge.JavaBridgeFactory
php.java.bridge.SessionFactory
php.java.bridge.http.ContextFactory
public final class ContextFactory
Create session, jsr223 contexts.
The ContextFactory may keep a promise (a "proxy") which one may evaluate to a session reference (for PHP/JSP session sharing), and/or it may reference a "half-executed" bridge for local channel re-directs (for "high speed" communication links).
A unique context instance should be created for each request and destroyed when the request is done.
Clients of the PHP clients may attach additional data and run with
a customized ContextFactory by using the visitor pattern,
see accept(IContextFactoryVisitor).
The string ID of the instance should be passed to the client, which may pass it back together with the getSession request or the "local channel re-direct". If the former happens, we invoke the promise and return the session object to the client. Different promises can evaluate to the same session object. For local channel re-directs the ContextFactory is given to a ContextRunner which handles the local channel communication.
When a php client is not interested in a context for 5 seconds (checked every 10 minutes), the context is destroyed: a) switching from the HTTP tunnel to the local channel of the ContextRunner or b) switching from the fresh context created by the client of the PHP client to the recycled, persistent context, costs only one round-trip. The time for such a context switch is usually much less than 10ms unless either the php client or the client that waits for the php client is traced. If 5 seconds is not enough during debugging, change the ORPHANED_TIMEOUT.
In a shared environment with k web contexts there can be up to n*k active JavaBridge/ContextFactory instances
(where n is the number of active php clients). All ContextFactories are kept in a shared, per-loader
map. But the map can only be accessed via get(String), which checks if the ContextFactory
belongs to the same ContextServer.
ServletContextFactory,
ContextServer,
SessionFactory.TIMER_DURATION| Field Summary | |
|---|---|
static java.lang.String |
EMPTY_CONTEXT_NAME
This context name can be used when a ContextFactory is used outside of a servlet environment |
| Fields inherited from class php.java.bridge.SessionFactory |
|---|
TIMER_DURATION |
| Constructor Summary | |
|---|---|
ContextFactory(java.lang.String webContext,
boolean isManaged)
Create a new ContextFactory. |
|
| Method Summary | |
|---|---|
void |
accept(IContextFactoryVisitor visitor)
Use this method to attach a visitor to the ContextFactory. |
static IContextFactory |
addNew()
Create a new simple ContextFactory (a factory which creates an emulated JSR223 context) and add it to the list of context factories kept by this classloader. |
void |
destroy()
Destroy the factory |
static void |
destroyAll()
Remove all context factories from the classloader. |
static IContextFactory |
get(java.lang.String id)
Only for internal use. |
IContext |
getContext()
Returns the 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 standard session, shared with JSP |
ISession |
getSimpleSession(java.lang.String name,
short clientIsNew,
int timeout)
Return a simple session which cannot be shared with JSP |
void |
initialize()
Called when the context runner starts |
void |
invalidate()
Hook is called at the end of the life cycle. |
void |
parseHeader(Request req,
java.io.InputStream in)
Called for the request header |
void |
recycle()
Called before destroy() |
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 until this context is finished and release/destroy it. |
void |
setContext(IContext context)
Set the Context into this factory. |
java.lang.String |
toString()
|
void |
waitFor(long timeout)
Wait until this context is finished. |
| Methods inherited from class php.java.bridge.SessionFactory |
|---|
destroyTimer, flushBuffer |
| Methods inherited from class php.java.bridge.JavaBridgeFactory |
|---|
getBridge, isNew |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface php.java.bridge.IJavaBridgeFactory |
|---|
flushBuffer, getBridge, isNew |
| Field Detail |
|---|
public static final java.lang.String EMPTY_CONTEXT_NAME
| Constructor Detail |
|---|
public ContextFactory(java.lang.String webContext,
boolean isManaged)
webContext - The current web context or "@"isManaged - true if the factory should NOT be gc'ed after MAX_TIMEOUT| Method Detail |
|---|
public static IContextFactory addNew()
get(String)public static IContextFactory get(java.lang.String id)
id
id - The ID
java.lang.SecurityException - if id belongs to a different ContextServer.addNew()public void recycle(java.lang.String id)
Update the context factory with the new JavaBridge obtained from the servlet
recycle in interface IContextFactoryid - The fresh idrecycle(),
Request.setBridge(php.java.bridge.JavaBridge),
Request.recycle()public void recycle()
recycle in interface IJavaBridgeFactoryrecycle in class JavaBridgeFactorypublic void destroy()
destroy in interface IJavaBridgeFactorydestroy in class JavaBridgeFactorypublic static void destroyAll()
ContextServer
public void releaseManaged()
throws java.lang.InterruptedException
releaseManaged in interface IContextFactoryjava.lang.InterruptedExceptionContextRunner
public void waitFor(long timeout)
throws java.lang.InterruptedException
waitFor in interface IContextFactorytimeout - The timeout
java.lang.InterruptedExceptionContextRunnerpublic java.lang.String getId()
getId in interface IContextFactorypublic java.lang.String toString()
toString in class java.lang.Objectpublic IContext getContext()
getContext in interface IContextFactorygetContext in interface IJavaBridgeFactorygetContext in class SessionFactorygetContext()public void setContext(IContext context)
setContext in interface IContextFactorycontext - The context.addNew()public void accept(IContextFactoryVisitor visitor)
visitor - The custom ContextFactory
public ISession getSimpleSession(java.lang.String name,
short clientIsNew,
int timeout)
getSimpleSession in interface IContextFactoryname - The session nameclientIsNew - true, if the client wants a new sessiontimeout - expires in n seconds
ISession
public ISession getSession(java.lang.String name,
short clientIsNew,
int timeout)
getSession in interface IContextFactorygetSession in interface IJavaBridgeFactorygetSession in class SessionFactoryname - The session nameclientIsNew - true, if the client wants a new sessiontimeout - expires in n seconds
ISessionpublic void release()
release in interface IContextFactorypublic void initialize()
initialize in interface IContextFactoryIContextFactory.releaseManaged(),
IJavaBridgeFactory.destroy()public void invalidate()
invalidate in interface IJavaBridgeFactoryinvalidate in class SessionFactoryIJavaBridgeFactory.destroy(),
IJavaBridgeFactory.recycle()
public void parseHeader(Request req,
java.io.InputStream in)
throws java.io.IOException
parseHeader in interface IJavaBridgeFactoryparseHeader in class JavaBridgeFactoryreq - the current requestin - the input stream
java.io.IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||