Class HeartbeatInterceptor
- java.lang.Object
-
- org.atmosphere.cpr.AtmosphereInterceptorAdapter
-
- org.atmosphere.interceptor.HeartbeatInterceptor
-
- All Implemented Interfaces:
AtmosphereInterceptor,AtmosphereConfigAware,InvokationOrder
public class HeartbeatInterceptor extends AtmosphereInterceptorAdapter
An interceptor that send whitespace every in 60 seconds by default. Another value could be specified with the
ApplicationConfig.HEARTBEAT_INTERVAL_IN_SECONDSin the atmosphere config. The heartbeat will be scheduled as soon as the request is suspended.Moreover, any client can ask for a particular value with the
HeaderConfig.X_HEARTBEAT_SERVERheader set in request. This value will be taken in consideration if it is greater than the configured value. Client can also specify the value "0" to disable heartbeat.Finally the server notifies thanks to the
JavaScriptProtocolthe desired heartbeat interval that the client should applies. This interceptor just manage the configured value and theprotocolsends the value to the client.- Author:
- Jeanfrancois Arcand
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.atmosphere.interceptor.InvokationOrder
InvokationOrder.PRIORITY
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringHEARTBEAT_FUTUREstatic java.lang.StringINTERCEPTOR_ADDED-
Fields inherited from interface org.atmosphere.interceptor.InvokationOrder
AFTER_DEFAULT, BEFORE_DEFAULT, FIRST_BEFORE_DEFAULT
-
-
Constructor Summary
Constructors Constructor Description HeartbeatInterceptor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intclientHeartbeatFrequencyInSeconds()Gets the desired heartbeat frequency from client.HeartbeatInterceptorclientHeartbeatFrequencyInSeconds(int clientHeartbeatFrequencyInSeconds)HeartbeatInterceptorclock(int interval, AtmosphereResource r, AtmosphereRequest request, AtmosphereResponse response)Configures the heartbeat sent by the server in an interval in seconds specified in parameter for the given resource.voidconfigure(AtmosphereConfig config)Configure an AtmosphereFramework object.voiddestroy()Clean the AtmosphereInterceptor when removed or when the Atmosphere is undeployed.protected intextractHeartbeatInterval(AtmosphereResourceImpl resource)Extracts the heartbeat interval as explained in class description.byte[]getPaddingBytes()Gets the bytes to use when sending an heartbeat for both client and server.intheartbeatFrequencyInSeconds()HeartbeatInterceptorheartbeatFrequencyInSeconds(int heartbeatFrequencyInSeconds)Actioninspect(AtmosphereResource r)Invoked before anAtmosphereResourcegets dispatched toAtmosphereHandler.HeartbeatInterceptorpaddingText(byte[] paddingBytes)booleanresumeOnHeartbeat()HeartbeatInterceptorresumeOnHeartbeat(boolean resumeOnHeartbeat)java.lang.StringtoString()-
Methods inherited from class org.atmosphere.cpr.AtmosphereInterceptorAdapter
postInspect, priority
-
-
-
-
Field Detail
-
INTERCEPTOR_ADDED
public static final java.lang.String INTERCEPTOR_ADDED
-
HEARTBEAT_FUTURE
public static final java.lang.String HEARTBEAT_FUTURE
- See Also:
- Constant Field Values
-
-
Method Detail
-
paddingText
public HeartbeatInterceptor paddingText(byte[] paddingBytes)
-
getPaddingBytes
public byte[] getPaddingBytes()
Gets the bytes to use when sending an heartbeat for both client and server.
- Returns:
- the heartbeat value
-
heartbeatFrequencyInSeconds
public HeartbeatInterceptor heartbeatFrequencyInSeconds(int heartbeatFrequencyInSeconds)
-
heartbeatFrequencyInSeconds
public int heartbeatFrequencyInSeconds()
-
clientHeartbeatFrequencyInSeconds
public int clientHeartbeatFrequencyInSeconds()
Gets the desired heartbeat frequency from client.
- Returns:
- the frequency in seconds
-
clientHeartbeatFrequencyInSeconds
public HeartbeatInterceptor clientHeartbeatFrequencyInSeconds(int clientHeartbeatFrequencyInSeconds)
-
resumeOnHeartbeat
public boolean resumeOnHeartbeat()
-
resumeOnHeartbeat
public HeartbeatInterceptor resumeOnHeartbeat(boolean resumeOnHeartbeat)
-
configure
public void configure(AtmosphereConfig config)
Description copied from interface:AtmosphereConfigAwareConfigure an AtmosphereFramework object.- Specified by:
configurein interfaceAtmosphereConfigAware- Overrides:
configurein classAtmosphereInterceptorAdapter- Parameters:
config-AtmosphereConfig
-
inspect
public Action inspect(AtmosphereResource r)
Description copied from interface:AtmosphereInterceptorInvoked before anAtmosphereResourcegets dispatched toAtmosphereHandler.- Specified by:
inspectin interfaceAtmosphereInterceptor- Overrides:
inspectin classAtmosphereInterceptorAdapter- Parameters:
r- aAtmosphereResource- Returns:
Action.CONTINUEorAction.SUSPENDto dispatch theAtmosphereResourceto otherAtmosphereInterceptororAtmosphereHandler. ReturnAction.TYPE.CANCELLEDto stop the processing.
-
extractHeartbeatInterval
protected int extractHeartbeatInterval(AtmosphereResourceImpl resource)
Extracts the heartbeat interval as explained in class description. This method could be overridden to change the the configuration points.
- Parameters:
resource- the resource- Returns:
- the interval, 0 won't trigger the heartbeat
-
clock
public HeartbeatInterceptor clock(int interval, AtmosphereResource r, AtmosphereRequest request, AtmosphereResponse response)
Configures the heartbeat sent by the server in an interval in seconds specified in parameter for the given resource.
- Parameters:
interval- the interval in secondsr- the resourcerequest- the request responseresponse- the resource response
-
toString
public java.lang.String toString()
- Overrides:
toStringin classAtmosphereInterceptorAdapter
-
destroy
public void destroy()
Description copied from interface:AtmosphereInterceptorClean the AtmosphereInterceptor when removed or when the Atmosphere is undeployed.- Specified by:
destroyin interfaceAtmosphereInterceptor- Overrides:
destroyin classAtmosphereInterceptorAdapter
-
-