|
||||||||||
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 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.grizzly.comet.CometHandler, boolean)
. Executing this operation
will tells Grizzly to suspend the response.
(3) Finally, you can CometContext.notify(java.lang.Object)
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> |
cometContextCache
cached CometContexts |
protected static CometEngine |
cometEngine
The single instance of this class. |
static int |
DISABLE_CLIENT_DISCONNECTION_DETECTION
|
static int |
DISABLE_SUSPEND_TIMEOUT
|
protected static Logger |
logger
Main logger |
protected ExtendedThreadPool |
threadPool
The ExecutorService used to execute CometTask |
protected static ThreadLocal<CometTask> |
updatedContexts
Store updatedCometContext. |
Constructor Summary | |
---|---|
protected |
CometEngine()
Creat a singleton and initialize all lists required. |
Method Summary | |
---|---|
protected void |
flushPostExecute(CometTask task,
boolean cancelKey)
Ensures ProcessorTask is recycled and that SelectionKey is canceled when needed. |
CometContext |
getCometContext(String topic)
Return the CometContext associated with the topic. |
static CometEngine |
getEngine()
Return a singleton of this Class. |
ExtendedThreadPool |
getThreadPool()
returns the thread pool comet is using |
protected boolean |
handle(AsyncProcessorTask apt)
Handle an interrupted(or polled) request by matching the current context path with the registered one. |
protected boolean |
interrupt(CometTask task,
boolean finishExecution)
Interrupt a CometHandler by invoking CometHandler.onInterrupt(com.sun.grizzly.comet.CometEvent) |
protected void |
interrupt0(CometTask task,
boolean finishExecution)
Interrupt logic in its own method, so it can be executed either async or sync. cometHandler.onInterrupt is performed async due to its functionality is unknown, hence not safe to run in the performance critical selector thread. |
protected boolean |
isCometEnabled()
Return true is Comet is enabled, e.g. |
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 NotificationHandler> notificationClass)
Instantiate a new CometContext . |
void |
setThreadPool(ExtendedThreadPool pool)
sets the default ThreadPool that DefaultNotificationHandler use. |
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 static final Logger logger
protected ExtendedThreadPool threadPool
ExecutorService
used to execute CometTask
protected static final CometEngine cometEngine
protected final ConcurrentHashMap<String,CometContext> activeContexts
CometContext
keyed by context path.
protected final Queue<CometContext> cometContextCache
protected static final ThreadLocal<CometTask> updatedContexts
Constructor Detail |
---|
protected CometEngine()
Method Detail |
---|
protected boolean isCometEnabled()
SelectorThread.setEnableAsyncExecution(boolean)
has been set to true
public static CometEngine getEngine()
public final void setThreadPool(ExtendedThreadPool pool)
public ExtendedThreadPool getThreadPool()
public CometContext unregister(String topic)
CometHandler
to the list of the
CometContext
. Invoking this method will invoke all
CometHandler.onTerminate(CometEvent)
before
removing the associated CometContext
. Invoking that method
will also resume the underlying connection associated with the
CometHandler
, similar to what
CometContext.resumeCometHandler(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
CometContext
type
- 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 NotificationHandler> notificationClass)
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_PROCESSING
CometContext
if not already created, or the
existing one.protected boolean handle(AsyncProcessorTask apt) throws IOException
CometContext.notify(java.lang.Object)
the CometHandler
apt
- the current apt representing the request.
IOException
public CometContext getCometContext(String topic)
CometContext
associated with the topic.
topic
- the topic used to creates the CometContext
protected boolean interrupt(CometTask task, boolean finishExecution)
CometHandler
by invoking CometHandler.onInterrupt(com.sun.grizzly.comet.CometEvent)
task
- The CometTask
encapsulating the suspended connection.finishExecution
- Finish the current execution.protected void interrupt0(CometTask task, boolean finishExecution)
task
- The CometTask
encapsulating the suspended connection.finishExecution
- Finish the current execution.protected void flushPostExecute(CometTask task, boolean cancelKey)
ProcessorTask
is recycled and that SelectionKey
is canceled when needed.
task
- cancelKey
- public static Logger logger()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |