com.vaadin.ui
Class ConnectorTracker

java.lang.Object
  extended by com.vaadin.ui.ConnectorTracker
All Implemented Interfaces:
java.io.Serializable

public class ConnectorTracker
extends java.lang.Object
implements java.io.Serializable

A class which takes care of book keeping of ClientConnectors 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 ClientConnectors 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 its com.vaadin.client.ServerConnector.

Since:
7.0.0
Author:
Vaadin Ltd
See Also:
Serialized Form

Constructor Summary
ConnectorTracker(UI uI)
          Creates a new ConnectorTracker for the given uI.
 
Method Summary
 void cleanConnectorMap()
          Cleans the connector map from all connectors that are no longer attached to the application.
 ClientConnector getConnector(java.lang.String connectorId)
          Gets a connector by its id.
 org.json.JSONObject getDiffState(ClientConnector connector)
           
 java.util.Collection<ClientConnector> getDirtyConnectors()
          Returns a collection of all connectors which have been marked as dirty.
static java.util.logging.Logger getLogger()
          Gets a logger for this class
 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.
 void registerConnector(ClientConnector connector)
          Register the given connector.
 void setDiffState(ClientConnector connector, org.json.JSONObject diffState)
           
 void setWritingResponse(boolean writingResponse)
          Sets the current response write status.
 void unregisterConnector(ClientConnector connector)
          Unregister the given connector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 a ConnectorTracker.

Parameters:
uI - The uI to attach to. Cannot be null.
Method Detail

getLogger

public static java.util.logging.Logger getLogger()
Gets a logger for this class

Returns:
A logger instance for logging within this class

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(java.lang.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. 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 java.util.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.

getDiffState

public org.json.JSONObject getDiffState(ClientConnector connector)

setDiffState

public void setDiffState(ClientConnector connector,
                         org.json.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.

Parameters:
writingResponse - the new response status.
Throws:
java.lang.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()


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