publicclass ConnectionHandlerextendsThread
Handles a connection from a client to Spanner. This ConnectionHandler uses WireMessage to receive and send all messages from and to the client, using the intermediate
representation IntermediateStatement that servers as a middle layer between Postgres and
Spanner.
Each ConnectionHandler is also a Thread. Although a TCP connection does not
necessarily need to have its own thread, this makes the implementation more straightforward.
Methods
cancelActiveStatement(int connectionId, int secret)
publicbooleancancelActiveStatement(intconnectionId,intsecret)
To be used by a cancellation command to cancel a currently running statement, as contained in a
specific connection identified by connectionId. Since cancellation is a flimsy contract at
best, it is not imperative that the cancellation run, but it should be attempted nonetheless.
| Parameters |
| Name |
Description |
connectionId |
int
The connection whose statement must be cancelled.
|
secret |
int
The secret value linked to the connection that is being cancelled. If it does not
match, we cannot cancel.
|
| Returns |
| Type |
Description |
boolean |
true if the statement was cancelled.
|
publicvoidcleanUp(IntermediateStatementstatement)
Closes portals and statements if the result of an execute was the end of a transaction.
clearActiveCopyStatement()
publicvoidclearActiveCopyStatement()
clearInvalidMessageCount()
publicvoidclearInvalidMessageCount()
Clears the number of invalid messages that was received. This is called whenever a valid
message is encountered.
closeAllPortals()
publicvoidcloseAllPortals()
Closes all named and unnamed portals on this connection.
closeAllStatements()
publicvoidcloseAllStatements()
closePortal(String portalName)
publicvoidclosePortal(StringportalName)
| Parameter |
| Name |
Description |
portalName |
String
|
closeStatement(String statementName)
publicvoidcloseStatement(StringstatementName)
| Parameter |
| Name |
Description |
statementName |
String
|
connectToSpanner(String database, Credentials credentials)
publicvoidconnectToSpanner(Stringdatabase,Credentialscredentials)
| Parameters |
| Name |
Description |
database |
String
|
credentials |
com.google.auth.Credentials
|
getActiveCopyStatement()
publicCopyStatementgetActiveCopyStatement()
getAutoDescribedStatement(String sql)
publicFuture<DescribeResult>getAutoDescribedStatement(Stringsql)
Returns the parameter types of a cached auto-described statement, or null if none is available
in the cache.
| Parameter |
| Name |
Description |
sql |
String
|
getConnectionId()
publicintgetConnectionId()
| Returns |
| Type |
Description |
int |
publicConnectionMetadatagetConnectionMetadata()
getDatabaseId()
publicDatabaseIdgetDatabaseId()
| Returns |
| Type |
Description |
com.google.cloud.spanner.DatabaseId |
getExtendedQueryProtocolHandler()
publicExtendedQueryProtocolHandlergetExtendedQueryProtocolHandler()
getInvalidMessageCount()
publicintgetInvalidMessageCount()
Returns the number of invalid messages that this connection has received in a row. This can for
example happen if a client has initiated a COPY operation and the copy operation fails on the
server. The server will then respond with an error response, but if the client fails to read
that message and continues to send copy data messages, the server could get flooded. This value
is used to detect such a situation and breaks the connection if too many invalid messages in a
row are received.
| Returns |
| Type |
Description |
int |
getPortal(String portalName)
publicIntermediatePortalStatementgetPortal(StringportalName)
| Parameter |
| Name |
Description |
portalName |
String
|
getSecret()
| Returns |
| Type |
Description |
int |
getServer()
publicProxyServergetServer()
getSpannerConnection()
publicConnectiongetSpannerConnection()
getStatement(String statementName)
publicIntermediatePreparedStatementgetStatement(StringstatementName)
| Parameter |
| Name |
Description |
statementName |
String
|
getStatus()
publicsynchronizedConnectionHandler.ConnectionStatusgetStatus()
getWellKnownClient()
publicClientAutoDetector.WellKnownClientgetWellKnownClient()
handleMessages()
publicvoidhandleMessages()
Reads and handles wire-protocol messages. This method is normally only called from this ConnectionHandler, but certain sub-protocols such as the COPY protocol also need to process
messages in line.
handleTerminate()
publicvoidhandleTerminate()
hasPortal(String portalName)
publicbooleanhasPortal(StringportalName)
| Parameter |
| Name |
Description |
portalName |
String
|
hasStatement(String statementName)
publicbooleanhasStatement(StringstatementName)
| Parameter |
| Name |
Description |
statementName |
String
|
increaseInvalidMessageCount()
publicvoidincreaseInvalidMessageCount()
Increases the number of invalid messages that was received in a row by 1.
maybeDetermineWellKnownClient(Statement statement)
publicvoidmaybeDetermineWellKnownClient(Statementstatement)
| Parameter |
| Name |
Description |
statement |
com.google.cloud.spanner.Statement
|
maybeDetermineWellKnownClient(ParseMessage parseMessage)
publicvoidmaybeDetermineWellKnownClient(ParseMessageparseMessage)
publicvoidregisterAutoDescribedStatement(Stringsql,Future<DescribeResult>describeResult)
Stores the parameter types of an auto-described statement in the cache.
publicvoidregisterPortal(StringportalName,IntermediatePortalStatementportal)
publicvoidregisterStatement(StringstatementName,IntermediatePreparedStatementstatement)
run()
Simple runner starts a loop which keeps taking inbound messages, processing them, sending them
to Spanner, getting a result, processing that result, and replying to the client (in that
order). Also instantiates input and output streams from the client and handles auth.
Overrides
setActiveCopyStatement(CopyStatement copyStatement)
publicvoidsetActiveCopyStatement(CopyStatementcopyStatement)
setMessageState(WireMessage message)
publicvoidsetMessageState(WireMessagemessage)
setStatus(ConnectionHandler.ConnectionStatus status)
publicsynchronizedvoidsetStatus(ConnectionHandler.ConnectionStatusstatus)
setWellKnownClient(ClientAutoDetector.WellKnownClient wellKnownClient)
publicvoidsetWellKnownClient(ClientAutoDetector.WellKnownClientwellKnownClient)