Class AtmospherePushConnection
java.lang.Object
com.vaadin.flow.server.communication.AtmospherePushConnection
- All Implemented Interfaces:
FragmentedMessageHolder,PushConnection,Serializable
public class AtmospherePushConnection
extends Object
implements PushConnection, FragmentedMessageHolder
A
PushConnection implementation using the Atmosphere push support
that is by default included in Vaadin.
For internal use only. May be renamed or removed in a future release.
- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a message that can arrive as multiple fragments.protected static enum -
Constructor Summary
ConstructorsConstructorDescriptionCreates an instance connected to the given UI. -
Method Summary
Modifier and TypeMethodDescriptionvoidclearFragmentedMessage(org.atmosphere.cpr.AtmosphereResource resource) Clears the partial message that is currently being received.voidconnect(org.atmosphere.cpr.AtmosphereResource resource) Associates thisAtmospherePushConnectionwith the givenAtmosphereResourcerepresenting an established push connection.voidCalled when the connection to the client has been lost.voidCloses the connection.static voidInternal method used for reconfiguring loggers to show all Atmosphere log messages in the console.static StringGets the Atmosphere version in use, as reported byVersion.getRawVersion().getOrCreateFragmentedMessage(org.atmosphere.cpr.AtmosphereResource resource) Gets the partial message that is currently being received, if any.protected org.atmosphere.cpr.AtmosphereResourceprotected AtmospherePushConnection.StategetState()Returns the state of this connection.protected UIgetUI()booleanReturns whether this connection is currently open.voidpush()Pushes pending state changes and client RPC calls to the client.voidpush(boolean async) Pushes pending state changes and client RPC calls to the client.protected static ReaderreceiveMessage(org.atmosphere.cpr.AtmosphereResource resource, Reader reader, FragmentedMessageHolder holder) Reads and buffers a (possibly partial) message.protected voidsendMessage(String message) Sends the given message to the current client.
-
Constructor Details
-
AtmospherePushConnection
Creates an instance connected to the given UI.- Parameters:
ui- the UI to which this connection belongs
-
-
Method Details
-
getAtmosphereVersion
Gets the Atmosphere version in use, as reported byVersion.getRawVersion().- Returns:
- the Atmosphere version in use or null if Atmosphere was not found
-
push
public void push()Description copied from interface:PushConnectionPushes pending state changes and client RPC calls to the client. Can be called even ifPushConnection.isConnected()is false; the push will be deferred until a connection is available. It is NOT safe to invoke this method if not holding the session lock.This is internal API; please use
UI.push()instead.- Specified by:
pushin interfacePushConnection
-
push
public void push(boolean async) Pushes pending state changes and client RPC calls to the client. IfisConnected()is false, defers the push until a connection is established.- Parameters:
async- True if this push asynchronously originates from the server, false if it is a response to a client request.
-
sendMessage
Sends the given message to the current client. Cannot be called ifisConnected()returns false.- Parameters:
message- The message to send
-
receiveMessage
protected static Reader receiveMessage(org.atmosphere.cpr.AtmosphereResource resource, Reader reader, FragmentedMessageHolder holder) throws IOException Reads and buffers a (possibly partial) message. If a complete message was received, or if the call resulted in the completion of a partially received message, returns aReaderyielding the complete message. Otherwise, returns null.- Parameters:
resource- The atmosphere resource with datareader- The request body readerholder- A holder for a previously received partial message- Returns:
- A Reader yielding a complete message or null if the message is not yet complete.
- Throws:
IOException- if an IO error occurred
-
isConnected
public boolean isConnected()Description copied from interface:PushConnectionReturns whether this connection is currently open.- Specified by:
isConnectedin interfacePushConnection- Returns:
- true if the connection is open, false otherwise
-
connect
public void connect(org.atmosphere.cpr.AtmosphereResource resource) Associates thisAtmospherePushConnectionwith the givenAtmosphereResourcerepresenting an established push connection. If already connected, callsdisconnect()first. If there is a deferred push, carries it out via the new connection.- Parameters:
resource- the resource to associate this connection with
-
getUI
- Returns:
- the UI associated with this connection.
-
getResource
protected org.atmosphere.cpr.AtmosphereResource getResource()- Returns:
- The AtmosphereResource associated with this connection or null if connection not open.
-
disconnect
public void disconnect()Description copied from interface:PushConnectionCloses the connection. Cannot be called ifPushConnection.isConnected()is false.- Specified by:
disconnectin interfacePushConnection
-
connectionLost
public void connectionLost()Called when the connection to the client has been lost. -
getOrCreateFragmentedMessage
public AtmospherePushConnection.FragmentedMessage getOrCreateFragmentedMessage(org.atmosphere.cpr.AtmosphereResource resource) Description copied from interface:FragmentedMessageHolderGets the partial message that is currently being received, if any.- Specified by:
getOrCreateFragmentedMessagein interfaceFragmentedMessageHolder- Parameters:
resource- the resource to get the partial message from- Returns:
- the fragmented message being received or a new empty instance
-
clearFragmentedMessage
public void clearFragmentedMessage(org.atmosphere.cpr.AtmosphereResource resource) Description copied from interface:FragmentedMessageHolderClears the partial message that is currently being received. Should be called when the whole message has been received.- Specified by:
clearFragmentedMessagein interfaceFragmentedMessageHolder- Parameters:
resource- the related resource
-
getState
Returns the state of this connection.- Returns:
- the state of this connection
-
enableAtmosphereDebugLogging
public static void enableAtmosphereDebugLogging()Internal method used for reconfiguring loggers to show all Atmosphere log messages in the console.
-