org.atmosphere.interceptor
Class HeartbeatInterceptor

java.lang.Object
  extended by org.atmosphere.cpr.AtmosphereInterceptorAdapter
      extended by org.atmosphere.interceptor.HeartbeatInterceptor
All Implemented Interfaces:
AtmosphereInterceptor, 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_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.

Author:
Jeanfrancois Arcand

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.atmosphere.interceptor.InvokationOrder
InvokationOrder.PRIORITY
 
Field Summary
static String HEARTBEAT_FUTURE
           
static String INTERCEPTOR_ADDED
           
 
Fields inherited from interface org.atmosphere.interceptor.InvokationOrder
AFTER_DEFAULT, BEFORE_DEFAULT, FIRST_BEFORE_DEFAULT
 
Constructor Summary
HeartbeatInterceptor()
           
 
Method Summary
 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)
          Allow this object to configure its state when initialized.
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()
           
 
Methods inherited from class org.atmosphere.cpr.AtmosphereInterceptorAdapter
postInspect, priority
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INTERCEPTOR_ADDED

public static final String INTERCEPTOR_ADDED

HEARTBEAT_FUTURE

public static final String HEARTBEAT_FUTURE
See Also:
Constant Field Values
Constructor Detail

HeartbeatInterceptor

public HeartbeatInterceptor()
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: AtmosphereInterceptor
Allow this object to configure its state when initialized.

Specified by:
configure in interface AtmosphereInterceptor
Overrides:
configure in class AtmosphereInterceptorAdapter
Parameters:
config - an AtmosphereConfig

inspect

public Action inspect(AtmosphereResource r)
Description copied from interface: AtmosphereInterceptor
Invoked before an AtmosphereResource gets dispatched to AtmosphereHandler.

Specified by:
inspect in interface AtmosphereInterceptor
Overrides:
inspect in class AtmosphereInterceptorAdapter
Parameters:
r - a AtmosphereResource
Returns:
Action.CONTINUE or Action.SUSPEND to dispatch the AtmosphereResource to other AtmosphereInterceptor or AtmosphereHandler. Return Action.TYPE.CANCELLED to 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 seconds
r - the resource
request - the request response
response - the resource response
Returns:
this

toString

public String toString()
Overrides:
toString in class AtmosphereInterceptorAdapter


Copyright © 2014. All Rights Reserved.