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_SECONDS
in 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_SERVER
header 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 JavaScriptProtocol
the desired heartbeat interval that the client
should applies. This interceptor just manage the configured value and the protocol
sends
the value to the client.
InvokationOrder.PRIORITY
Modifier and Type | Field and Description |
---|---|
static String |
HEARTBEAT_FUTURE |
static String |
INTERCEPTOR_ADDED |
AFTER_DEFAULT, BEFORE_DEFAULT, FIRST_BEFORE_DEFAULT
Constructor and Description |
---|
HeartbeatInterceptor() |
Modifier and Type | Method and Description |
---|---|
int |
clientHeartbeatFrequencyInSeconds()
Gets the desired heartbeat frequency from client.
|
HeartbeatInterceptor |
clientHeartbeatFrequencyInSeconds(int clientHeartbeatFrequencyInSeconds) |
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.
|
void |
configure(AtmosphereConfig config)
Configure an AtmosphereFramework object.
|
void |
destroy()
Clean the AtmosphereInterceptor when removed or when the Atmosphere is undeployed.
|
protected int |
extractHeartbeatInterval(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.
|
int |
heartbeatFrequencyInSeconds() |
HeartbeatInterceptor |
heartbeatFrequencyInSeconds(int heartbeatFrequencyInSeconds) |
Action |
inspect(AtmosphereResource r)
Invoked before an
AtmosphereResource gets dispatched to AtmosphereHandler . |
HeartbeatInterceptor |
paddingText(byte[] paddingBytes) |
boolean |
resumeOnHeartbeat() |
HeartbeatInterceptor |
resumeOnHeartbeat(boolean resumeOnHeartbeat) |
String |
toString() |
postInspect, priority
public static final String INTERCEPTOR_ADDED
public static final String HEARTBEAT_FUTURE
public HeartbeatInterceptor paddingText(byte[] paddingBytes)
public byte[] getPaddingBytes()
Gets the bytes to use when sending an heartbeat for both client and server.
public HeartbeatInterceptor heartbeatFrequencyInSeconds(int heartbeatFrequencyInSeconds)
public int heartbeatFrequencyInSeconds()
public int clientHeartbeatFrequencyInSeconds()
Gets the desired heartbeat frequency from client.
public HeartbeatInterceptor clientHeartbeatFrequencyInSeconds(int clientHeartbeatFrequencyInSeconds)
public boolean resumeOnHeartbeat()
public HeartbeatInterceptor resumeOnHeartbeat(boolean resumeOnHeartbeat)
public void configure(AtmosphereConfig config)
AtmosphereConfigAware
configure
in interface AtmosphereConfigAware
configure
in class AtmosphereInterceptorAdapter
config
- AtmosphereConfig
public Action inspect(AtmosphereResource r)
AtmosphereInterceptor
AtmosphereResource
gets dispatched to AtmosphereHandler
.inspect
in interface AtmosphereInterceptor
inspect
in class AtmosphereInterceptorAdapter
r
- a AtmosphereResource
Action.CONTINUE
or Action.SUSPEND
to dispatch the AtmosphereResource
to other AtmosphereInterceptor
or AtmosphereHandler
.
Return Action.TYPE.CANCELLED
to stop the processing.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.
resource
- the resourcepublic 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.
interval
- the interval in secondsr
- the resourcerequest
- the request responseresponse
- the resource responsepublic String toString()
toString
in class AtmosphereInterceptorAdapter
public void destroy()
AtmosphereInterceptor
destroy
in interface AtmosphereInterceptor
destroy
in class AtmosphereInterceptorAdapter
Copyright © 2016. All rights reserved.