public class CometEngine extends Object
(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(org.glassfish.grizzly.comet.CometHandler<E>)
. Executing this operation
will tells Grizzly to suspend the response.
(3) Finally, you can CometContext.notify(E)
other CometHandler
to share information between CometHandler
. 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, int)
), which can be before, during or after invoking a Servlet
There is known limitation related to HTTP pipelining, it can't work
properly when CometContext.isDetectClosedConnections()
is enabled.
So if you want to support HTTP pipelining, the closed connection
detection mechanism should be disabled via CometContext.setDetectClosedConnections(boolean)
.Modifier and Type | Field and Description |
---|---|
protected Map<String,CometContext> |
activeContexts
The current active
CometContext keyed by context path. |
static int |
AFTER_RESPONSE_PROCESSING
Deprecated.
|
static int |
AFTER_SERVLET_PROCESSING
Deprecated.
|
static int |
BEFORE_REQUEST_PROCESSING
Deprecated.
|
static int |
DISABLE_CLIENT_DISCONNECTION_DETECTION
Deprecated.
|
static int |
DISABLE_SUSPEND_TIMEOUT
Deprecated.
|
protected static Logger |
logger
Main logger
|
protected ExecutorService |
threadPool
The
ExecutorService used to execute |
Modifier | Constructor and Description |
---|---|
protected |
CometEngine()
Create a singleton and initialize all lists required.
|
Modifier and Type | Method and Description |
---|---|
CometContext |
deregister(String topic)
Deregister the
CometHandler to the list of the CometContext . |
<E> CometContext<E> |
getCometContext(String topic)
Return the
CometContext associated with the topic. |
static CometEngine |
getEngine()
Return a singleton of this Class.
|
protected boolean |
interrupt(CometHandler handler,
boolean finishExecution)
Deprecated.
use the CometContext version
|
protected void |
interrupt0(CometHandler handler,
boolean finishExecution)
Deprecated.
use the CometContext version
|
protected boolean |
isCometEnabled()
Return true if comet is enabled.
|
static Logger |
logger()
Return the current logger.
|
<E> CometContext<E> |
register(String topic)
Register a context path with this
CometEngine . |
<E> CometContext<E> |
register(String topic,
Class<? extends NotificationHandler> notificationClass)
Instantiate a new
CometContext . |
<E> CometContext<E> |
register(String topic,
int type)
Deprecated.
Use
register(String) instead |
void |
setCometSupported(boolean supported) |
CometContext |
unregister(String topic)
Deprecated.
|
@Deprecated public static final int DISABLE_SUSPEND_TIMEOUT
@Deprecated public static final int DISABLE_CLIENT_DISCONNECTION_DETECTION
@Deprecated public static final int BEFORE_REQUEST_PROCESSING
@Deprecated public static final int AFTER_SERVLET_PROCESSING
@Deprecated public static final int AFTER_RESPONSE_PROCESSING
protected static final Logger logger
protected ExecutorService threadPool
ExecutorService
used to executeprotected final Map<String,CometContext> activeContexts
CometContext
keyed by context path.protected CometEngine()
protected boolean isCometEnabled()
public void setCometSupported(boolean supported)
public static CometEngine getEngine()
@Deprecated public CometContext unregister(String topic)
deregister(String)
.public CometContext deregister(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 <E> CometContext<E> register(String topic, int type)
register(String)
insteadtopic
- the context path used to create the CometContext
type
- when the request will be suspendedCometContext
.public <E> CometContext<E> 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 <E> CometContext<E> register(String topic, Class<? extends NotificationHandler> notificationClass)
CometContext
.topic
- the topic the new CometContext
will represent.CometContext
if not already created, or the existing one.public <E> CometContext<E> getCometContext(String topic)
CometContext
associated with the topic.topic
- the topic used to creates the CometContext
protected boolean interrupt(CometHandler handler, boolean finishExecution) throws IOException
CometHandler
by invoking CometHandler.onInterrupt(org.glassfish.grizzly.comet.CometEvent)
handler
- The CometHandler
encapsulating the suspended connection.finishExecution
- Finish the current execution.IOException
CometContext.interrupt(CometHandler, boolean)
protected void interrupt0(CometHandler handler, boolean finishExecution) throws IOException
handler
- The CometHandler
encapsulating the suspended connection.finishExecution
- Finish the current execution.IOException
CometContext.interrupt0(CometHandler, boolean)
public static Logger logger()
Copyright © 2014 Oracle Corporation. All rights reserved.