Package org.glassfish.grizzly.comet
Class CometEngine
java.lang.Object
org.glassfish.grizzly.comet.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(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).- Author:
- Jeanfrancois Arcand, Gustav Trede
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<String,CometContext> The current activeCometContextkeyed by context path.static final intDeprecated.static final intDeprecated.static final intDeprecated.static final intDeprecated.static final intDeprecated.protected static final org.slf4j.LoggerMain loggerprotected ExecutorServiceTheExecutorServiceused to execute -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreate a singleton and initialize all lists required. -
Method Summary
Modifier and TypeMethodDescriptionderegister(String topic) Deregister theCometHandlerto the list of theCometContext.<E> CometContext<E>getCometContext(String topic) Return theCometContextassociated with the topic.static CometEngineReturn a singleton of this Class.protected booleaninterrupt(CometHandler handler, boolean finishExecution) Deprecated.use the CometContext versionprotected voidinterrupt0(CometHandler handler, boolean finishExecution) Deprecated.use the CometContext versionprotected booleanReturn true if comet is enabled.static org.slf4j.Loggerlogger()Return the current logger.<E> CometContext<E>Register a context path with thisCometEngine.<E> CometContext<E>Deprecated.Useregister(String)instead<E> CometContext<E>register(String topic, Class<? extends NotificationHandler> notificationClass) Instantiate a newCometContext.voidsetCometSupported(boolean supported) unregister(String topic) Deprecated.
-
Field Details
-
DISABLE_SUSPEND_TIMEOUT
Deprecated.- See Also:
-
DISABLE_CLIENT_DISCONNECTION_DETECTION
Deprecated.- See Also:
-
BEFORE_REQUEST_PROCESSING
Deprecated.The token used to support BEFORE_REQUEST_PROCESSING polling.- See Also:
-
AFTER_SERVLET_PROCESSING
Deprecated.The token used to support AFTER_SERVLET_PROCESSING polling.- See Also:
-
AFTER_RESPONSE_PROCESSING
Deprecated.The token used to support BEFORE_RESPONSE_PROCESSING polling.- See Also:
-
LOGGER
protected static final org.slf4j.Logger LOGGERMain logger -
threadPool
TheExecutorServiceused to execute -
activeContexts
The current activeCometContextkeyed by context path.
-
-
Constructor Details
-
CometEngine
protected CometEngine()Create a singleton and initialize all lists required.
-
-
Method Details
-
isCometEnabled
protected boolean isCometEnabled()Return true if comet is enabled. -
setCometSupported
public void setCometSupported(boolean supported) -
getEngine
Return a singleton of this Class.- Returns:
- CometEngine the singleton.
-
unregister
Deprecated.Calls through toderegister(String). -
deregister
Deregister theCometHandlerto the list of theCometContext. Invoking this method will invoke allCometHandler.onTerminate(CometEvent)before removing the associatedCometContext. Invoking that method will also resume the underlying connection associated with theCometHandler, similar to whatCometContext.resumeCometHandler(CometHandler)do. -
register
Deprecated.Useregister(String)instead- Parameters:
topic- the context path used to create theCometContexttype- when the request will be suspended- Returns:
- CometContext a configured
CometContext.
-
register
Register a context path with thisCometEngine. TheCometContextreturned will be of type AFTER_SERVLET_PROCESSING, which means the request target (most probably a Servlet) will be executed first and then polled.- Parameters:
topic- the context path used to create theCometContext- Returns:
- CometContext a configured
CometContext.
-
register
public <E> CometContext<E> register(String topic, Class<? extends NotificationHandler> notificationClass) Instantiate a newCometContext.- Parameters:
topic- the topic the newCometContextwill represent.- Returns:
- a new
CometContextif not already created, or the existing one.
-
getCometContext
Return theCometContextassociated with the topic.- Parameters:
topic- the topic used to creates theCometContext
-
interrupt
Deprecated.use the CometContext versionInterrupt aCometHandlerby invokingCometHandler.onInterrupt(org.glassfish.grizzly.comet.CometEvent)- Parameters:
handler- TheCometHandlerencapsulating the suspended connection.finishExecution- Finish the current execution.- Throws:
IOException- See Also:
-
interrupt0
Deprecated.use the CometContext versionInterrupt 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.- Parameters:
handler- TheCometHandlerencapsulating the suspended connection.finishExecution- Finish the current execution.- Throws:
IOException- See Also:
-
logger
public static org.slf4j.Logger logger()Return the current logger.
-