Top Description Fields Constructors Methods
org.glassfish.grizzly.comet

public Class CometEngine

extends Object
Class Inheritance
Imports
java.io.IOException, java.util.Map, java.util.concurrent.ConcurrentHashMap, .ExecutorService, java.util.logging.Level, .Logger, org.glassfish.grizzly.localization.LogMessages

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. Executing this operation
    will tells Grizzly to suspend the response.
(3) Finally, you can CometContext#notify 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), 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).
Authors
Jeanfrancois Arcand, Gustav Trede

Field Summary

Modifier and TypeField and Description
protected final Map<String, CometContext<E>>
activeContexts

The current active CometContext keyed by context path.

public static final int
AFTER_RESPONSE_PROCESSING

Deprecated
The token used to support BEFORE_RESPONSE_PROCESSING polling.
public static final int
AFTER_SERVLET_PROCESSING

Deprecated
The token used to support AFTER_SERVLET_PROCESSING polling.
public static final int
BEFORE_REQUEST_PROCESSING

Deprecated
The token used to support BEFORE_REQUEST_PROCESSING polling.
private static final CometEngine
cometEngine

The single instance of this class.

public static final int
public static final int
private boolean
isCometSupported

Is Grizzly ARP enabled?

protected static final Logger
logger

Main logger

protected ExecutorService
threadPool

The ExecutorService used to execute

Constructor Summary

AccessConstructor and Description
protected
CometEngine()

Create a singleton and initialize all lists required.

Method Summary

Modifier and TypeMethod and Description
public CometContext<E>
deregister(String topic)

Deregister the CometHandler to the list of the CometContext.

public <E> CometContext<E>
getCometContext(String
the topic used to creates the CometContext
topic
)

Return the CometContext associated with the topic.

public static CometEngine

Returns:

CometEngine the singleton.
getEngine
()

Return a singleton of this Class.

protected boolean
interrupt(CometHandler<E>
The CometHandler encapsulating the suspended connection.
handler
,
boolean
Finish the current execution.
finishExecution
)
Deprecated use the CometContext version

Interrupt a CometHandler by invoking CometHandler#onInterrupt

protected void
interrupt0(CometHandler<E>
The CometHandler encapsulating the suspended connection.
handler
,
boolean
Finish the current execution.
finishExecution
)
Deprecated use the CometContext version

Interrupt logic in its own method, so it can be executed either async or sync.

protected boolean
isCometEnabled()

Return true if comet is enabled.

public static Logger
logger()

Return the current logger.

public <E> CometContext<E>

Returns:

CometContext a configured CometContext.
register
(String
the context path used to create the CometContext
topic
,
int
when the request will be suspended
type
)
Deprecated Use register(String) instead

Register a context path with this CometEngine.

public <E> CometContext<E>

Returns:

CometContext a configured CometContext.
register
(String
the context path used to create the CometContext
topic
)

Register a context path with this CometEngine.

public <E> CometContext<E>

Returns:

a new CometContext if not already created, or the existing one.
register
(String
the topic the new CometContext will represent.
topic
,
Class<? extends NotificationHandler> notificationClass)

Instantiate a new CometContext.

public void
setCometSupported(boolean supported)

public CometContext<E>
unregister(String topic)
Deprecated

Calls through to deregister(String).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activeContextsback to summary
protected final Map<String, CometContext<E>> activeContexts

The current active CometContext keyed by context path.

AFTER_RESPONSE_PROCESSINGback to summary
public static final int AFTER_RESPONSE_PROCESSING

Deprecated

The token used to support BEFORE_RESPONSE_PROCESSING polling.

Annotations
@Deprecated
AFTER_SERVLET_PROCESSINGback to summary
public static final int AFTER_SERVLET_PROCESSING

Deprecated

The token used to support AFTER_SERVLET_PROCESSING polling.

Annotations
@Deprecated
BEFORE_REQUEST_PROCESSINGback to summary
public static final int BEFORE_REQUEST_PROCESSING

Deprecated

The token used to support BEFORE_REQUEST_PROCESSING polling.

Annotations
@Deprecated
cometEngineback to summary
private static final CometEngine cometEngine

The single instance of this class.

DISABLE_CLIENT_DISCONNECTION_DETECTIONback to summary
public static final int DISABLE_CLIENT_DISCONNECTION_DETECTION

Deprecated

Annotations
@Deprecated
DISABLE_SUSPEND_TIMEOUTback to summary
public static final int DISABLE_SUSPEND_TIMEOUT

Deprecated

Annotations
@Deprecated
isCometSupportedback to summary
private boolean isCometSupported

Is Grizzly ARP enabled? By default we set it to false.

loggerback to summary
protected static final Logger logger

Main logger

threadPoolback to summary
protected ExecutorService threadPool

The ExecutorService used to execute

Constructor Detail

CometEngineback to summary
protected CometEngine()

Create a singleton and initialize all lists required.

Method Detail

deregisterback to summary
public CometContext<E> deregister(String topic)

Deregister the 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.

getCometContextback to summary
public <E> CometContext<E> getCometContext(String topic)

Return the CometContext associated with the topic.

Parameters
topic:String

the topic used to creates the CometContext

Annotations
@SuppressWarnings:unchecked
getEngineback to summary
public static CometEngine getEngine()

Return a singleton of this Class.

Returns:CometEngine

CometEngine the singleton.

interruptback to summary
protected boolean interrupt(CometHandler<E> handler, boolean finishExecution) throws IOException

Deprecated

use the CometContext version

Interrupt a CometHandler by invoking CometHandler#onInterrupt

Parameters
handler:CometHandler<E>

The CometHandler encapsulating the suspended connection.

finishExecution:boolean

Finish the current execution.

Annotations
@Deprecated
@SuppressWarnings:deprecation
See Also
CometContext#interrupt(CometHandler, boolean)
interrupt0back to summary
protected void interrupt0(CometHandler<E> handler, boolean finishExecution) throws IOException

Deprecated

use the CometContext version

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.

Parameters
handler:CometHandler<E>

The CometHandler encapsulating the suspended connection.

finishExecution:boolean

Finish the current execution.

Annotations
@Deprecated
See Also
CometContext#interrupt0(CometHandler, boolean)
isCometEnabledback to summary
protected boolean isCometEnabled()

Return true if comet is enabled.

loggerback to summary
public static Logger logger()

Return the current logger.

registerback to summary
public <E> CometContext<E> register(String topic, int type)

Deprecated

Use register(String) instead

Register a context path with this CometEngine. The CometContext returned will be of type type.

Parameters
topic:String

the context path used to create the CometContext

type:int

when the request will be suspended

Returns:CometContext<E>

CometContext a configured CometContext.

Annotations
@Deprecated
registerback to summary
public <E> CometContext<E> register(String topic)

Register a context path with this 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.

Parameters
topic:String

the context path used to create the CometContext

Returns:CometContext<E>

CometContext a configured CometContext.

registerback to summary
public <E> CometContext<E> register(String topic, Class<? extends NotificationHandler> notificationClass)

Instantiate a new CometContext.

Parameters
topic:String

the topic the new CometContext will represent.

Returns:CometContext<E>

a new CometContext if not already created, or the existing one.

Annotations
@SuppressWarnings:unchecked
setCometSupportedback to summary
public void setCometSupported(boolean supported)
unregisterback to summary
public CometContext<E> unregister(String topic)

Deprecated

Calls through to deregister(String).

Annotations
@Deprecated