Class ConnectorTracker
- java.lang.Object
-
- com.vaadin.ui.ConnectorTracker
-
- All Implemented Interfaces:
Serializable
public class ConnectorTracker extends Object implements Serializable
A class which takes care of book keeping ofClientConnector
s for a UI.Provides
getConnector(String)
which can be used to lookup a connector from its id. This is for framework use only and should not be needed in applications.Tracks which
ClientConnector
s are dirty so they can be updated to the client when the following response is sent. A connector is dirty when an operation has been performed on it on the server and as a result of this operation new information needs to be sent to itsServerConnector
.- Since:
- 7.0.0
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ConnectorTracker(UI uI)
Creates a new ConnectorTracker for the given uI.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMarkedAsDirtyListener(MarkedAsDirtyListener listener)
Adds a marked as dirty listener that will be called when a client connector is marked as dirty.void
addStreamVariable(String connectorId, String variableName, StreamVariable variable)
Adds a StreamVariable of the given name to the indicated connector.void
cleanConnectorMap()
Cleans the connector map from all connectors that are no longer attached to the application.void
cleanStreamVariable(String connectorId, String variableName)
Removes any StreamVariable of the given name from the indicated connector.ClientConnector
getConnector(String connectorId)
Gets a connector by its id.int
getCurrentSyncId()
Gets the most recently generated server sync id.JsonObject
getDiffState(ClientConnector connector)
Collection<ClientConnector>
getDirtyConnectors()
Returns a collection of all connectors which have been marked as dirty.ArrayList<ClientConnector>
getDirtyVisibleConnectors()
Returns a collection of thosedirty connectors
that are actually visible to the client.String
getSeckey(StreamVariable variable)
Returns the security key associated with the given StreamVariable.StreamVariable
getStreamVariable(String connectorId, String variableName)
Checks if the indicated connector has a StreamVariable of the given name and returns the variable if one is found.boolean
hasDirtyConnectors()
Checks if there a dirty connectors.boolean
isClientSideInitialized(ClientConnector connector)
Checks whether the given connector has already been initialized in the browser.boolean
isDirty(ClientConnector connector)
boolean
isWritingResponse()
Checks whether the response is currently being written.void
markAllClientSidesUninitialized()
Marks all currently registered connectors as uninitialized.void
markAllConnectorsClean()
Mark all connectors in this uI as clean.void
markAllConnectorsDirty()
Mark all connectors in this uI as dirty.void
markClean(ClientConnector connector)
Mark the connector as clean.void
markClientSideInitialized(ClientConnector connector)
Marks the given connector as initialized, meaning that the client-side state has been initialized for the connector.void
markDirty(ClientConnector connector)
Mark the connector as dirty and notifies any marked as dirty listeners.void
notifyMarkedAsDirtyListeners(ClientConnector connector)
Notify all registered MarkedAsDirtyListeners the given client connector has been marked as dirty.void
registerConnector(ClientConnector connector)
Register the given connector.void
removeMarkedAsDirtyListener(MarkedAsDirtyListener listener)
Removes a marked as dirty listener.void
setDiffState(ClientConnector connector, JsonObject diffState)
void
setWritingResponse(boolean writingResponse)
Sets the current response write status.void
unregisterConnector(ClientConnector connector)
Unregister the given connector.
-
-
-
Constructor Detail
-
ConnectorTracker
public ConnectorTracker(UI uI)
Creates a new ConnectorTracker for the given uI. A tracker is always attached to a uI and the uI cannot be changed during the lifetime of aConnectorTracker
.- Parameters:
uI
- The uI to attach to. Cannot be null.
-
-
Method Detail
-
registerConnector
public void registerConnector(ClientConnector connector)
Register the given connector.The lookup method
getConnector(String)
only returns registered connectors.- Parameters:
connector
- The connector to register.
-
unregisterConnector
public void unregisterConnector(ClientConnector connector)
Unregister the given connector.The lookup method
getConnector(String)
only returns registered connectors.- Parameters:
connector
- The connector to unregister
-
isClientSideInitialized
public boolean isClientSideInitialized(ClientConnector connector)
Checks whether the given connector has already been initialized in the browser. The given connector should be registered with this connector tracker.- Parameters:
connector
- the client connector to check- Returns:
true
if the initial state has previously been sent to the browser,false
if the client-side doesn't already know anything about the connector.
-
markClientSideInitialized
public void markClientSideInitialized(ClientConnector connector)
Marks the given connector as initialized, meaning that the client-side state has been initialized for the connector.- Parameters:
connector
- the connector that should be marked as initialized- See Also:
isClientSideInitialized(ClientConnector)
-
markAllClientSidesUninitialized
public void markAllClientSidesUninitialized()
Marks all currently registered connectors as uninitialized. This should be done when the client-side has been reset but the server-side state is retained.- See Also:
isClientSideInitialized(ClientConnector)
-
getConnector
public ClientConnector getConnector(String connectorId)
Gets a connector by its id.- Parameters:
connectorId
- The connector id to look for- Returns:
- The connector with the given id or null if no connector has the given id
-
cleanConnectorMap
public void cleanConnectorMap()
Cleans the connector map from all connectors that are no longer attached to the application. This should only be called by the framework.
-
markDirty
public void markDirty(ClientConnector connector)
Mark the connector as dirty and notifies any marked as dirty listeners. This should not be done while the response is being written.- Parameters:
connector
- The connector that should be marked clean.- See Also:
getDirtyConnectors()
,isWritingResponse()
-
markClean
public void markClean(ClientConnector connector)
Mark the connector as clean.- Parameters:
connector
- The connector that should be marked clean.
-
markAllConnectorsDirty
public void markAllConnectorsDirty()
Mark all connectors in this uI as dirty.
-
markAllConnectorsClean
public void markAllConnectorsClean()
Mark all connectors in this uI as clean.
-
getDirtyConnectors
public Collection<ClientConnector> getDirtyConnectors()
Returns a collection of all connectors which have been marked as dirty.The state and pending RPC calls for dirty connectors are sent to the client in the following request.
- Returns:
- A collection of all dirty connectors for this uI. This list may contain invisible connectors.
-
hasDirtyConnectors
public boolean hasDirtyConnectors()
Checks if there a dirty connectors.- Returns:
- true if there are dirty connectors, false otherwise
-
getDirtyVisibleConnectors
public ArrayList<ClientConnector> getDirtyVisibleConnectors()
Returns a collection of thosedirty connectors
that are actually visible to the client.- Returns:
- A list of dirty and visible connectors.
-
getDiffState
public JsonObject getDiffState(ClientConnector connector)
-
setDiffState
public void setDiffState(ClientConnector connector, JsonObject diffState)
-
isDirty
public boolean isDirty(ClientConnector connector)
-
isWritingResponse
public boolean isWritingResponse()
Checks whether the response is currently being written. Connectors can not be marked as dirty when a response is being written.- Returns:
true
if the response is currently being written,false
if outside the response writing phase.- See Also:
setWritingResponse(boolean)
,markDirty(ClientConnector)
-
setWritingResponse
public void setWritingResponse(boolean writingResponse)
Sets the current response write status. Connectors can not be marked as dirty when the response is written.This method has a side-effect of incrementing the sync id by one (see
getCurrentSyncId()
), ifisWritingResponse()
returnstrue
andwritingResponse
is set tofalse
.- Parameters:
writingResponse
- the new response status.- Throws:
IllegalArgumentException
- if the new response status is the same as the previous value. This is done to help detecting problems caused by missed invocations of this method.- See Also:
markDirty(ClientConnector)
,isWritingResponse()
,getCurrentSyncId()
-
getStreamVariable
public StreamVariable getStreamVariable(String connectorId, String variableName)
Checks if the indicated connector has a StreamVariable of the given name and returns the variable if one is found.- Parameters:
connectorId
-variableName
-- Returns:
- variable if a matching one exists, otherwise null
-
addStreamVariable
public void addStreamVariable(String connectorId, String variableName, StreamVariable variable)
Adds a StreamVariable of the given name to the indicated connector.- Parameters:
connectorId
-variableName
-variable
-
-
cleanStreamVariable
public void cleanStreamVariable(String connectorId, String variableName)
Removes any StreamVariable of the given name from the indicated connector.- Parameters:
connectorId
-variableName
-
-
getSeckey
public String getSeckey(StreamVariable variable)
Returns the security key associated with the given StreamVariable.- Parameters:
variable
-- Returns:
- matching security key if one exists, null otherwise
-
getCurrentSyncId
public int getCurrentSyncId()
Gets the most recently generated server sync id.The sync id is incremented by one whenever a new response is being written. This id is then sent over to the client. The client then adds the most recent sync id to each communication packet it sends back to the server. This way, the server knows at what state the client is when the packet is sent. If the state has changed on the server side since that, the server can try to adjust the way it handles the actions from the client side.
The sync id value
-1
is ignored to facilitate testing with pre-recorded requests.- Returns:
- the current sync id
- Since:
- 7.2
- See Also:
setWritingResponse(boolean)
,#connectorWasPresentAsRequestWasSent(String, long)
-
addMarkedAsDirtyListener
public void addMarkedAsDirtyListener(MarkedAsDirtyListener listener)
Adds a marked as dirty listener that will be called when a client connector is marked as dirty.- Parameters:
listener
- listener to add- Since:
- 7.7.14
-
removeMarkedAsDirtyListener
public void removeMarkedAsDirtyListener(MarkedAsDirtyListener listener)
Removes a marked as dirty listener.- Parameters:
listener
- listener to remove- Since:
- 7.7.14
-
notifyMarkedAsDirtyListeners
public void notifyMarkedAsDirtyListeners(ClientConnector connector)
Notify all registered MarkedAsDirtyListeners the given client connector has been marked as dirty.- Parameters:
connector
- client connector marked as dirty- Since:
- 7.7.14
-
-