Class AtmospherePushConnection
- java.lang.Object
-
- com.vaadin.client.communication.AtmospherePushConnection
-
- All Implemented Interfaces:
PushConnection
public class AtmospherePushConnection extends Object implements PushConnection
The defaultPushConnectionimplementation that uses Atmosphere for handling the communication channel.- Since:
- 1.0
- Author:
- Vaadin Ltd
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAtmospherePushConnection.AbstractJSOJavaScriptObject class with some helper methods to set and get primitive values.static classAtmospherePushConnection.AtmosphereConfigurationProvides information from the Atmosphere configuration object.static classAtmospherePushConnection.AtmosphereResponseProvides data from an Atmosphere response JavaScript object.protected static classAtmospherePushConnection.FragmentedMessageRepresents a message splitted into multiple fragments of maximum lengthAtmospherePushConnection.FragmentedMessage.FRAGMENT_LENGTH.protected static classAtmospherePushConnection.StateRepresents the connection state of a push connection.
-
Constructor Summary
Constructors Constructor Description AtmospherePushConnection(Registry registry)Creates a new instance connected to the given registry.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected AtmospherePushConnection.AtmosphereConfigurationcreateConfig()Creates the default Atmosphere configuration object.voiddisconnect(Command command)Closes the push connection.protected AtmospherePushConnection.AtmosphereConfigurationgetConfig()StringgetTransportType()Returns a human readable string representation of the transport type used to communicate with the server.booleanisActive()Checks whether this push connection is in a state where it can push messages to the server.booleanisBidirectional()Checks whether this push connection should be used for communication in both directions or if an XHR should be used for client to server communication.protected voidonClientTimeout(AtmospherePushConnection.AtmosphereResponse response)Called when the Atmosphere client side timeout occurs.protected voidonClose(AtmospherePushConnection.AtmosphereResponse response)Called when the push connection has been closed.protected voidonConnect(AtmospherePushConnection.AtmosphereResponse response)Called whenever a server push connection is established (or re-established).protected voidonError(AtmospherePushConnection.AtmosphereResponse response)Called if the push connection fails.protected voidonMessage(AtmospherePushConnection.AtmosphereResponse response)Called whenever a message is received by Atmosphere.protected voidonOpen(AtmospherePushConnection.AtmosphereResponse response)protected voidonReconnect(com.google.gwt.core.client.JavaScriptObject request, AtmospherePushConnection.AtmosphereResponse response)Called when the push connection has lost the connection to the server and will proceed to try to re-establish the connection.protected voidonReopen(AtmospherePushConnection.AtmosphereResponse response)protected voidonTransportFailure()Called if the transport mechanism cannot be used and the fallback will be tried.voidpush(elemental.json.JsonObject message)Pushes a message to the server.
-
-
-
Constructor Detail
-
AtmospherePushConnection
public AtmospherePushConnection(Registry registry)
Creates a new instance connected to the given registry.- Parameters:
registry- the global registry
-
-
Method Detail
-
isActive
public boolean isActive()
Description copied from interface:PushConnectionChecks whether this push connection is in a state where it can push messages to the server. A connection is active untilPushConnection.disconnect(Command)has been called.- Specified by:
isActivein interfacePushConnection- Returns:
trueif this connection can accept new messages;falseif this connection is disconnected or disconnecting.
-
isBidirectional
public boolean isBidirectional()
Description copied from interface:PushConnectionChecks whether this push connection should be used for communication in both directions or if an XHR should be used for client to server communication. A bidirectional push connection must be able to reliably inform about its connection state.- Specified by:
isBidirectionalin interfacePushConnection- Returns:
- true if the push connection should be used for messages in both directions, false if it should only be used for server to client messages
-
push
public void push(elemental.json.JsonObject message)
Description copied from interface:PushConnectionPushes a message to the server. Will throw an exception if the connection is not active (seePushConnection.isActive()).Implementation detail: If the push connection is not connected and the message can thus not be sent, the implementation must call
ConnectionStateHandler.pushNotConnected(JsonObject), which will retry the send later.This method must not be called if the push connection is not bidirectional (if
PushConnection.isBidirectional()returns false)- Specified by:
pushin interfacePushConnection- Parameters:
message- the payload to push- See Also:
PushConnection.isActive()
-
getConfig
protected AtmospherePushConnection.AtmosphereConfiguration getConfig()
-
onReopen
protected void onReopen(AtmospherePushConnection.AtmosphereResponse response)
-
onOpen
protected void onOpen(AtmospherePushConnection.AtmosphereResponse response)
-
onConnect
protected void onConnect(AtmospherePushConnection.AtmosphereResponse response)
Called whenever a server push connection is established (or re-established).- Parameters:
response- the response
-
disconnect
public final void disconnect(Command command)
Description copied from interface:PushConnectionCloses the push connection. To ensure correct message delivery order, new messages should not be sent using any other channel until it has been confirmed that all messages pending for this connection have been delivered. The provided command callback is invoked when messages can be passed using some other communication channel.After this method has been called,
PushConnection.isActive()returnsfalse. Calling this method for a connection that is no longer active will throw an exception.- Specified by:
disconnectin interfacePushConnection- Parameters:
command- command to invoke when the connection has been properly disconnected
-
onMessage
protected void onMessage(AtmospherePushConnection.AtmosphereResponse response)
Called whenever a message is received by Atmosphere.- Parameters:
response- the Atmosphere response object, which contains the message
-
onTransportFailure
protected void onTransportFailure()
Called if the transport mechanism cannot be used and the fallback will be tried.
-
onError
protected void onError(AtmospherePushConnection.AtmosphereResponse response)
Called if the push connection fails.Atmosphere will automatically retry the connection until successful.
- Parameters:
response- the Atmosphere response for the failed connection
-
onClose
protected void onClose(AtmospherePushConnection.AtmosphereResponse response)
Called when the push connection has been closed.This does not necessarily indicate an error and Atmosphere might try to reconnect or downgrade to the fallback transport automatically.
- Parameters:
response- the Atmosphere response which was closed
-
onClientTimeout
protected void onClientTimeout(AtmospherePushConnection.AtmosphereResponse response)
Called when the Atmosphere client side timeout occurs.The connection will be closed at this point and reconnect will not happen automatically.
- Parameters:
response- the Atmosphere response which was used when the timeout occurred
-
onReconnect
protected void onReconnect(com.google.gwt.core.client.JavaScriptObject request, AtmospherePushConnection.AtmosphereResponse response)Called when the push connection has lost the connection to the server and will proceed to try to re-establish the connection.- Parameters:
request- the Atmosphere requestresponse- the Atmosphere response
-
createConfig
protected final AtmospherePushConnection.AtmosphereConfiguration createConfig()
Creates the default Atmosphere configuration object.- Returns:
- the Atmosphere configuration object
-
getTransportType
public String getTransportType()
Description copied from interface:PushConnectionReturns a human readable string representation of the transport type used to communicate with the server.- Specified by:
getTransportTypein interfacePushConnection- Returns:
- A human readable string representation of the transport type
-
-