php.java.bridge.http
Class ContextServer

java.lang.Object
  extended by php.java.bridge.http.ContextServer
All Implemented Interfaces:
ContextFactory.ICredentials

public final class ContextServer
extends java.lang.Object
implements ContextFactory.ICredentials

A bridge pattern which either uses the PipeContextServer or the SocketContextServer, depending on the OS and/or the security restrictions. On windows, which cannot use named pipes, a SocketContextServer is used. All other operating systems use a PipeContextServer unless the system property php.java.bridge.promiscuous is set to true or the system property php.java.bridge.no_pipe_server is set to true.

A ContextServer instance represents the current web context. When the PipeContextServer is used, there can be more than one PipeContextServer instance per classloader, the ContextFactory.get() checks if it is called with the same ContextServer and throws a SecurityException otherwise. So one cannot access contexts belonging to other web contexts.

The SocketContextServer uses only one server socket for all shared web contexts and cannot do any security checks.

Author:
jostb
See Also:
PipeContextServer, SocketContextServer

Constructor Summary
ContextServer(java.lang.String contextName)
          Create a new ContextServer using a thread pool.
 
Method Summary
 void destroy()
          Destroy the pipe or socket context server.
 ContextFactory.ICredentials getCredentials(java.lang.String channelName, java.lang.String kontext)
          Return the credentials provided by the ContextServer.
 AbstractChannelName getFallbackChannelName(java.lang.String channelName, java.lang.String kontext, IContextFactory currentCtx)
          Return the channelName which be passed to the client as X_JAVABRIDGE_REDIRECT
 boolean isAvailable(java.lang.String channelName)
          Check if either the pipe of the socket context server is available.
 ContextRunner schedule(AbstractChannelName channelName)
          Check for a ContextRunner for channelName
 void start(AbstractChannelName channelName)
          Start a channel name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextServer

public ContextServer(java.lang.String contextName)
Create a new ContextServer using a thread pool.

Parameters:
contextName - The the name of the web context to which this server belongs.
Method Detail

destroy

public void destroy()
Destroy the pipe or socket context server.


isAvailable

public boolean isAvailable(java.lang.String channelName)
Check if either the pipe of the socket context server is available. This function may try start a SocketContextServer, if a PipeContextServer is not available.

Parameters:
channelName - The header value for X_JAVABRIDGE_CHANNEL, may be null.
Returns:
true if either the pipe or the socket context server is available.

start

public void start(AbstractChannelName channelName)
Start a channel name.

Parameters:
channelName - The ChannelName.
Throws:
java.lang.IllegalStateException - if there's no Pipe- or SocketContextServer available

schedule

public ContextRunner schedule(AbstractChannelName channelName)
Check for a ContextRunner for channelName

Parameters:
channelName - The ChannelName
Returns:
The ContextRunner or null. BOGUS: This could be removed if we modify the C code to always pass the header.

getFallbackChannelName

public AbstractChannelName getFallbackChannelName(java.lang.String channelName,
                                                  java.lang.String kontext,
                                                  IContextFactory currentCtx)
Return the channelName which be passed to the client as X_JAVABRIDGE_REDIRECT

Parameters:
channelName - The name of the channel, see X_JAVABRIDGE_CHANNEL
kontext - The name of the client's default ContextFactory, see X_JAVABRIDGE_CONTEXT_DEFAULT
currentCtx - The current ContextFactory, see X_JAVABRIDGE_CONTEXT
Returns:
The channel name of the Pipe- or SocketContextServer.

getCredentials

public ContextFactory.ICredentials getCredentials(java.lang.String channelName,
                                                  java.lang.String kontext)
Return the credentials provided by the ContextServer. The SocketContextServer is insecure and cannot provide any, because there's only one SocketContextServer instance for all shared web contexts. The PipeContextServer returns a token which will be used in ContextFactory.get() to check if the web context is allowed to access this contextFactory instance or not.

Parameters:
channelName - The name of the channel, see X_JAVABRIDGE_CHANNEL
kontext - The name of the client's default ContextFactory, see X_JAVABRIDGE_CONTEXT_DEFAULT
Returns:
A security token.