|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.grizzly.comet.CometContext<E>
public class CometContext<E>
The main object used by CometHandler
.
The CometContext
is always available for CometHandler
and can be used to notify other CometHandler
.
Attributes can be added/removed the same way HttpServletSession
is doing. It is not recommended to use attributes if this
CometContext
is not shared amongs multiple
context path (uses HttpServletSession instead).
Field Summary | |
---|---|
protected boolean |
blockingNotification
true if the caller of CometContext.notify should block when notifying other CometHandler. |
protected boolean |
cancelled
Is the CometContext instance been cancelled. |
protected int |
continuationType
The CometContext continuationType. |
protected ConcurrentHashMap<CometHandler,SelectionKey> |
handlers
The list of registered CometHandler |
protected static String |
INVALID_COMET_HANDLER
Generic error message |
protected NotificationHandler |
notificationHandler
The default NotificationHandler. |
Constructor Summary | |
---|---|
CometContext(String contextPath,
int continuationType)
Create a new instance |
Method Summary | |
---|---|
protected void |
addActiveCometTask(CometTask cometTask)
Add a CometTask to the active list. |
void |
addAttribute(Object key,
Object value)
Add an attibute. |
int |
addCometHandler(CometHandler handler)
Add a CometHandler . |
int |
addCometHandler(CometHandler handler,
boolean completeExecution)
Add a CometHandler . |
protected static void |
addInProgressSelectionKey(SelectionKey key)
Add a SelectionKey to the list of current operations. |
Object |
getAttribute(Object key)
Retrive an attribute. |
CometHandler |
getCometHandler(int hashCode)
Retrive a CometHandler using its hashKey; |
protected CometHandler |
getCometHandler(SelectionKey key)
Retrive a CometHandler using its SelectionKey. |
String |
getContextPath()
Get the context path associated with this instance. |
long |
getExpirationDelay()
Return the long delay before a request is resumed. |
NotificationHandler |
getNotificationHandler()
Return the associated NotificationHandler |
protected void |
initialize(SelectionKey key)
Initialize the newly added CometHandler . |
protected void |
interrupt(CometTask task)
Interrupt a CometHandler by invoking CometHandler.onInterrupt(com.sun.grizzly.comet.CometEvent) |
boolean |
isActive(CometHandler cometHandler)
Return true if this CometHandler is still active, e.g. |
boolean |
isBlockingNotification()
Return true if the invoker of notify() should block when notifying Comet Handlers. |
protected boolean |
isCancelled()
Is this instance beeing cancelled by the CometSelector |
protected void |
notify(CometEvent event,
int eventType,
SelectionKey key)
Notify all CometHandler . |
void |
notify(E attachment)
Notify all CometHandler . |
void |
notify(E attachment,
int eventType)
Notify all CometHandler . |
void |
notify(E attachment,
int eventType,
int cometHandlerID)
Notify a single CometHandler . |
protected void |
recycle()
Recycle this object. |
boolean |
registerAsyncRead(CometHandler handler)
Register for asynchronous read. |
boolean |
registerAsyncWrite(CometHandler handler)
Register for asynchronous write. |
Object |
removeAttribute(Object key)
Remove an attribute. |
void |
removeCometHandler(CometHandler handler)
Remove a CometHandler . |
void |
removeCometHandler(int hashCode)
Remove a CometHandler based on its hashcode. |
protected static boolean |
removeInProgressSelectionKey(SelectionKey key)
Remove a SelectionKey to the list of current operations. |
protected void |
resetSuspendIdleTimeout()
Reset the current timestamp on a suspended connection. |
void |
resumeCometHandler(CometHandler handler)
Resume the Comet request and remove it from the active CometHandler list. |
protected void |
resumeCometHandler(CometHandler handler,
boolean remove)
Resume the Comet request. |
void |
setBlockingNotification(boolean blockingNotification)
Set to true if the invoker of notify() should block when notifying Comet Handlers. |
protected void |
setCancelled(boolean cancelled)
Cancel this object or "uncancel". |
protected void |
setCometSelector(CometSelector cometSelector)
Set the CometSelector associated with this instance. |
void |
setExpirationDelay(long expirationDelay)
Set the long delay before a request is resumed. |
void |
setNotificationHandler(NotificationHandler notificationHandler)
Set the current NotificationHandler |
String |
toString()
Helper. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final String INVALID_COMET_HANDLER
protected boolean cancelled
CometContext
instance been cancelled.
protected ConcurrentHashMap<CometHandler,SelectionKey> handlers
CometHandler
protected int continuationType
CometContext
continuationType. See CometEngine
protected boolean blockingNotification
protected NotificationHandler notificationHandler
Constructor Detail |
---|
public CometContext(String contextPath, int continuationType)
contextPath
- the context pathtype
- when the Comet processing will happen (see CometEngine).Method Detail |
---|
public String getContextPath()
public void addAttribute(Object key, Object value)
key
- the keyvalue
- the valuepublic Object getAttribute(Object key)
key
- the key
public Object removeAttribute(Object key)
key
- the key
public int addCometHandler(CometHandler handler, boolean completeExecution)
CometHandler
. Client of this method might
make sure the CometHandler
is removed when the
CometHandler.onInterrupt
is invoked.
handler
- a new CometHandler
completeExecution
- Add the Comethandler but don't block waiting
for event.public int addCometHandler(CometHandler handler)
CometHandler
. Client on this method might
make sure the CometHandler
is removed when the
CometHandler.onInterrupt
is invoked.
handler
- a new CometHandler
public CometHandler getCometHandler(int hashCode)
CometHandler
using its hashKey;
protected CometHandler getCometHandler(SelectionKey key)
CometHandler
using its SelectionKey. The
SelectionKey
is not exposed to the Comet API, hence this
method must be protected.
protected void notify(CometEvent event, int eventType, SelectionKey key) throws IOException
CometHandler
. The attachment can be null.
The type
will determine which code>CometHandler
method will be invoked:
CometEvent.INTERRUPT -> CometHandler.onInterrupt
CometEvent.NOTIFY -> CometHandler.onEvent
CometEvent.INITIALIZE -> CometHandler.onInitialize
CometEvent.TERMINATE -> CometHandler.onTerminate
CometEvent.READ -> CometHandler.onEvent
CometEvent.WRITE -> CometHandler.onEvent
attachment
- An object shared amongst CometHandler
.type
- The type of notification.key
- The SelectionKey associated with the CometHandler.
IOException
public void removeCometHandler(CometHandler handler)
CometHandler
. If the continuation (connection)
associated with this CometHandler
no longer have
CometHandler
associated to it, it will be resumed.
public void removeCometHandler(int hashCode)
CometHandler
based on its hashcode.
public void resumeCometHandler(CometHandler handler)
protected void resumeCometHandler(CometHandler handler, boolean remove)
handler
- The CometHandler associated with the current continuation.remove
- true if the CometHandler needs to be removed.public boolean isActive(CometHandler cometHandler)
public void notify(E attachment) throws IOException
CometHandler
. The attachment can be null. All
CometHandler.onEvent()
will be invoked.
attachment
- An object shared amongst CometHandler
.
IOException
public void notify(E attachment, int eventType, int cometHandlerID) throws IOException
CometHandler
. The attachment can be null.
The type
will determine which code>CometHandler
method will be invoked:
CometEvent.INTERRUPT -> CometHandler.onInterrupt
CometEvent.NOTIFY -> CometHandler.onEvent
CometEvent.INITIALIZE -> CometHandler.onInitialize
CometEvent.TERMINATE -> CometHandler.onTerminate
CometEvent.READ -> CometHandler.onEvent
attachment
- An object shared amongst CometHandler
.type
- The type of notification.cometHandlerID
- Notify a single CometHandler.
IOException
protected void initialize(SelectionKey key) throws IOException
CometHandler
.
attachment
- An object shared amongst CometHandler
.type
- The type of notification.key
- The SelectionKey representing the CometHandler.
IOException
public void notify(E attachment, int eventType) throws IOException
CometHandler
. The attachment can be null.
The type
will determine which code>CometHandler
method will be invoked:
CometEvent.INTERRUPT -> CometHandler.onInterrupt
CometEvent.NOTIFY -> CometHandler.onEvent
CometEvent.INITIALIZE -> CometHandler.onInitialize
CometEvent.TERMINATE -> CometHandler.onTerminate
CometEvent.READ -> CometHandler.onEvent
attachment
- An object shared amongst CometHandler
.type
- The type of notification.
IOException
protected void resetSuspendIdleTimeout()
public boolean registerAsyncRead(CometHandler handler)
CometRead
that will read the next http request. In that
case, it is strongly recommended to not use that method unless your
CometHandler can handle the http request.
public boolean registerAsyncWrite(CometHandler handler)
protected void recycle()
protected boolean isCancelled()
CometSelector
protected void setCancelled(boolean cancelled)
cancelled
- true or false.protected void setCometSelector(CometSelector cometSelector)
CometSelector
associated with this instance.
CometSelector
- the CometSelector
associated with
this instance.public String toString()
toString
in class Object
public long getExpirationDelay()
long
delay before a request is resumed.
long
delay before a request is resumed.public void setExpirationDelay(long expirationDelay)
long
delay before a request is resumed.
long
- the long
delay before a request is resumed.protected void interrupt(CometTask task)
CometHandler
by invoking CometHandler.onInterrupt(com.sun.grizzly.comet.CometEvent)
protected void addActiveCometTask(CometTask cometTask)
CometTask
to the active list.
cometTask
- public boolean isBlockingNotification()
public void setBlockingNotification(boolean blockingNotification)
public void setNotificationHandler(NotificationHandler notificationHandler)
NotificationHandler
notificationHandler
- public NotificationHandler getNotificationHandler()
NotificationHandler
protected static void addInProgressSelectionKey(SelectionKey key)
SelectionKey
to the list of current operations.
key
- protected static boolean removeInProgressSelectionKey(SelectionKey key)
SelectionKey
to the list of current operations.
key
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |