Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## php.java.bridge.http
Class ContextFactory

    java.lang.Object
      php.java.bridge.SessionFactory
          php.java.bridge.http.ContextFactory

All Implemented Interfaces:
  IContextFactory

    public final class ContextFactory

extends SessionFactory
implements IContextFactory

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(IContextFactory).

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.

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

See Also:
  `ServletContextFactory`, `ContextServer`, `SessionFactory.TIMER_FREQ`

Field Summary

Fields inherited from class php.java.bridge.SessionFactory
`TIMER_FREQ`

Constructor Summary
`ContextFactory()`

Method Summary
`void` | `accept(IContextFactoryVisitor visitor)` Use this method to attach a visitor to the ContextFactory.
`static IContextFactory` | `addNew()` Create a new ContextFactory and add it to the list of context factories kept by this classloader.
`void` | `destroy()` Removes the context factory from the classloader's list of context factories and destroys its content.
`static void` | `destroyAll()` Remove all context factories from the classloader.
`static IContextFactory` | `get(java.lang.String id, ContextServer server)` Only for internal use.
`JavaBridge` | `getBridge()` Return the JavaBridge.
`java.lang.Object` | `getContext()` Return the associated context
`java.lang.String` | `getId()` Return the serializable ID of the context factory
`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
`void` | `recycle(ContextFactory target)` Typically the visitor implements this method, it should attach itself to the target by calling `target.accept(this)`.
`void` | `recycle(java.lang.String id)` Synchronize the current state with id.
`static void` | `removeAll()` Deprecated.
`void` | `removeOrphaned()` Removes the unused context factory from the classloader's list of context factories.
`void` | `setBridge(JavaBridge bridge)`
`void` | `setContext(java.lang.Object context)` Set the Context into this factory.
`java.lang.String` | `toString()`
`void` | `waitFor()` Wait until this context is finished.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### ContextFactory

    public ContextFactory()

Method Detail

### addNew

    public static IContextFactory addNew()

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

  Returns:
    The created ContextFactory.
  See Also:
    `get(String, ContextServer)`

### get

    public static IContextFactory get(java.lang.String id,
                                      ContextServer server)

  Only for internal use. Returns the context factory associated with the given `id`

  Parameters:
    `id` - The ID
    `server` - Your context server.
  Returns:
    The ContextFactory or null.
  Throws:
    `java.lang.SecurityException` - if id belongs to a different ContextServer.
  See Also:
    `addNew()`

### recycle

    public void recycle(ContextFactory target)

  Description copied from interface: `IContextFactory`
  Typically the visitor implements this method, it should attach itself to the target by calling `target.accept(this)`.

  Specified by:
    `recycle` in interface `IContextFactory`
  Parameters:
    `target` - The persistent ContextFactory.
  See Also:
    `IContextFactory.recycle(String)`, `accept(IContextFactoryVisitor)`, `IContextFactoryVisitor.visit(ContextFactory)`, `SimpleContextFactory`

### recycle

    public void recycle(java.lang.String id)
                 throws java.lang.SecurityException

  Description copied from interface: `IContextFactory`
  Synchronize the current state with id.

  When persistent connections are used, the bridge instances recycle their context factories (persistent php clients store their context id, so that they don't have to aquire a new one). However, a client of a php client may have passed a fresh context id. If this happened, the bridge calls this method, which may update the current context with the fresh values from id.

  Typically the ContextFactory implements this method. It should find the ContextFactory for id, check that the Factory is not in use (and throw a SecurityException, if isInitialized() returns true), remove it by calling removeOrphaned() and call its recycle() method passing it the current ContextFactory.

  Specified by:
    `recycle` in interface `IContextFactory`
  Parameters:
    `id` - The fresh id
  Throws:
    `java.lang.SecurityException` - if the found ContextFactory is initialized.
  See Also:
    `IContextFactory.recycle(ContextFactory)`, `JavaBridge.recycle()`

### destroy

    public void destroy()

  Description copied from interface: `IContextFactory`
  Removes the context factory from the classloader's list of context factories and destroys its content.

  Specified by:
    `destroy` in interface `IContextFactory`

### removeAll

    public static void removeAll()

  Deprecated.

  See Also:
    `destroyAll()`

### destroyAll

    public static void destroyAll()

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

  See Also:
    `ContextServer`

### waitFor

    public void waitFor()
                 throws java.lang.InterruptedException

  Description copied from interface: `IContextFactory`
  Wait until this context is finished.

  Specified by:
    `waitFor` in interface `IContextFactory`
  Throws:
    `java.lang.InterruptedException`
  See Also:
    `ContextRunner`

### getId

    public java.lang.String getId()

  Description copied from interface: `IContextFactory`
  Return the serializable ID of the context factory

  Specified by:
    `getId` in interface `IContextFactory`
  Returns:
    The ID

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

### getContext

    public java.lang.Object getContext()

  Description copied from class: `SessionFactory`
  Return the associated context

  Specified by:
    `getContext` in interface `IContextFactory`
  Overrides:
    `getContext` in class `SessionFactory`
  Returns:
    Always null
  See Also:
    `getContext()`

### setContext

    public void setContext(java.lang.Object context)

  Set the Context into this factory. Should be called by Context.addNew() only.

  Specified by:
    `setContext` in interface `IContextFactory`
  Parameters:
    `context` -
  See Also:
    `addNew()`

### setBridge

    public void setBridge(JavaBridge bridge)

### getBridge

    public JavaBridge getBridge()

  Description copied from interface: `IContextFactory`
  Return the JavaBridge.

  Specified by:
    `getBridge` in interface `IContextFactory`
  Returns:
    Returns the bridge.

### accept

    public void accept(IContextFactoryVisitor visitor)

  Use this method to attach a visitor to the ContextFactory.

  Parameters:
    `visitor` - The custom ContextFactory

### getSimpleSession

    public ISession getSimpleSession(java.lang.String name,
                                     boolean clientIsNew,
                                     int timeout)

  Return a simple session which cannot be shared with JSP

  Parameters:
    `name` - The session name
    `clientIsNew` - true, if the client wants a new session
    `timeout` - expires in n seconds

### getSession

    public ISession getSession(java.lang.String name,
                               boolean clientIsNew,
                               int timeout)

  Return a standard session, shared with JSP

  Specified by:
    `getSession` in interface `IContextFactory`
  Overrides:
    `getSession` in class `SessionFactory`
  Parameters:
    `name` - The session name
    `clientIsNew` - true, if the client wants a new session
    `timeout` - expires in n seconds
  Returns:
    The session
  See Also:
    `ISession`

### removeOrphaned

    public void removeOrphaned()

  Description copied from interface: `IContextFactory`
  Removes the unused context factory from the classloader's list of context factories.

  Specified by:
    `removeOrphaned` in interface `IContextFactory`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD