com.vaadin.client.communication
Class MessageHandler

java.lang.Object
  extended by com.vaadin.client.communication.MessageHandler

public class MessageHandler
extends java.lang.Object

A MessageHandler is responsible for handling all incoming messages (JSON) from the server (state changes, RPCs and other updates) and ensuring that the connectors are updated accordingly.

Since:
7.6
Author:
Vaadin Ltd

Field Summary
static java.lang.String JSON_COMMUNICATION_PREFIX
           
static java.lang.String JSON_COMMUNICATION_SUFFIX
           
protected  int lastProcessingTime
          Holds the time spent rendering the last request
protected  int totalProcessingTime
          Holds the total time spent rendering requests during the lifetime of the session.
 
Constructor Summary
MessageHandler()
           
 
Method Summary
 java.lang.String getCsrfToken()
          Gets the token (aka double submit cookie) that the server uses to protect against Cross Site Request Forgery attacks.
 int getLastSeenServerSyncId()
          Gets the server id included in the last received response.
protected  void handleJSON(ValueMap json)
           
 void handleMessage(ValueMap json)
          Handles a received UIDL JSON text, parsing it, and passing it on to the appropriate handlers, while logging timing information.
 boolean isInitialUidlHandled()
          Checks if the first UIDL has been handled
 boolean isUpdatingState()
          Checks whether state changes are currently being processed.
static ValueMap parseJson(java.lang.String jsonText)
          Unwraps and parses the given JSON, originating from the server
static ValueMap parseWrappedJson(java.lang.String wrappedJsonText)
          Parse the given wrapped JSON, received from the server, to a ValueMap
 void resumeResponseHandling(java.lang.Object lock)
          Resumes the rendering process once all locks have been removed.
 void setConnection(ApplicationConnection connection)
          Sets the application connection this instance is connected to.
static java.lang.String stripJSONWrapping(java.lang.String jsonWithWrapping)
          Strips the JSON wrapping from the given json string with wrapping.
 void suspendReponseHandling(java.lang.Object lock)
          This method can be used to postpone rendering of a response for a short period of time (e.g.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JSON_COMMUNICATION_PREFIX

public static final java.lang.String JSON_COMMUNICATION_PREFIX
See Also:
Constant Field Values

JSON_COMMUNICATION_SUFFIX

public static final java.lang.String JSON_COMMUNICATION_SUFFIX
See Also:
Constant Field Values

lastProcessingTime

protected int lastProcessingTime
Holds the time spent rendering the last request


totalProcessingTime

protected int totalProcessingTime
Holds the total time spent rendering requests during the lifetime of the session.

Constructor Detail

MessageHandler

public MessageHandler()
Method Detail

setConnection

public void setConnection(ApplicationConnection connection)
Sets the application connection this instance is connected to. Called internally by the framework.

Parameters:
connection - the application connection this instance is connected to

handleMessage

public void handleMessage(ValueMap json)
Handles a received UIDL JSON text, parsing it, and passing it on to the appropriate handlers, while logging timing information.

Parameters:
jsonText - The JSON to handle

handleJSON

protected void handleJSON(ValueMap json)

suspendReponseHandling

public void suspendReponseHandling(java.lang.Object lock)
This method can be used to postpone rendering of a response for a short period of time (e.g. to avoid the rendering process during animation).

Parameters:
lock -

resumeResponseHandling

public void resumeResponseHandling(java.lang.Object lock)
Resumes the rendering process once all locks have been removed.

Parameters:
lock -

getLastSeenServerSyncId

public int getLastSeenServerSyncId()
Gets the server id included in the last received response.

This id can be used by connectors to determine whether new data has been received from the server to avoid doing the same calculations multiple times.

No guarantees are made for the structure of the id other than that there will be a new unique value every time a new response with data from the server is received.

The initial id when no request has yet been processed is -1.

Returns:
an id identifying the response

getCsrfToken

public java.lang.String getCsrfToken()
Gets the token (aka double submit cookie) that the server uses to protect against Cross Site Request Forgery attacks.

Returns:
the CSRF token string

isUpdatingState

public boolean isUpdatingState()
Checks whether state changes are currently being processed. Certain operations are not allowed when the internal state of the application might be in an inconsistent state because some state changes have been applied but others not. This includes running layotus.

Returns:
true if the internal state might be inconsistent because changes are being processed; false if the state should be consistent

isInitialUidlHandled

public boolean isInitialUidlHandled()
Checks if the first UIDL has been handled

Returns:
true if the initial UIDL has already been processed, false otherwise

stripJSONWrapping

public static java.lang.String stripJSONWrapping(java.lang.String jsonWithWrapping)
Strips the JSON wrapping from the given json string with wrapping. If the given string is not wrapped as expected, returns null

Parameters:
jsonWithWrapping - the JSON received from the server
Returns:
an unwrapped JSON string or null if the given string was not wrapped
Since:
7.6

parseJson

public static ValueMap parseJson(java.lang.String jsonText)
Unwraps and parses the given JSON, originating from the server

Parameters:
jsonText - the json from the server
Returns:
A parsed ValueMap or null if the input could not be parsed (or was null)

parseWrappedJson

public static ValueMap parseWrappedJson(java.lang.String wrappedJsonText)
Parse the given wrapped JSON, received from the server, to a ValueMap

Parameters:
wrappedJsonText - the json, wrapped as done by the server
Returns:
a ValueMap, or null if the wrapping was incorrect or json could not be parsed


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.