Class ConnectionHandler (0.15.0)
Stay organized with collections
Save and categorize content based on your preferences.
publicclass ConnectionHandlerextendsThreadHandles 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.
Inherited Members
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.
secret
int The secret value linked to the connection that is being cancelled. If it does not match, we cannot cancel.
boolean
true if the statement was cancelled.
cleanUp(IntermediateStatement statement)
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.
closeAllStatements()
publicvoidcloseAllStatements()closePortal(String portalName)
publicvoidclosePortal(StringportalName)closeStatement(String statementName)
publicvoidcloseStatement(StringstatementName)connectToSpanner(String database, Credentials credentials)
publicvoidconnectToSpanner(Stringdatabase,Credentialscredentials)credentials
com.google.auth.CredentialsgetActiveCopyStatement()
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.
getConnectionId()
publicintgetConnectionId()getConnectionMetadata()
publicConnectionMetadatagetConnectionMetadata()getDatabaseId()
publicDatabaseIdgetDatabaseId()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.
getPortal(String portalName)
publicIntermediatePortalStatementgetPortal(StringportalName)getSecret()
publicintgetSecret()getServer()
publicProxyServergetServer()getSpannerConnection()
publicConnectiongetSpannerConnection()getStatement(String statementName)
publicIntermediatePreparedStatementgetStatement(StringstatementName)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()Called when a Terminate message is received. This closes this ConnectionHandler.
hasPortal(String portalName)
publicbooleanhasPortal(StringportalName)hasStatement(String statementName)
publicbooleanhasStatement(StringstatementName)increaseInvalidMessageCount()
publicvoidincreaseInvalidMessageCount()Increases the number of invalid messages that was received in a row by 1.
maybeDetermineWellKnownClient(Statement statement)
publicvoidmaybeDetermineWellKnownClient(Statementstatement)This is called by the simple com.google.cloud.spanner.pgadapter.wireprotocol.QueryMessage to give the connection the opportunity to determine the client that is connected based on the SQL string that is being executed.
statement
com.google.cloud.spanner.StatementregisterAutoDescribedStatement(String sql, Future<DescribeResult> describeResult)
publicvoidregisterAutoDescribedStatement(Stringsql,Future<DescribeResult>describeResult)Stores the parameter types of an auto-described statement in the cache.
registerPortal(String portalName, IntermediatePortalStatement portal)
publicvoidregisterPortal(StringportalName,IntermediatePortalStatementportal)registerStatement(String statementName, IntermediatePreparedStatement statement)
publicvoidregisterStatement(StringstatementName,IntermediatePreparedStatementstatement)run()
publicvoidrun()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.
setActiveCopyStatement(CopyStatement copyStatement)
publicvoidsetActiveCopyStatement(CopyStatementcopyStatement)setMessageState(WireMessage message)
publicvoidsetMessageState(WireMessagemessage)setStatus(ConnectionHandler.ConnectionStatus status)
publicsynchronizedvoidsetStatus(ConnectionHandler.ConnectionStatusstatus)setWellKnownClient(ClientAutoDetector.WellKnownClient wellKnownClient)
publicvoidsetWellKnownClient(ClientAutoDetector.WellKnownClientwellKnownClient)