net.BrowserChannel Extends Object
Encapsulates the logic for a single BrowserChannel.

Inheritance

Constructor

goog.net.BrowserChannel(clientVersion)

Parameters

clientVersion :
An application-specific version number that is sent to the server when connected.

Instance Methods

Public Protected Private
addAdditionalParams_(uri)
Adds the additional parameters from the handler to the given URI.
Arguments:
uri :
(goog.Uri | null)
The URI to add the parameters to.
code »
cancelRequests_()
Cancels all outstanding requests.
code »
clearDeadBackchannelTimer_()
Clears the timer that indicates that our backchannel is no longer able to successfully receive data from the server.
code »
connect(testPathchannelPathextraParamsopt_oldSessionIdopt_oldArrayId)
Starts the channel. This initiates connections to the server.
Arguments:
testPath :
The path for the test connection.
channelPath :
The path for the channel connection.
extraParams :
(Object | null)
Extra parameter keys and values to add to the requests.
opt_oldSessionId :
(string | undefined)
Session ID from a previous session.
opt_oldArrayId :
(number | undefined)
The last array ID from a previous session.
code »
connectChannel_()
Starts the regular channel which is run after the test channel is complete.
code »
connectTest_(testPath)
Starts the test channel to determine network conditions.
Arguments:
testPath :
The relative PATH for the test connection.
code »
correctHostPrefix(serverHostPrefix)
(null | string)
Decides which host prefix should be used, if any. If there is a handler, allows the handler to validate a host prefix provided by the server, and optionally override it.
Arguments:
serverHostPrefix :
(null | string)
The host prefix provided by the server.
Returns: 
(null | string)
  The host prefix to actually use, if any. Will return null if the use of host prefixes was disabled via setAllowHostPrefix().
code »
createDataUri(hostPrefixpathopt_overridePort)
(goog.Uri | null)
Creates a data Uri applying logic for secondary hostprefix, port overrides, and versioning.
Arguments:
hostPrefix :
(null | string)
The host prefix.
path :
The path on the host (may be absolute or relative).
opt_overridePort :
(number | undefined)
Optional override port.
Returns: 
(goog.Uri | null)
  The data URI.
code »
createXhrIo(hostPrefix)
Called when BC needs to create an XhrIo object. Override in a subclass if you need to customize the behavior, for example to enable the creation of XHR's capable of calling a secondary domain.
Arguments:
hostPrefix :
(null | string)
The host prefix, if we need an XhrIo object capable of calling a secondary domain.
Returns:   A new XhrIo object.
code »
dequeueOutgoingMaps_()
Returns the request text from the outgoing maps and resets it.
Returns:   The encoded request text created from all the currently queued outgoing maps.
code »
disconnect()
Disconnects and closes the channel.
code »
ensureBackChannel_()
Ensures there is a backchannel request for receiving data from the server.
code »
ensureForwardChannel_()
Ensures that a forward channel request is scheduled.
code »
ensureInState_(var_args)
Helper to ensure the BrowserChannel is in the expected state.
Arguments:
var_args :
(number | undefined)
The channel must be in one of the indicated states.
code »
getAllowChunkedMode()
Returns whether chunked mode is allowed. In certain debugging situations, it's useful for the application to have a way to disable chunked mode for a user.
Returns:   Whether chunked mode is allowed.
code »
getAllowHostPrefix()
Returns whether the channel allows the use of a subdomain. There may be cases where this isn't allowed.
Returns:   Whether a host prefix is allowed.
code »
getBackChannelMaxRetries()
No description.
Returns:   The max number of back-channel retries, which is a constant.
code »
getBackChannelUri(hostPrefixpath)
(goog.Uri | null)
Gets the Uri used for the connection that receives data from the server.
Arguments:
hostPrefix :
(null | string)
The host prefix.
path :
The path on the host.
Returns: 
(goog.Uri | null)
  The back channel URI.
code »
getChannelDebug()
Returns the browserchannel logger.
Returns:   The channel debug object.
code »
getExtraHeaders()
(Object | null)
Returns the extra HTTP headers to add to all the requests sent to the server.
Returns: 
(Object | null)
  The HTTP headers, or null.
code »
getForwardChannelMaxRetries()
No description.
Returns:   The max number of forward-channel retries, which will be 0 in fail-fast mode.
code »
getForwardChannelUri(path)
(goog.Uri | null)
Gets the Uri used for the connection that sends data to the server.
Arguments:
path :
The path on the host.
Returns: 
(goog.Uri | null)
  The forward channel URI.
code »
getHandler()
Returns the handler used for channel callback events.
Returns:   The handler.
code »
getLastArrayId()
No description.
Returns:   The last array id received.
code »
getLastStatusCode()
Return the last status code received for a request.
Returns:   The last status code received for a request.
code »
getRetryTime_(retryCount)
No description.
Arguments:
retryCount :
Number of retries so far.
Returns:   Time in ms before firing next retry request.
code »
getSessionId()
Returns the session id of the channel. Only available after the channel has been opened.
Returns:   Session ID.
code »
getState()
goog.net.BrowserChannel.State.<number>
Returns the browser channel state.
Returns: 
goog.net.BrowserChannel.State.<number>
  The current state of the browser channel.
code »
handleBackchannelMissing_()
Handles a POST response from the server telling us that it has detected that we have no hanging GET connection.
code »
handlePostResponse_(responseValues)
Handles a POST response from the server.
Arguments:
responseValues :
(Array | null)
The key value pairs in the POST response.
code »
hasOutstandingRequests()
Returns whether there are outstanding requests servicing the channel.
Returns:   true if there are outstanding requests.
code »
isActive()
Gets whether this channel is currently active. This is used to determine the length of time to wait before retrying. This call delegates to the handler.
Returns:   Whether the channel is currently active.
code »
isBuffered()
Returns whether the channel is buffered or not. This state is valid for querying only after the test connection has completed. This may be queried in the goog.net.BrowserChannel.okToMakeRequest() callback. A channel may be buffered if the test connection determines that a chunked response could not be sent down within a suitable time.
Returns:   Whether the channel is buffered.
code »
isClosed()
Returns whether the channel is closed
Returns:   true if the channel is closed.
code »
makeForwardChannelRequest_(opt_retryRequest)
Makes a forward channel request using XMLHTTP.
Arguments:
opt_retryRequest :
(goog.net.ChannelRequest | null | undefined)
A failed request to retry.
code »
maybeRetryBackChannel_()
Schedules a back-channel retry, unless the max retries has been reached.
Returns:   true iff a retry was scheduled.
code »
maybeRetryForwardChannel_(request)
Schedules a forward-channel retry for the specified request, unless the max retries has been reached.
Arguments:
request :
The failed request to retry.
Returns:   true iff a retry was scheduled.
code »
okToMakeRequest_()
Gives the handler a chance to return an error code and stop channel execution. A handler might want to do this to check that the user is still logged in, for example.
Returns:   If it's OK to make a request.
code »
onBackChannelDead_()
Handles the timer that indicates that our backchannel is no longer able to successfully receive data from the server.
code »
onClose_()
Called when the channel has been closed. It notifiers the handler of the event, and reports any pending or undelivered maps.
code »
onError_(error)
Called when we've determined the final error for a channel. It closes the notifiers the handler of the error and closes the channel.
Arguments:
error :
goog.net.BrowserChannel.Error.<number>
The error code for the failure.
code »
onInput_(respArray)
Processes the data returned by the server.
Arguments:
respArray :
(Array | null)
The response array returned by the server.
code »
onRequestComplete(request)
Callback from ChannelRequest that indicates a request has completed.
Arguments:
request :
The request object.
code »
onRequestData(requestresponseText)
Callback from ChannelRequest for when new data is received
Arguments:
request :
The request object.
responseText :
The text of the response.
code »
onStartBackChannelTimer_()
Timer callback for ensureBackChannel_.
code »
onStartForwardChannelTimer_(opt_retryRequest)
Timer callback for ensureForwardChannel
Arguments:
opt_retryRequest :
(goog.net.ChannelRequest | null | undefined)
A failed request to retry.
code »
open_()
Establishes a new channel session with the the server.
code »
outstandingRequests_()
Returns the number of outstanding requests.
Returns:   The number of outstanding requests to the server.
code »
requeuePendingMaps_()
Requeues unacknowledged sent arrays for retransmission in the next forward channel request.
code »
sendMap(map)
Sends a request to the server. The format of the request is a Map data structure of key/value pairs. These maps are then encoded in a format suitable for the wire and then reconstituted as a Map data structure that the server can process.
Arguments:
map :
(Object | null)
The map to send.
code »
setAllowChunkedMode(allowChunkedMode)
Sets whether chunked mode is allowed. In certain debugging situations, it's useful for the application to have a way to disable chunked mode for a user.
Arguments:
allowChunkedMode :
Whether chunked mode is allowed.
code »
setAllowHostPrefix(allowHostPrefix)
Sets whether the channel allows the use of a subdomain. There may be cases where this isn't allowed, for example, logging in with troutboard where using a subdomain causes Apache to force the user to authenticate twice.
Arguments:
allowHostPrefix :
Whether a host prefix is allowed.
code »
setChannelDebug(channelDebug)
Set the browserchannel logger. TODO(user): Add interface for channel loggers or remove this function.
Arguments:
channelDebug :
The channel debug object.
code »
setExtraHeaders(extraHeaders)
Sets extra HTTP headers to add to all the requests sent to the server.
Arguments:
extraHeaders :
(Object | null)
The HTTP headers, or null.
code »
setFailFast(failFast)
When set to true, this changes the behavior of the forward channel so it will not retry requests; it will fail after one network failure, and if there was already one network failure, the request will fail immediately.
Arguments:
failFast :
Whether or not to fail fast.
code »
setHandler(handler)
Sets the handler used for channel callback events.
Arguments:
handler :
The handler to set.
code »
shouldRetryBackChannel_(outstandingBytes)
Determines whether we should start the process of retrying a possibly dead backchannel.
Arguments:
outstandingBytes :
The number of bytes for which the server has not yet received acknowledgement.
Returns:   Whether to start the backchannel retry timer.
code »
shouldUseSecondaryDomains()
Determines whether to use a secondary domain when the server gives us a host prefix. This allows us to work around browser per-domain connection limits. Currently, we only use secondary domains when using Trident's ActiveXObject, because it supports cross-domain requests out of the box. Even if we wanted to use secondary domains on Gecko/Webkit, they wouldn't work due to security restrictions on cross-origin XHRs. If you need to use secondary domains on other browsers, you'll need to override this method in a subclass, and make sure that those browsers use some messaging mechanism that works cross-domain.
Returns:   Whether to use secondary domains.
code »
signalError_(error)
Signals an error has occurred.
Arguments:
error :
goog.net.BrowserChannel.Error.<number>
The error code for the failure.
code »
startBackChannel_()
Begins a new back channel operation to the server.
code »
startForwardChannel_(opt_retryRequest)
Begins a new forward channel operation to the server.
Arguments:
opt_retryRequest :
(goog.net.ChannelRequest | null | undefined)
A failed request to retry.
code »
testConnectionBlocked(testChannel)
Callback from BrowserTestChannel for when the channel is blocked.
Arguments:
testChannel :
The BrowserTestChannel.
code »
testConnectionFailure(testChannelerrorCode)
Callback from BrowserTestChannel for when the channel has an error.
Arguments:
testChannel :
The BrowserTestChannel.
errorCode :
goog.net.ChannelRequest.Error.<number>
The error code of the failure.
code »
testConnectionFinished(testChanneluseChunked)
Callback from BrowserTestChannel for when the channel is finished.
Arguments:
testChannel :
The BrowserTestChannel.
useChunked :
Whether we can chunk responses.
code »
testGoogleComCallback_(networkUp)
Callback for testGoogleCom during error handling.
Arguments:
networkUp :
Whether the network is up.
code »

Instance Properties

backChannelAttemptId_ :
The attempt id for the current back channel request. Starts at 1 and increments for each reconnect. The server uses this to log if our connection is flaky or not.
Code »
backChannelRequest_ :
The ChannelRequest object for the backchannel.
Code »
backChannelRetryCount_ :
Number of times it a row that we have retried the current back channel request and received no data.
Code »
backChannelTimerId_ :
(null | number)
Timer identifier for asynchronously making a back channel request.
Code »
backChannelUri_ :
(goog.Uri | null)
The absolute URI for the backchannel request.
Code »
channelDebug_ :
The channel debug used for browserchannel logging
Code »
channelVersion_ :
The channel version that we negotiated with the server for this session. Starts out as the version we request, and then is changed to the negotiated version after the initial open.
Code »
clientVersion_ :
The application specific version that is passed to the server.
Code »
connectionTest_ :
The BrowserTestChannel object which encapsulates the logic for determining interesting network conditions about the client.
Code »
deadBackChannelTimerId_ :
(null | number)
Timer identifier for the timer that waits for us to retry the backchannel in the case where it is dead and no longer receiving data.
Code »
extraHeaders_ :
(Object | null)
Extra HTTP headers to add to all the requests sent to the server.
Code »
extraParams_ :
(Object | null)
Extra parameters to add to all the requests sent to the server.
Code »
failFast_ :
Whether to fail forward-channel requests after one try, or after a few tries.
Code »
forwardChannelRequest_ :
The current ChannelRequest object for the forwardchannel.
Code »
forwardChannelRetryCount_ :
Number of times we have retried the current forward channel request.
Code »
forwardChannelTimerId_ :
(null | number)
Timer identifier for asynchronously making a forward channel request.
Code »
forwardChannelUri_ :
(goog.Uri | null)
The absolute URI for the forwardchannel request.
Code »
handler_ :
The handler that receive callbacks for state changes and data.
Code »
hostPrefix_ :
(null | string)
A subdomain prefix for using a subdomain in IE for the backchannel requests.
Code »
lastArrayId_ :
The array identifier of the last array received from the server for the backchannel request.
Code »
lastPostResponseArrayId_ :
The array identifier of the last array sent by the server that we know about.
Code »
lastStatusCode_ :
The last status code received.
Code »
nextMapId_ :
The id to use for the next outgoing map. This identifier uniquely identifies a sent map.
Code »
nextRid_ :
The next id to use for the RID (request identifier) parameter. This identifier uniquely identifies the forward channel request.
Code »
outgoingMaps_ :
(Array | null)
An array of queued maps that need to be sent to the server.
Code »
path_ :
(null | string)
The relative path (in the context of the the page hosting the browser channel) for making requests to the server.
Code »
pendingMaps_ :
(Array | null)
An array of dequeued maps that we have either received a non-successful response for, or no response at all, and which therefore may or may not have been received by the server.
Code »
state_ :
goog.net.BrowserChannel.State.<number>
The current state of the BrowserChannel. It should be one of the goog.net.BrowserChannel.State constants.
Code »
useChunked_ :
(boolean | null)
Whether the client's network conditions can support chunked responses.
Code »

Static Methods

goog.net.BrowserChannel.createChannelRequest(channelchannelDebugopt_sessionIdopt_requestIdopt_retryId)
Instantiates a ChannelRequest with the given parameters. Overidden in tests.
Arguments:
channel :
The BrowserChannel that owns this request.
channelDebug :
A ChannelDebug to use for logging.
opt_sessionId :
(string | undefined)
The session id for the channel.
opt_requestId :
(number | string | undefined)
The request id for this request.
opt_retryId :
(number | undefined)
The retry id for this request.
Returns:   The created channel request.
code »
goog.net.BrowserChannel.getStatEventTarget()
Returns the singleton event target for stat events.
Returns:   The event target for stat events.
code »
goog.net.BrowserChannel.isFatalError_(errorstatusCode)
Returns whether or not the given error/status combination is fatal or not. On fatal errors we immediately close the session rather than retrying the failed request.
Arguments:
error :
(goog.net.ChannelRequest.Error.<number> | null)
The error code for the failed request.
statusCode :
The last HTTP status code.
Returns:   Whether or not the error is fatal.
code »
goog.net.BrowserChannel.notifyStatEvent(stat)
Helper function to call the stat event callback.
Arguments:
stat :
goog.net.BrowserChannel.Stat.<number>
The stat.
code »
goog.net.BrowserChannel.notifyTimingEvent(sizerttretries)
Helper function to notify listeners about POST request performance.
Arguments:
size :
Number of characters in the POST data.
rtt :
The amount of time from POST start to response.
retries :
The number of times the POST had to be retried.
code »
goog.net.BrowserChannel.onEndExecution()
Helper function to call the end hook
code »
goog.net.BrowserChannel.onStartExecution()
Helper function to call the start hook
code »
goog.net.BrowserChannel.setEndThreadExecutionHook(endHook)
Allows the application to set an execution hooks for when BrowserChannel stops processing requests. This is useful to track timing or logging special information. The function takes no parameters and return void.
Arguments:
endHook :
(Function | null)
The function for the end hook.
code »
goog.net.BrowserChannel.setStartThreadExecutionHook(startHook)
Allows the application to set an execution hooks for when BrowserChannel starts processing requests. This is useful to track timing or logging special information. The function takes no parameters and return void.
Arguments:
startHook :
(Function | null)
The function for the start hook.
code »
goog.net.BrowserChannel.setTimeout(fnms)
Wrapper around SafeTimeout which calls the start and end execution hooks with a try...finally block.
Arguments:
fn :
(Function | null)
The callback function.
ms :
The time in MS for the timer.
Returns:   The ID of the timer.
code »

Static Properties

goog.net.BrowserChannel.BACK_CHANNEL_MAX_RETRIES :
Maximum number of attempts to connect to the server for back channel requests.
Code »
goog.net.BrowserChannel.Event :
(Object | null)
Events fired by BrowserChannel and associated objects
Code »
goog.net.BrowserChannel.FORWARD_CHANNEL_MAX_RETRIES :
Maximum number of attempts to connect to the server for forward channel requests.
Code »
goog.net.BrowserChannel.FORWARD_CHANNEL_RETRY_TIMEOUT :
The timeout in milliseconds for a forward channel request.
Code »
goog.net.BrowserChannel.INACTIVE_CHANNEL_RETRY_FACTOR :
When retrying for an inactive channel, we will multiply the total delay by this number.
Code »
goog.net.BrowserChannel.LATEST_CHANNEL_VERSION :
The latest protocol version that this class supports. We request this version from the server when opening the connection. Should match com.google.net.browserchannel.BrowserChannel.LATEST_CHANNEL_VERSION.
Code »
goog.net.BrowserChannel.MAGIC_RESPONSE_COOKIE :
The normal response for forward channel requests. Used only before version 8 of the protocol.
Code »
goog.net.BrowserChannel.MAX_MAPS_PER_REQUEST_ :
The maximum number of maps that can be sent in one POST. Should match com.google.net.browserchannel.BrowserChannel.MAX_MAPS_PER_REQUEST.
Code »
goog.net.BrowserChannel.OUTSTANDING_DATA_BACKCHANNEL_RETRY_CUTOFF :
A guess at a cutoff at which to no longer assume the backchannel is dead when we are slow to receive data. Number in bytes. Assumption: The worst bandwidth we work on is 50 kilobits/sec 50kbits/sec * (1 byte / 8 bits) * 6 sec dead backchannel timeout
Code »
goog.net.BrowserChannel.RETRY_DELAY_MS :
Default timeout in MS before the initial retry. Subsequent retries will be slower.
Code »
goog.net.BrowserChannel.RETRY_DELAY_SEED :
We will add a random time between 0 and this number of MS to retries to the retry time for this request.
Code »
goog.net.BrowserChannel.RTT_ESTIMATE :
A number in MS of how long we guess the maxmium amount of time a round trip to the server should take. In the future this could be substituted with a real measurement of the RTT.
Code »
goog.net.BrowserChannel.endExecutionHook_ :
(Function | null)
Application provided execution hook for the end hook.
Code »
goog.net.BrowserChannel.startExecutionHook_ :
(Function | null)
Application provided execution hook for the start hook.
Code »
goog.net.BrowserChannel.statEventTarget_ :
Singleton event target for firing stat events
Code »

Enumerations

goog.net.BrowserChannel.ChannelType_ :
Internal enum type for the two browser channel channel types.
Constants:
FORWARD_CHANNEL
No description.
BACK_CHANNEL
No description.
Code »
goog.net.BrowserChannel.Error :
Enum type for identifying a BrowserChannel error.
Constants:
OK
Value that indicates no error has occurred.
NO_DATA
An error due to server response which contains no data.
UNKNOWN_SESSION_ID
An error due to a server response indicating an unknown session id
REQUEST_FAILED
An error due to a request failing.
BAD_RESPONSE
An error due to a response that doesn't start with the magic cookie.
LOGGED_OUT
An error due to the user being logged out.
BAD_DATA
An error due to bad data being returned from the server.
NETWORK
A general network error.
STOP
An error due to a server response requesting to stop the channel.
BLOCKED
An error due to the channel being blocked by a network administrator.
Code »
goog.net.BrowserChannel.Stat :
Enum that identifies events for statistics that are interesting to track. TODO(user) - Change name not to use Event or use EventTarget
Constants:
REQUEST_NO_DATA
Event indicating no data was received when data was expected.
BACKCHANNEL_DEAD
Event indicating that we have determined that our hanging GET is not receiving data when it should be. Thus it is dead dead and will be retried.
TEST_STAGE_ONE_FAILED
Event indicating stage one of the test request failed.
TEST_STAGE_TWO_DATA_ONE
Event indicating the first piece of test data was received.
TEST_STAGE_TWO_DATA_TWO
Event indicating that the second piece of test data was received and it was recieved separately from the first.
CONNECT_ATTEMPT
Event indicating a new connection attempt.
ERROR_NETWORK
Event indicating a connection error due to a general network problem.
TEST_STAGE_TWO_FAILED
Event indicating stage two of the test request failed.
PROXY
Event indicating that a buffering proxy is likely between the client and the server.
BACKCHANNEL_MISSING
Event indicating that the server never received our hanging GET and so it is being retried.
TEST_STAGE_TWO_START
Event indicating the start of test stage two.
NOPROXY
Event indicating that no buffering proxy is likely between the client and the server.
REQUEST_BAD_STATUS
Event indicating a bad status code was received.
CHANNEL_BLOCKED
Event indicating the channel is blocked by a network administrator.
REQUEST_BAD_DATA
Event indicating bad data was received
REQUEST_INCOMPLETE_DATA
Event indicating incomplete data was received
REQUEST_UNKNOWN_SESSION_ID
Event indicating an unknown SID error.
REQUEST_TIMEOUT
Event indicating a request timeout.
TEST_STAGE_TWO_DATA_BOTH
Event indicating both pieces of test data were received simultaneously.
ERROR_OTHER
Event indicating a connection error that isn't due to a general network problem.
TEST_STAGE_ONE_START
Event indicating the start of test stage one.
Code »
goog.net.BrowserChannel.State :
Enum type for the browser channel state machine.
Constants:
CLOSED
The channel is closed.
OPENING
The channel is in the process of opening a connection to the server.
OPENED
The channel is open.
INIT
The channel has been initialized but hasn't yet initiated a connection.
Code »

Package net

Package Reference