|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.enterprise.web.connector.grizzly.comet.CometEngine
public final class CometEngine
Main class allowing Comet support on top of Grizzly Asynchronous Request Processing mechanism. This class is the entry point to any component interested to execute Comet request style. Components can be Servlets, JSP, JSF or pure Java class. A component interested to support Comet request must do:
(1) First, register the topic on which Comet support will be applied:
CometEngine cometEngine = CometEngine.getEngine()
CometContext cometContext = cometEngine.register(topic)
(2) Second, add an instance of CometHandler to the
CometContext returned by the register method:
CometContext.addCometHandler(com.sun.enterprise.web.connector.grizzly.comet.CometHandler, boolean). Executing this operation
will tells Grizzly to suspend the response.
(3) Finally, you can CometContext.notify(E) other CometHandler
to share information between . When notified,
CometHandler can decides to push back the data, resume the
response, or simply ignore the content of the notification.
You can also select the stage where the suspension of the response happens when
registering the CometContext's topic (see register(java.lang.String)), which can be
before, during or after invoking a Servlet
| Field Summary | |
|---|---|
protected ConcurrentHashMap<String,CometContext> |
activeContexts
The current active CometContext keyed by context path. |
static int |
AFTER_RESPONSE_PROCESSING
The token used to support BEFORE_RESPONSE_PROCESSING polling. |
static int |
AFTER_SERVLET_PROCESSING
The token used to support AFTER_SERVLET_PROCESSING polling. |
static int |
BEFORE_REQUEST_PROCESSING
The token used to support BEFORE_REQUEST_PROCESSING polling. |
protected Queue<CometContext> |
cometContexts
Cache of CometContext instance. |
protected CometSelector |
cometSelector
The CometSelector used to poll requests. |
protected Queue<CometTask> |
cometTasks
Cache of CometTask instance |
static int |
DISABLE_CLIENT_DISCONNECTION_DETECTION
|
static int |
DISABLE_SUSPEND_TIMEOUT
|
protected static String |
notificationHandlerClassName
The default class to use when deciding which NotificationHandler to use. |
protected Pipeline |
pipeline
The Pipeline used to execute CometTask |
protected ConcurrentHashMap<Long,SelectionKey> |
threadsId
Temporary repository that associate a Thread ID with a Key. |
protected ConcurrentHashMap<Long,CometContext> |
updatedCometContexts
Store modified CometContext. |
| Constructor Summary | |
|---|---|
protected |
CometEngine()
Create a singleton and initialize all lists required. |
| Method Summary | |
|---|---|
protected SelectionKey |
activateContinuation(Long threadId,
CometContext cometContext,
boolean continueExecution)
Tell the CometEngine to activate Grizzly ARP on that CometContext. |
CometContext |
getCometContext(String topic)
Return the CometContext associated with the topic. |
static CometEngine |
getEngine()
Return a singleton of this Class. |
static String |
getNotificationHandlerClassName()
Return the default NotificationHandler class name. |
Pipeline |
getPipeline()
|
protected boolean |
handle(AsyncProcessorTask apt)
Handle an interrupted(or polled) request by matching the current context path with the registered one. |
protected void |
interrupt(CometTask cometTask)
|
protected void |
interrupt(SelectionKey key)
The CometSelector is expiring idle SelectionKey,
hence we need to resume the current request. |
protected static NotificationHandler |
loadNotificationHandlerInstance(String className)
Util to load classes using reflection. |
static Logger |
logger()
Return the current logger. |
CometContext |
register(String topic)
Register a context path with this CometEngine. |
CometContext |
register(String topic,
int type)
Register a context path with this CometEngine. |
CometContext |
register(String topic,
int type,
Class<? extends CometContext> contextclass)
Instanciate a new CometContext. |
protected void |
resume(SelectionKey key)
Resume the long polling request by unblocking the current SelectionKey |
protected void |
returnTask(CometTask cometTask)
Return a Task to the pool. |
static void |
setNotificationHandlerClassName(String aNotificationHandlerClassName)
Set the default NotificationHandler class name. |
void |
setPipeline(Pipeline pipeline)
|
CometContext |
unregister(String topic)
Unregister the CometHandler to the list of the
CometContext. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DISABLE_SUSPEND_TIMEOUT
public static final int DISABLE_CLIENT_DISCONNECTION_DETECTION
public static final int BEFORE_REQUEST_PROCESSING
public static final int AFTER_SERVLET_PROCESSING
public static final int AFTER_RESPONSE_PROCESSING
protected volatile Pipeline pipeline
Pipeline used to execute CometTask
protected ConcurrentHashMap<String,CometContext> activeContexts
CometContext keyed by context path.
protected Queue<CometTask> cometTasks
CometTask instance
protected Queue<CometContext> cometContexts
CometContext instance.
protected CometSelector cometSelector
CometSelector used to poll requests.
protected static String notificationHandlerClassName
protected ConcurrentHashMap<Long,SelectionKey> threadsId
protected ConcurrentHashMap<Long,CometContext> updatedCometContexts
| Constructor Detail |
|---|
protected CometEngine()
CometSelector
| Method Detail |
|---|
public static CometEngine getEngine()
public CometContext unregister(String topic)
CometHandler to the list of the
CometContext. Invoking this method will invoke all
CometHandler.onTerminate(com.sun.enterprise.web.connector.grizzly.comet.CometEvent) before
removing the associated CometContext. Invoking that method
will also resume the underlying connection associated with the
CometHandler, similar to what
CometContext.resumeCometHandler(com.sun.enterprise.web.connector.grizzly.comet.CometHandler)
do.
public CometContext register(String topic)
CometEngine. The
CometContext returned will be of type
AFTER_SERVLET_PROCESSING, which means the request target (most probably
a Servlet) will be executed first and then polled.
topic - the context path used to create the
CometContext
CometContext.
public CometContext register(String topic,
int type)
CometEngine. The
CometContext returned will be of type
type.
topic - the context path used to create the
CometContexttype - when the request will be suspended, e.g. BEFORE_REQUEST_PROCESSING,
AFTER_SERVLET_PROCESSING or AFTER_RESPONSE_PROCESSING
CometContext.
public CometContext register(String topic,
int type,
Class<? extends CometContext> contextclass)
CometContext.
topic - the topic the new CometContext will represent.type - when the request will be suspended, e.g. BEFORE_REQUEST_PROCESSING,
AFTER_SERVLET_PROCESSING or AFTER_RESPONSE_PROCESSINGcontextclass - The CometContext class to instanticate.
CometContext if not already created, or the
existing one.
protected boolean handle(AsyncProcessorTask apt)
throws IOException
CometContext.notify(E) the CometHandler
apt - the current apt representing the request.
IOException
protected SelectionKey activateContinuation(Long threadId,
CometContext cometContext,
boolean continueExecution)
threadId - the Thread.getId().cometContext - An instance of CometContext.
public CometContext getCometContext(String topic)
CometContext associated with the topic.
topic - the topic used to creates the CometContextprotected void interrupt(SelectionKey key)
CometSelector is expiring idle SelectionKey,
hence we need to resume the current request.
key - the expired SelectionKeyprotected void interrupt(CometTask cometTask)
protected void returnTask(CometTask cometTask)
Task to the pool.
protected void resume(SelectionKey key)
SelectionKey
public static String getNotificationHandlerClassName()
NotificationHandler class name.
NotificationHandler class name.public static void setNotificationHandlerClassName(String aNotificationHandlerClassName)
NotificationHandler class name.
the - default NotificationHandler class name.public Pipeline getPipeline()
public void setPipeline(Pipeline pipeline)
protected static final NotificationHandler loadNotificationHandlerInstance(String className)
public static final Logger logger()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||