|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.grizzly.comet.CometEngine
public 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 cometContext path on which Comet support will be applied:
CometEngine cometEngine = CometEngine.getEngine()
CometContext cometContext = cometEngine.register(contextPath)
(2) Second, add an instance of CometHandler
to the
CometContext
returned by the register method:
cometContext.addCometHandler(handler);
(3) Finally, you can notify other CometHandler
by doing:
cometContext.notify(Object)(handler);
You can also select the stage where the request polling happens when
registering the cometContext path (see register(String,int);
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 ConcurrentLinkedQueue<CometContext> |
cometContexts
Cache of CometContext instance. |
protected CometSelector |
cometSelector
The CometSelector used to poll requests. |
protected ConcurrentLinkedQueue<CometTask> |
cometTasks
Cache of CometTask instance |
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()
Creat 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 contextPath)
Return the CometContext associated with the cometContext path. |
protected CometTask |
getCometTask(CometContext cometContext,
SelectionKey key,
Pipeline ctxPipeline)
Return a clean and configured CometTask |
static CometEngine |
getEngine()
Return a singleton of this Class. |
static String |
getNotificationHandlerClassName()
Return the default NotificationHandler class name. |
protected boolean |
handle(AsyncProcessorTask apt)
Handle an interrupted(or polled) request by matching the current context path with the registered one. |
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 contextPath)
Register a context path with this CometEngine . |
CometContext |
register(String contextPath,
int type)
Register a context path with this CometEngine . |
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. |
CometContext |
unregister(String contextPath)
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 BEFORE_REQUEST_PROCESSING
public static final int AFTER_SERVLET_PROCESSING
public static final int AFTER_RESPONSE_PROCESSING
protected Pipeline pipeline
Pipeline
used to execute CometTask
protected ConcurrentHashMap<String,CometContext> activeContexts
CometContext
keyed by context path.
protected ConcurrentLinkedQueue<CometTask> cometTasks
CometTask
instance
protected ConcurrentLinkedQueue<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 contextPath)
CometHandler
to the list of the
CometContext
.
public CometContext register(String contextPath)
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.
contextPath
- the context path used to create the
CometContext
CometContext
.public CometContext register(String contextPath, int type)
CometEngine
. The
CometContext
returned will be of type
type
.
contextPath
- the context path used to create the
CometContext
CometContext
.protected boolean handle(AsyncProcessorTask apt) throws IOException
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.
protected CometTask getCometTask(CometContext cometContext, SelectionKey key, Pipeline ctxPipeline)
CometTask
cometContext
- the CometContext to cleankey
- The current SelectionKey
public CometContext getCometContext(String contextPath)
CometContext
associated with the cometContext path.
XXX: This is not secure as a you can get a CometContext associated
with another cometContext path. But this allow interesting application...
MUST BE REVISTED.
contextPath
- the request's cometContext path.protected void interrupt(SelectionKey key)
CometSelector
is expiring idle SelectionKey
,
hence we need to resume the current request.
key
- the expired SelectionKeyprotected 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.protected static 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 |