|
||||||||||
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, ICredentials)
, which checks if the ContextFactory
belongs to the same ContextServer.
ServletContextFactory
,
ContextServer
,
SessionFactory.TIMER_DURATION
Nested Class Summary | |
---|---|
static interface |
ContextFactory.ICredentials
The credentials provided by the web context, usually this ContextFactory. |
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 |
static ContextFactory.ICredentials |
NO_CREDENTIALS
Use this if you don't care about security. |
Fields inherited from class php.java.bridge.SessionFactory |
---|
TIMER_DURATION, TIMER_FREQ |
Constructor Summary | |
---|---|
ContextFactory(java.lang.String webContext)
|
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. |
static IContextFactory |
addNew(java.lang.String webContext)
Create a new ContextFactory 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. |
void |
finishContext()
Called by recycle at the end of the script |
static IContextFactory |
get(java.lang.String id,
ContextFactory.ICredentials server)
Only for internal use. |
java.lang.ClassLoader |
getClassLoader()
Return an instance of the current thread context class loader. |
IContext |
getContext()
Returns the context. |
java.lang.String |
getId()
Return the serializable ID of the context factory |
SimpleJavaBridgeClassLoader |
getJavaBridgeClassLoader()
Return an instance of the JavaBridgeClassLoader |
ISession |
getSession(java.lang.String name,
boolean clientIsNew,
int timeout)
Return a standard session, shared with JSP |
ISession |
getSimpleSession(java.lang.String name,
boolean clientIsNew,
int timeout)
Return a simple session which cannot be shared with JSP |
static IContextFactory |
peek(java.lang.String id)
Only for internal use. |
void |
recycle()
Recycle the factory for new reqests. |
void |
recycle(ContextFactory factory)
|
void |
recycle(java.lang.String id)
Update the context factory with the new JavaBridge obtained from the servlet. |
void |
recycleLegacy(java.lang.String id)
Deprecated. |
static void |
removeAll()
Deprecated. |
void |
removeOrphaned()
Removes the unused context factory from the classloader's list of context factories. |
void |
setClassLoader(java.lang.ClassLoader loader)
Set the class loader obtained from the current servlet into the context. |
void |
setContext(IContext context)
Set the Context into this factory. |
void |
setIsLegacyClient(boolean isLegacyClient)
Will be called by the PhpJavaServlet and by the JavaBridgeRunner when the client is not the pure PHP client. |
java.lang.String |
toString()
|
void |
waitFor()
Wait until this context is finished. |
void |
waitFor(long timeout)
Wait until this context is finished. |
Methods inherited from class php.java.bridge.JavaBridgeFactory |
---|
getBridge |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface php.java.bridge.IJavaBridgeFactory |
---|
getBridge |
Field Detail |
---|
public static final java.lang.String EMPTY_CONTEXT_NAME
public static final ContextFactory.ICredentials NO_CREDENTIALS
SocketContextServer
Constructor Detail |
---|
public ContextFactory(java.lang.String webContext)
Method Detail |
---|
public static IContextFactory addNew(java.lang.String webContext)
webContext
- The current web context, use ContextFactory.EMPTY_CONTEXT
if servlet web contexts are not available, config.getServletContext().getRealPath("") otherwise.
get(String, ICredentials)
public static IContextFactory addNew()
get(String, ICredentials)
public static IContextFactory get(java.lang.String id, ContextFactory.ICredentials server)
id
id
- The IDserver
- Your context server.
java.lang.SecurityException
- if id belongs to a different ContextServer.addNew(String)
public static IContextFactory peek(java.lang.String id)
get(String, php.java.bridge.http.ContextFactory.ICredentials)
with the second argument set to null.
The servlet may use this procedure to check for a new context factory.
id
- The existing id.
java.lang.IllegalStateException
- if the context is in use.public void recycle(ContextFactory factory)
recycle
in interface IContextFactory
public void recycle(java.lang.String id) throws java.lang.SecurityException
IContextFactory
Update the context factory with the new JavaBridge obtained from the servlet.
Since version 4.1.1 both, the C and the pure PHP implementation pass the context factory via a protocol header. This procedure must obtain the factory for id and pass the bridge to the current context factory. Furthermore it must update the currentThreadContextClassLoader. After the request is done, the ContextFactory#recycle() method is called, which must restore the currentThreadContextClassLoader and the old context factory.
recycle
in interface IContextFactory
id
- The fresh id
java.lang.SecurityException
recycle()
,
Request.setBridge(php.java.bridge.JavaBridge)
,
Request.recycle()
public void recycle()
recycle
in class SessionFactory
public void destroy()
SessionFactory
destroy
in interface IContextFactory
destroy
in class SessionFactory
public static void removeAll()
destroyAll()
public static void destroyAll()
ContextServer
public void waitFor() throws java.lang.InterruptedException
IContextFactory
waitFor
in interface IContextFactory
java.lang.InterruptedException
ContextRunner
public void waitFor(long timeout) throws java.lang.InterruptedException
IContextFactory
waitFor
in interface IContextFactory
timeout
- The timeout
java.lang.InterruptedException
ContextRunner
public java.lang.String getId()
IContextFactory
getId
in interface IContextFactory
public java.lang.String toString()
toString
in class java.lang.Object
public IContext getContext()
getContext
in interface IContextFactory
getContext
in class SessionFactory
getContext()
public void setContext(IContext context)
setContext
in interface IContextFactory
context
- The context.addNew(String)
public void accept(IContextFactoryVisitor visitor)
visitor
- The custom ContextFactorypublic ISession getSimpleSession(java.lang.String name, boolean clientIsNew, int timeout)
name
- The session nameclientIsNew
- true, if the client wants a new sessiontimeout
- expires in n secondspublic ISession getSession(java.lang.String name, boolean clientIsNew, int timeout)
getSession
in interface IContextFactory
getSession
in class SessionFactory
name
- The session nameclientIsNew
- true, if the client wants a new sessiontimeout
- expires in n seconds
ISession
public void removeOrphaned()
IContextFactory
removeOrphaned
in interface IContextFactory
public void finishContext()
finishContext
in interface IContextFactory
public void setClassLoader(java.lang.ClassLoader loader)
IContextFactory
setClassLoader
in interface IContextFactory
loader
- The currentThreadContextClassLoaderpublic SimpleJavaBridgeClassLoader getJavaBridgeClassLoader()
JavaBridgeFactory
getJavaBridgeClassLoader
in class SessionFactory
public java.lang.ClassLoader getClassLoader()
JavaBridgeFactory
getClassLoader
in interface IContextFactory
getClassLoader
in class SessionFactory
public void setIsLegacyClient(boolean isLegacyClient)
IContextFactory
setIsLegacyClient
in interface IContextFactory
public void recycleLegacy(java.lang.String id) throws java.lang.SecurityException
recycleLegacy
in interface IContextFactory
java.lang.SecurityException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |