com.vaadin.client.communication.
Class MessageSender
- java.lang.Object
-
- com.vaadin.client.communication.MessageSender
-
public class MessageSender extends Object
MessageSender is responsible for sending messages to the server.
Internally uses
XhrConnection
and/orPushConnection
for delivering messages, depending on the application configuration.Since:
7.6
Author:
Vaadin Ltd
-
-
Constructor Summary
Constructors Constructor Description MessageSender()
-
Method Summary
All Methods Modifier and Type Method Description void
endRequest()
static void
extendLiferaySession()
If on Liferay and logged in, ask the client side session management JavaScript to extend the session duration.
String
getCommunicationMethodName()
Returns a human readable string representation of the method used to communicate with the server.
boolean
hasActiveRequest()
Indicates whether or not there are currently active UIDL requests.
protected elemental.json.JsonObject
preparePayload(elemental.json.JsonArray reqInvocations, elemental.json.JsonObject extraJson)
Creates an UIDL request that can be sent to the server.
void
resynchronize()
Resynchronize the client side, i.e.
static void
runPostRequestHooks(String appId)
Runs possibly registered client side post request hooks.
protected void
send(elemental.json.JsonArray reqInvocations, elemental.json.JsonObject extraJson)
Send a UIDL request to the server.
void
send(elemental.json.JsonObject payload)
Sends an asynchronous or synchronous UIDL request to the server using the given URI.
static void
sendBeacon(String url, String payload)
Send a beacon message to the server.
void
sendInvocationsToServer()
void
sendUnloadBeacon()
Send an unload beacon message to the server over the XHR connection to notify the server of the page having been closed.
void
sendUnloadMessage()
Send an unload message to the server over the XHR connection to notify the server of the page having been closed.
void
setClientToServerMessageId(int nextExpectedId, boolean force)
Used internally to update what the server expects.
void
setConnection(ApplicationConnection connection)
Sets the application connection this instance is connected to.
void
setPushEnabled(boolean enabled)
Sets the status for the push connection.
void
startRequest()
-
-
-
Method Detail
-
sendUnloadBeacon
public void sendUnloadBeacon()
Send an unload beacon message to the server over the XHR connection to notify the server of the page having been closed.
See Also:
-
sendUnloadMessage
public void sendUnloadMessage()
Send an unload message to the server over the XHR connection to notify the server of the page having been closed.
-
sendBeacon
public static void sendBeacon(String url, String payload)
Send a beacon message to the server. Beacon requests are asynchronous and will be handled even after the page has closed and the rest of the associated javascript is no longer active.
Parameters:
url
- target URLpayload
- payload (should be kept very small)
-
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
-
sendInvocationsToServer
public void sendInvocationsToServer()
-
preparePayload
protected elemental.json.JsonObject preparePayload(elemental.json.JsonArray reqInvocations, elemental.json.JsonObject extraJson)
Creates an UIDL request that can be sent to the server.
Parameters:
reqInvocations
- Data containing RPC invocations and all related information.extraJson
- The JsonObject whose parameters are added to the payload
-
send
protected void send(elemental.json.JsonArray reqInvocations, elemental.json.JsonObject extraJson)
Send a UIDL request to the server.
Parameters:
reqInvocations
- Data containing RPC invocations and all related information.extraJson
- The JsonObject whose parameters are added to the payload
-
send
public void send(elemental.json.JsonObject payload)
Sends an asynchronous or synchronous UIDL request to the server using the given URI.
Parameters:
payload
- The contents of the request to send
-
setPushEnabled
public void setPushEnabled(boolean enabled)
Sets the status for the push connection.
Parameters:
enabled
-true
to enable the push connection;false
to disable the push connection.
-
startRequest
public void startRequest()
-
endRequest
public void endRequest()
-
runPostRequestHooks
public static void runPostRequestHooks(String appId)
Runs possibly registered client side post request hooks. This is expected to be run after each uidl request made by Vaadin application.
Parameters:
appId
-
-
extendLiferaySession
public static void extendLiferaySession()
If on Liferay and logged in, ask the client side session management JavaScript to extend the session duration. Otherwise, Liferay client side JavaScript will explicitly expire the session even though the server side considers the session to be active. See ticket #8305 for more information.
-
hasActiveRequest
public boolean hasActiveRequest()
Indicates whether or not there are currently active UIDL requests. Used internally to sequence requests properly, seldom needed in Widgets.
Returns:
true if there are active requests
-
getCommunicationMethodName
public String getCommunicationMethodName()
Returns a human readable string representation of the method used to communicate with the server.
Returns:
A string representation of the current transport type
-
resynchronize
public void resynchronize()
Resynchronize the client side, i.e. reload all component hierarchy and state from the server
-
setClientToServerMessageId
public void setClientToServerMessageId(int nextExpectedId, boolean force)
Used internally to update what the server expects.
Parameters:
nextExpectedId
- the new client id to setforce
- true if the id must be updated, false otherwise
-
-