php.java.bridge.http
Class ContextServer

java.lang.Object
  extended by php.java.bridge.http.ContextServer

public final class ContextServer
extends java.lang.Object

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:
SocketContextServer

Field Summary
static java.lang.String ROOT_CONTEXT_SERVER_ATTRIBUTE
          Only for internal use
 
Constructor Summary
ContextServer(java.lang.String contextName, boolean promiscuous)
          Create a new ContextServer using a thread pool.
 
Method Summary
 void destroy()
          Destroy the pipe or socket context server.
 AbstractChannelName getChannelName(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.
 boolean isPromiscuous()
           
 void start(AbstractChannelName channelName, ILogger logger)
          Start a channel name.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ROOT_CONTEXT_SERVER_ATTRIBUTE

public static final java.lang.String ROOT_CONTEXT_SERVER_ATTRIBUTE
Only for internal use

Constructor Detail

ContextServer

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

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

isPromiscuous

public boolean isPromiscuous()
Returns:
true for all network interfaces, false for loopback only

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,
                  ILogger logger)
Start a channel name.

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

getChannelName

public AbstractChannelName getChannelName(IContextFactory currentCtx)
Return the channelName which be passed to the client as X_JAVABRIDGE_REDIRECT

Parameters:
currentCtx - The current ContextFactory, see X_JAVABRIDGE_CONTEXT
Returns:
The channel name of the Pipe- or SocketContextServer.

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object