### php.java.bridge.http

# Class ContextFactory

- `java.lang.Object`

- `php.java.bridge.SessionFactory`

- `php.java.bridge.http.ContextFactory`

Known Direct Subclasses:
  ContextFactory, PhpScriptContextFactory

`public class ContextFactory`
`extends SessionFactory`

Manage session contexts.

The context may a) keep a promise (a "proxy") which one may evaluate to a session reference (for PHP/JSP session sharing), and/or b) it may reference a "half-executed" bridge for local channel re-directs (for "high speed" communication links). Context instances are kept in an array with no more than 65535 entries, after 65535 context creations the context is destroyed if this did not happen explicitly. A unique [1..65535] context instance should be created for each request and destroyed when the request is done. 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 Context is given to a ContextRunner, which handles the local channel communication.

There can be only one instance of a ContextFactory per VM.

See Also:
  `ContextFactory`, `ContextServer`

## Method Summary

`static ContextFactory`

`addNew()`
  Create a new ContextFactory and add it to the list of context factories kept by this VM.

`static ContextFactory`

`get(java.lang.String id)`
  Returns the context factory associated with the given `id`

`JavaBridge`

`getBridge()`

`java.lang.Object`

`getContext()`
  Return the associated context

`java.lang.String`

`getId()`
  Return the serializable ID of the context manager

`void`

`remove()`
  Removes the context factory from the VM list of context factories.

`static void`

`removeAll()`
  Remove all context factories from the VM.

`void`

`setBridge(JavaBridge bridge)`
  Set the JavaBridge into this context.

`java.lang.String`

`toString()`
  Convert this Object to a human-readable String.

`void`

`waitFor()`
  Wait until this context is finished.

### Methods inherited from class php.java.bridge.SessionFactory

`getContext`, `getSession`

### Methods inherited from class java.lang.Object

`equals`, `getClass`, `hashCode`, `notify`, `notifyAll`, `toString`, `wait`, `wait`, `wait`

## Method Details

### addNew

    public static ContextFactory addNew()

> Create a new ContextFactory and add it to the list of context factories kept by this VM.

> Returns:
>   The created ContextFactory.

### get

    public static ContextFactory get(java.lang.String id)

> Returns the context factory associated with the given `id`

> Parameters:
>   `id` - The ID

> Returns:
>   The ContextFactory or null.

### getBridge

    public JavaBridge getBridge()

> Returns:
>   Returns the bridge.

### getContext

    public java.lang.Object getContext()

> Return the associated context
> Overrides:
>   getContext in interface SessionFactory

> Returns:
>   The context

### getId

    public java.lang.String getId()

> Return the serializable ID of the context manager

> Returns:
>   The ID

### remove

    public void remove()

> Removes the context factory from the VM list of context factories.

### removeAll

    public static void removeAll()

> Remove all context factories from the VM. May only be called by the ContextServer.

> See Also:
>   `ContextServer`

### setBridge

    public void setBridge(JavaBridge bridge)

> Set the JavaBridge into this context.

> Parameters:
>   `bridge` - The bridge to set.

### toString

    public java.lang.String toString()

> Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into `System.out.println()` and such.

> It is typical, but not required, to ensure that this method never completes abruptly with a `RuntimeException`.

> This method will be called when performing string concatenation with this object. If the result is `null`, string concatenation will instead use `"null"`.

> The default implementation returns `getClass().getName() + "@" + Integer.toHexString(hashCode())`.
> Overrides:
>   toString in interface java.lang.Object

> Returns:
>   the String representing this Object, which may be null

> See Also:
>   `getClass()`, `hashCode()`, `Class.getName()`, `Integer.toHexString(int)`

### waitFor

    public void waitFor()
                throws java.lang.InterruptedException

> Wait until this context is finished.

> Throws:
>   `java.lang.InterruptedException` -

> See Also:
>   `php.java.bridge.http.ContextRunner`