public class PgOutputMessageDecoder extends AbstractMessageDecoder
| Modifier and Type | Class and Description |
|---|---|
static class |
PgOutputMessageDecoder.MessageType |
| Modifier and Type | Field and Description |
|---|---|
private Instant |
commitTimestamp |
private MessageDecoderConfig |
config |
private static org.slf4j.Logger |
LOGGER |
private static Instant |
PG_EPOCH |
private static byte |
SPACE |
private int |
transactionId |
| Constructor and Description |
|---|
PgOutputMessageDecoder(MessageDecoderConfig config) |
| Modifier and Type | Method and Description |
|---|---|
private void |
decodeDelete(ByteBuffer buffer,
TypeRegistry typeRegistry,
ReplicationStream.ReplicationMessageProcessor processor)
Callback handler for the 'D' delete replication stream message.
|
private void |
decodeInsert(ByteBuffer buffer,
TypeRegistry typeRegistry,
ReplicationStream.ReplicationMessageProcessor processor)
Callback handler for the 'I' insert replication stream message.
|
private void |
decodeUpdate(ByteBuffer buffer,
TypeRegistry typeRegistry,
ReplicationStream.ReplicationMessageProcessor processor)
Callback handler for the 'U' update replication stream message.
|
private Map<String,Boolean> |
getTableColumnOptionalityFromDatabase(DatabaseMetaData databaseMetadata,
String schemaName,
String tableName) |
private Set<String> |
getTablePrimaryKeyColumnNamesFromDatabase(DatabaseMetaData databaseMetadata,
String schemaName,
String tableName) |
private void |
handleBeginMessage(ByteBuffer buffer)
Callback handler for the 'B' begin replication message.
|
private void |
handleCommitMessage(ByteBuffer buffer)
Callback handler for the 'C' commit replication message.
|
private void |
handleRelationMessage(ByteBuffer buffer,
TypeRegistry typeRegistry)
Callback handler for the 'R' relation replication message.
|
private boolean |
isColumnInPrimaryKey(String schemaName,
String tableName,
String columnName,
Set<String> primaryKeyColumns) |
org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder |
optionsWithMetadata(org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder builder)
Allows MessageDecoder to configure options with which the replication stream is started.
|
org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder |
optionsWithoutMetadata(org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder builder)
Allows MessageDecoder to configure options with which the replication stream is started.
|
void |
processMessage(ByteBuffer buffer,
ReplicationStream.ReplicationMessageProcessor processor,
TypeRegistry typeRegistry)
Process a message upon arrival from logical decoder
|
private static String |
readColumnValueAsString(ByteBuffer buffer)
Reads the replication stream where the column stream specifies a length followed by the value.
|
private static String |
readString(ByteBuffer buffer)
Reads the replication stream up to the next null-terminator byte and returns the contents as a string.
|
private static List<ReplicationMessage.Column> |
resolveColumnsFromStreamTupleData(ByteBuffer buffer,
TypeRegistry typeRegistry,
Table table)
Resolve the replication stream's tuple data to a list of replication message columns.
|
private Optional<Table> |
resolveRelation(int relationId)
Resolves a given replication message relation identifier to a
Table. |
private Table |
resolveRelationFromMetadata(PgOutputRelationMetaData metadata)
Constructs a
Table based on the supplied PgOutputRelationMetaData. |
boolean |
shouldMessageBeSkipped(ByteBuffer buffer,
Long lastReceivedLsn,
Long startLsn,
boolean skipFirstFlushRecord)
A callback into the decoder allowing it to decide whether the supplied message should be processed
by the decoder or whether it can be skipped.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsetContainsMetadataprivate static final org.slf4j.Logger LOGGER
private static final Instant PG_EPOCH
private static final byte SPACE
private Instant commitTimestamp
private int transactionId
private final MessageDecoderConfig config
public PgOutputMessageDecoder(MessageDecoderConfig config)
public boolean shouldMessageBeSkipped(ByteBuffer buffer, Long lastReceivedLsn, Long startLsn, boolean skipFirstFlushRecord)
MessageDecodershouldMessageBeSkipped in interface MessageDecodershouldMessageBeSkipped in class AbstractMessageDecoderbuffer - the replication stream bufferlastReceivedLsn - the last LSN reported by the replication streamstartLsn - the starting LSN reported by the streaming producerskipFirstFlushRecord - whether first flush record should be skippedtrue if the incoming message should be skipped, false otherwisepublic void processMessage(ByteBuffer buffer, ReplicationStream.ReplicationMessageProcessor processor, TypeRegistry typeRegistry) throws SQLException, InterruptedException
MessageDecoderbuffer - - binary representation of replication messageprocessor - - message processing on arrivaltypeRegistry - - registry with known typesSQLExceptionInterruptedExceptionpublic org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder optionsWithMetadata(org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder builder)
MessageDecoderpublic org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder optionsWithoutMetadata(org.postgresql.replication.fluent.logical.ChainedLogicalStreamBuilder builder)
MessageDecoderprivate void handleBeginMessage(ByteBuffer buffer)
buffer - The replication stream bufferprivate void handleCommitMessage(ByteBuffer buffer)
buffer - The replication stream bufferprivate void handleRelationMessage(ByteBuffer buffer, TypeRegistry typeRegistry) throws SQLException
buffer - The replication stream buffertypeRegistry - The postgres type registrySQLExceptionprivate Map<String,Boolean> getTableColumnOptionalityFromDatabase(DatabaseMetaData databaseMetadata, String schemaName, String tableName)
private Set<String> getTablePrimaryKeyColumnNamesFromDatabase(DatabaseMetaData databaseMetadata, String schemaName, String tableName)
private boolean isColumnInPrimaryKey(String schemaName, String tableName, String columnName, Set<String> primaryKeyColumns)
private void decodeInsert(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException
buffer - The replication stream buffertypeRegistry - The postgres type registryprocessor - The replication message processorSQLExceptionInterruptedExceptionprivate void decodeUpdate(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException
buffer - The replication stream buffertypeRegistry - The postgres type registryprocessor - The replication message processorSQLExceptionInterruptedExceptionprivate void decodeDelete(ByteBuffer buffer, TypeRegistry typeRegistry, ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException
buffer - The replication stream buffertypeRegistry - The postgres type registryprocessor - The replication message processorSQLExceptionInterruptedExceptionprivate Optional<Table> resolveRelation(int relationId)
Table.relationId - The replication message stream's relation identifierprivate Table resolveRelationFromMetadata(PgOutputRelationMetaData metadata)
Table based on the supplied PgOutputRelationMetaData.metadata - The relation metadata collected from previous 'R' replication stream messagesprivate static String readString(ByteBuffer buffer)
buffer - The replication stream bufferprivate static String readColumnValueAsString(ByteBuffer buffer)
buffer - The replication stream bufferprivate static List<ReplicationMessage.Column> resolveColumnsFromStreamTupleData(ByteBuffer buffer, TypeRegistry typeRegistry, Table table)
buffer - The replication stream buffertypeRegistry - The database type registrytable - The database tableCopyright © 2019 JBoss by Red Hat. All rights reserved.