Class SilverpeasAsyncContext
- java.lang.Object
-
- org.silverpeas.core.notification.sse.SilverpeasAsyncContext
-
- All Implemented Interfaces:
javax.servlet.AsyncContext
,SilverpeasServerEventContext
public class SilverpeasAsyncContext extends Object implements javax.servlet.AsyncContext
This is a wrap of aAsyncContext
instance.All Server Event requests performed from a HTTP Server Sent Event WEB API MUST be wrapped by this implementation and registered by
SilverpeasServerEventContextManager
.- Author:
- Yohann Chastagnier
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(javax.servlet.AsyncListener listener)
void
addListener(javax.servlet.AsyncListener listener, javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)
void
close()
Closes the context.void
closeOnPreviousCheckFailure()
Performs a check on the context and close it if a failure is detected.void
complete()
<T extends javax.servlet.AsyncListener>
TcreateListener(Class<T> clazz)
void
dispatch()
void
dispatch(String path)
void
dispatch(javax.servlet.ServletContext context, String path)
boolean
equals(Object obj)
Long
getLastServerEventId()
Gets the last server event identifier known before a network breakdown.protected SilverpeasServerEventContextManager
getManager()
javax.servlet.http.HttpServletRequest
getRequest()
String
getRequestURI()
Gets the request URI behind the async context.javax.servlet.http.HttpServletResponse
getResponse()
String
getSessionId()
Gets the session identifier linked to the context.long
getTimeout()
User
getUser()
Gets the user identifier linked to the context.protected W
getWrappedInstance()
int
hashCode()
boolean
hasOriginalRequestAndResponse()
boolean
isComplete()
boolean
isSendPossible()
Indicates if sending is possible according to the state of the context.void
performEventSend(String name, long id, String data)
boolean
sendEvent(String name, long id, String data)
Sends the given using elements of the context.void
sendHeartbeatIfEnabled()
Sends 'heartbeat' event if it has been indicated to the context that it MUST have theis behavior.void
setHeartbeat(boolean heartbeat)
void
setLastServerEventId(Long lastServerEventId)
Sets the last server event identifier.void
setTimeout(long timeout)
void
start(Runnable run)
String
toString()
static SilverpeasAsyncContext
wrap(org.silverpeas.kernel.logging.SilverLogger silverLogger, javax.servlet.AsyncContext asyncContext, String userSessionId, User user)
Wraps the given instance.
-
-
-
Method Detail
-
wrap
public static SilverpeasAsyncContext wrap(org.silverpeas.kernel.logging.SilverLogger silverLogger, javax.servlet.AsyncContext asyncContext, String userSessionId, User user) throws javax.servlet.ServletException
Wraps the given instance. Nothing is wrapped if the given instance is a wrapped one.- Parameters:
silverLogger
- the sse silverpeas logger.asyncContext
- the instance to wrap.userSessionId
- the identifier or the user session.user
- the identifier of th user linked to the async request.- Returns:
- the wrapped given instance.
- Throws:
javax.servlet.ServletException
-
closeOnPreviousCheckFailure
public void closeOnPreviousCheckFailure()
Description copied from interface:SilverpeasServerEventContext
Performs a check on the context and close it if a failure is detected.By default, noting is performed.
- Specified by:
closeOnPreviousCheckFailure
in interfaceSilverpeasServerEventContext
-
sendHeartbeatIfEnabled
public void sendHeartbeatIfEnabled()
Description copied from interface:SilverpeasServerEventContext
Sends 'heartbeat' event if it has been indicated to the context that it MUST have theis behavior.This is useful for old WEB browser implementations which do not implement entirely server event API.
By default, noting is performed.
- Specified by:
sendHeartbeatIfEnabled
in interfaceSilverpeasServerEventContext
-
performEventSend
public void performEventSend(String name, long id, String data) throws IOException
- Throws:
IOException
-
isSendPossible
public boolean isSendPossible()
Indicates if sending is possible according to the state of the context.- Specified by:
isSendPossible
in interfaceSilverpeasServerEventContext
- Returns:
- true if send is possible, false otherwise.
-
getRequestURI
public String getRequestURI()
Gets the request URI behind the async context.- Specified by:
getRequestURI
in interfaceSilverpeasServerEventContext
- Returns:
- a request URI as string.
-
getRequest
public javax.servlet.http.HttpServletRequest getRequest()
- Specified by:
getRequest
in interfacejavax.servlet.AsyncContext
-
getResponse
public javax.servlet.http.HttpServletResponse getResponse()
- Specified by:
getResponse
in interfacejavax.servlet.AsyncContext
-
hasOriginalRequestAndResponse
public boolean hasOriginalRequestAndResponse()
- Specified by:
hasOriginalRequestAndResponse
in interfacejavax.servlet.AsyncContext
-
dispatch
public void dispatch()
- Specified by:
dispatch
in interfacejavax.servlet.AsyncContext
-
dispatch
public void dispatch(String path)
- Specified by:
dispatch
in interfacejavax.servlet.AsyncContext
-
dispatch
public void dispatch(javax.servlet.ServletContext context, String path)
- Specified by:
dispatch
in interfacejavax.servlet.AsyncContext
-
complete
public void complete()
- Specified by:
complete
in interfacejavax.servlet.AsyncContext
-
setHeartbeat
public void setHeartbeat(boolean heartbeat)
-
isComplete
public boolean isComplete()
-
close
public void close()
Description copied from interface:SilverpeasServerEventContext
Closes the context.It will be removed from the management context handled by
SilverpeasServerEventContextManager
.- Specified by:
close
in interfaceSilverpeasServerEventContext
-
start
public void start(Runnable run)
- Specified by:
start
in interfacejavax.servlet.AsyncContext
-
addListener
public void addListener(javax.servlet.AsyncListener listener)
- Specified by:
addListener
in interfacejavax.servlet.AsyncContext
-
addListener
public void addListener(javax.servlet.AsyncListener listener, javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)
- Specified by:
addListener
in interfacejavax.servlet.AsyncContext
-
createListener
public <T extends javax.servlet.AsyncListener> T createListener(Class<T> clazz) throws javax.servlet.ServletException
- Specified by:
createListener
in interfacejavax.servlet.AsyncContext
- Throws:
javax.servlet.ServletException
-
getTimeout
public long getTimeout()
- Specified by:
getTimeout
in interfacejavax.servlet.AsyncContext
-
setTimeout
public void setTimeout(long timeout)
- Specified by:
setTimeout
in interfacejavax.servlet.AsyncContext
-
hashCode
public int hashCode()
-
equals
public boolean equals(Object obj)
-
toString
public String toString()
-
getSessionId
public String getSessionId()
Description copied from interface:SilverpeasServerEventContext
Gets the session identifier linked to the context.Be careful, according to the WEB context, the session identifier is not necessarily the JSESSIONID.
- Specified by:
getSessionId
in interfaceSilverpeasServerEventContext
- Returns:
- a session identifier as string.
-
getUser
public User getUser()
Description copied from interface:SilverpeasServerEventContext
Gets the user identifier linked to the context.- Specified by:
getUser
in interfaceSilverpeasServerEventContext
- Returns:
- a user identifier as string.
-
getLastServerEventId
public Long getLastServerEventId()
Description copied from interface:SilverpeasServerEventContext
Gets the last server event identifier known before a network breakdown.- Specified by:
getLastServerEventId
in interfaceSilverpeasServerEventContext
- Returns:
- an identifier as string.
-
setLastServerEventId
public void setLastServerEventId(Long lastServerEventId)
Sets the last server event identifier.- Specified by:
setLastServerEventId
in interfaceSilverpeasServerEventContext
- Parameters:
lastServerEventId
- a last event identifier as long, can be null.
-
getWrappedInstance
protected W getWrappedInstance()
-
getManager
protected SilverpeasServerEventContextManager getManager()
-
sendEvent
public boolean sendEvent(String name, long id, String data) throws IOException
Description copied from interface:SilverpeasServerEventContext
Sends the given using elements of the context.If sending has not been done, then context is removed from the context manager.
- Specified by:
sendEvent
in interfaceSilverpeasServerEventContext
- Parameters:
name
- the name of the event.id
- the unique identifier of the event (from the start of the server).data
- the data sent with the event.- Returns:
- true if send has been done, false otherwise.
- Throws:
IOException
-
-